Interface to dynamically loaded J engine. More...
#include <jengine.h>
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 |
Interface to dynamically loaded J engine.
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.
jengine::jengine | ( | ) |
Initializes J engine.
jengine::~jengine | ( | ) |
Frees J engine memory.
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.
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. |
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.
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). |
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.
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). |
bool jengine::doJ | ( | const std::string | s | ) |
Executes J sentence.
s | sentence to execute, must be single line. |
static void jengine::FR | ( | void * | hdr | ) | [static, protected] |
Frees J array memory.
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.
t | type of the array. | |
n | number of elements in the array. | |
r | rank of the array. | |
s | shape of the array. |
const jarray jengine::get | ( | const std::string | name | ) |
Retrieves a named array from J.
name | name of the array to retrieve |
Reimplemented in jplus.
std::set<std::string> jengine::getBuiltins | ( | ) | const |
Returns set of all names defined via defScript.
int jengine::getError | ( | ) |
J error code for the last unsuccessful operation.
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.
name | name to check |
static bool jengine::isInitialized | ( | ) | [static, protected] |
Checks if J engine is currently initialized.
bool jengine::ok | ( | ) | [inline] |
Conveniently check that there was no error.
bool jengine::set | ( | const std::string | name, | |
jarray & | value | |||
) |
Assigns J name to the specified array.
name | is the name for the array (may already be defined). | |
value | is the array to be known under the specified name. |
friend class jarray [friend] |
const int jengine::RMAX = 10000 [static] |
Constant to denote the infinite rank.