jengine Class Reference

Interface to dynamically loaded J engine. More...

#include <jengine.h>

Inheritance diagram for jengine:
Inheritance graph
[legend]

Public Types

typedef jarray(* monad )(jarray y)
 Pointer to function, implementing monadic variant of a verb.
typedef jarray(* dyad )(jarray x, jarray y)
 Pointer to function, implementing dyadic variant of a verb.
typedef jarray(* amonad )(monad um, dyad ud, jarray y)
 Pointer to function, implementing monadic variant of an adverb.
typedef jarray(* adyad )(monad um, dyad ud, jarray x, jarray y)
 Pointer to function, implementing dyadic variant of an adverb.

Public Member Functions

 jengine ()
 Initializes J engine.
 ~jengine ()
 Frees J engine memory.
bool doJ (const std::string s)
 Executes J sentence.
const jarray get (const std::string name)
 Retrieves a named array from J.
bool set (const std::string name, jarray &value)
 Assigns J name to the specified array.
int getError ()
 J error code for the last unsuccessful operation.
bool ok ()
 Conveniently check that there was no error.
bool defVerb (std::string name, monad mf, dyad df, int mr=RMAX, int lr=RMAX, int rr=RMAX)
 Defines J verb, calling one (or both) of specified C++ functions.
bool defAdverb (std::string name, amonad mf, adyad df)
 defines J adverb, calling one (or both) of specified C++ functions.
bool defScript (std::string name, int type, std::string code, int mr=jengine::RMAX, int lr=jengine::RMAX, int rr=jengine::RMAX)
 Defines a J script, given by a (possibly multi-libe) string.
bool isBuiltin (std::string name) const
 Checks if given name was defined via defScript.
std::set< std::string > getBuiltins () const
 Returns set of all names defined via defScript.

Static Public Member Functions

static void initJlibrary (std::ostream &)
 Loads and links J dynamic library, must be called once before this class is instantiated.

Static Public Attributes

static const int RMAX = 10000
 Constant to denote the infinite rank.

Static Protected Member Functions

static void * GA (const jarray::I t, const jarray::I n, const jarray::I r, const jarray::I *s)
 Allocates J array.
static void FR (void *hdr)
 Frees J array memory.
static bool isInitialized ()
 Checks if J engine is currently initialized.

Friends

class jarray

Detailed Description

Interface to dynamically loaded J engine.


Member Typedef Documentation

typedef jarray(* jengine::adyad)(monad um, dyad ud, jarray x, jarray y)

Pointer to function, implementing dyadic variant of an adverb.

typedef jarray(* jengine::amonad)(monad um, dyad ud, jarray y)

Pointer to function, implementing monadic variant of an adverb.

typedef jarray(* jengine::dyad)(jarray x, jarray y)

Pointer to function, implementing dyadic variant of a verb.

typedef jarray(* jengine::monad)(jarray y)

Pointer to function, implementing monadic variant of a verb.


Constructor & Destructor Documentation

jengine::jengine (  ) 

Initializes J engine.

jengine::~jengine (  ) 

Frees J engine memory.


Member Function Documentation

bool jengine::defAdverb ( std::string  name,
amonad  mf,
adyad  df 
)

defines J adverb, calling one (or both) of specified C++ functions.

Works similarly to verb definition, except the functions may now call the verb argument of an adverb monadically or dyadically. Adverbs always have infinite ranks.

Parameters:
name name of the new adverb (may already be defined).
mf function to be called when adverb is invoked monadically.
df function to be called when adverb is invoked dyadically.
Returns:
"true" on success.
bool jengine::defScript ( std::string  name,
int  type,
std::string  code,
int  mr = jengine::RMAX,
int  lr = jengine::RMAX,
int  rr = jengine::RMAX 
)

Defines a J script, given by a (possibly multi-libe) string.

Parameters:
name name of the script.
type type of the script (the left argument of ":" conjunction).
code code of the script (possibly multi-line).
mr monadic rank (infinite by default).
lr left rank (infinite by default).
rr right rank (infinite by default).
Returns:
"true" upon success.
bool jengine::defVerb ( std::string  name,
monad  mf,
dyad  df,
int  mr = RMAX,
int  lr = RMAX,
int  rr = RMAX 
)

Defines J verb, calling one (or both) of specified C++ functions.

Either of mf or df can be NULL, meaning the absence of corresponding (monadic/dyadic) case. Ranks, equal to RMAX denote "infinite" rank.

Parameters:
name name of the new verb (may already be defined).
mf function to be called when verb is invoked monadically.
df function to be called when verb is invoked dyadically.
mr monadic rank (infinite by default).
lr left rank (infinite by default).
rr right rank (infinite by default).
Returns:
"true" on success.
bool jengine::doJ ( const std::string  s  ) 

Executes J sentence.

Parameters:
s sentence to execute, must be single line.
Returns:
0 upon success.
static void jengine::FR ( void *  hdr  )  [static, protected]

Frees J array memory.

Parameters:
hdr pointer to the array header.
static void* jengine::GA ( const jarray::I  t,
const jarray::I  n,
const jarray::I  r,
const jarray::I s 
) [static, protected]

Allocates J array.

Parameters:
t type of the array.
n number of elements in the array.
r rank of the array.
s shape of the array.
Returns:
pointer to header of newly allocated array.
const jarray jengine::get ( const std::string  name  ) 

Retrieves a named array from J.

Parameters:
name name of the array to retrieve
Returns:
the J array with the specified name, invalid if name not defined.

Reimplemented in jplus.

std::set<std::string> jengine::getBuiltins (  )  const

Returns set of all names defined via defScript.

Returns:
set of all names, defined via defScript
int jengine::getError (  ) 

J error code for the last unsuccessful operation.

Returns:
J error code or 0 if no error
static void jengine::initJlibrary ( std::ostream &   )  [static]

Loads and links J dynamic library, must be called once before this class is instantiated.

bool jengine::isBuiltin ( std::string  name  )  const

Checks if given name was defined via defScript.

Parameters:
name name to check
Returns:
true if the name was defined via defScript
static bool jengine::isInitialized (  )  [static, protected]

Checks if J engine is currently initialized.

Returns:
"true" if J engine is initialized.
bool jengine::ok (  )  [inline]

Conveniently check that there was no error.

Returns:
true if there was no error.
bool jengine::set ( const std::string  name,
jarray value 
)

Assigns J name to the specified array.

Parameters:
name is the name for the array (may already be defined).
value is the array to be known under the specified name.
Returns:
true if success.

Friends And Related Function Documentation

friend class jarray [friend]

Field Documentation

const int jengine::RMAX = 10000 [static]

Constant to denote the infinite rank.


The documentation for this class was generated from the following file:
Generated on Mon Jun 25 21:17:56 2012 for jplus-0.4.1 by  doxygen 1.6.3