C++ representation of J array. More...
#include <jarray.h>
Data Structures | |
struct | header |
J array header. More... | |
struct | MS |
Layout of two words before every array, responsible for J memory management. More... | |
struct | Z |
complex type, equivalent to J More... | |
Public Types | |
enum | errorType { ERR_CONV = 10, ERR_SHAPE = 11 } |
error codes More... | |
enum | elementType { T_B01 = 1, T_LIT = 2, T_INT = 4, T_FL = 8, T_CMPX = 16 } |
Constants for possible array element types. More... | |
typedef char | B |
byte type, equivalent to J | |
typedef char | C |
literal type, equivalent to J | |
typedef short | S |
short int type, equivalent to J | |
typedef long | I |
integer type, equivalent to J | |
typedef double | D |
floating point type, equivalent to J | |
Public Member Functions | |
template<class T > | |
int | get (T &v, const int i) const |
Obtains the value of a specified element of ravel. | |
template<class T > | |
int | set (const int i, const T v) |
Assigns the value of the specified element of ravel. | |
template<class T > | |
int | get (std::vector< T > &v) const |
Fits ravel of the array into the specified STL vector. | |
template<class T > | |
int | get (T &v) |
Attempts to fit the whole array into the specified type. | |
jarray () | |
Invalid array, a valid array can be assigned to it. | |
jarray (std::istream &in) | |
Loads the array from binary representation in a stream. | |
jarray::I | esize () const |
Size (in bytes) of the single element of this array. | |
void | addhash (SHA1 &sha) |
Add this array (both shape and values) to the hash. | |
bool | write (std::ostream &out) |
Writes binary representation of this array into the specified output stream. | |
bool | isValid () const |
Returns true if the array is valid. | |
const I | type () const |
Returns array type. | |
const I | rank () const |
Rank (dimensionality) of the array. | |
I * | shape () const |
Returns pointer to the first element of the shape. | |
int | extent (int dimension) const |
Returns the extent of the specified dimension, element of shape. | |
void | shape (std::vector< I > &shape) const |
Copies array shape into STL vector. | |
const int | size () const |
Number of elements in ravel. | |
I * | data () const |
Returns pointer to the beginning of the array data. | |
jarray (void *hdr_) | |
Instantiates on top of an existing J array. | |
jarray (elementType type, I rank, I *shape) | |
Creates new multidimensional array of the given J type. | |
jarray (elementType type, const std::vector< I > &shape) | |
Creates new multidimensional array of the given J type. | |
jarray (const std::string &str) | |
Creates T_LIT vector from C++ string. | |
jarray (const jarray &other) | |
Makes a copy of another array (increments refcount). | |
jarray & | assign (const jarray &other) |
Assigns another array to this one (increments refcount and frees memory, if necessary). | |
jarray & | operator= (const jarray &other) |
Shortcut to assign. | |
bool | operator== (const jarray &rhs) const |
Performs by-element comparison and return true if two arrays are the same. | |
~jarray () | |
Decrements refcount, frees array memory, if necessary. | |
Static Public Member Functions | |
static jarray::I | esize (elementType type) |
Size (in bytes) of the particular data type. | |
Protected Member Functions | |
bool | allocate (elementType type, const I rank, const I *shape) |
Allocates new array in memory. | |
void | grab () const |
Increments refcount. | |
void | release () |
Decrements refcount and frees memory, if necessary. | |
I | getHeader (bool give_up_ownership=true) const |
Protected Attributes | |
header * | hdr |
Pointer to the array header, NULL for invalid array. | |
Friends | |
class | jengine |
C++ representation of J array.
This is the direct mapping of J array into C++ domain, for support of typed arrays (with automatic type conversion and convenient element indexing) see jarray_of_type template class. Only non-sparse array types are currently supported. This class may operate in standalone mode (managing its memory via malloc), or, if J engine is initalized, it will cooperate with J on memory allocation and make use of J garbage collection (AKA tempstack).
typedef char jarray::B |
byte type, equivalent to J
typedef char jarray::C |
literal type, equivalent to J
typedef double jarray::D |
floating point type, equivalent to J
typedef long jarray::I |
integer type, equivalent to J
typedef short jarray::S |
short int type, equivalent to J
enum jarray::elementType |
Constants for possible array element types.
T_B01 |
B boolean. |
T_LIT |
C literal (character). |
T_INT |
I integer. |
T_FL |
D double (IEEE floating point). |
T_CMPX |
Z complex. |
enum jarray::errorType |
jarray::jarray | ( | ) |
Invalid array, a valid array can be assigned to it.
jarray::jarray | ( | std::istream & | in | ) |
Loads the array from binary representation in a stream.
The representation can be created by the write method.
in | stream to read the array from. |
jarray::jarray | ( | void * | hdr_ | ) |
Instantiates on top of an existing J array.
hdr_ | pointer to J array header. |
jarray::jarray | ( | elementType | type, | |
I | rank, | |||
I * | shape | |||
) |
Creates new multidimensional array of the given J type.
type | the type of new array (one of T_XXX). | |
rank | rank of the new array. | |
shape | pointer to elements of shape. |
jarray::jarray | ( | elementType | type, | |
const std::vector< I > & | shape | |||
) |
Creates new multidimensional array of the given J type.
type | the array type (one of T_XXX). | |
shape | the STL vector, holding elements of shape. |
jarray::jarray | ( | const std::string & | str | ) |
Creates T_LIT vector from C++ string.
str | string the new array will contain. |
jarray::jarray | ( | const jarray & | other | ) |
Makes a copy of another array (increments refcount).
other | the array to copy. |
jarray::~jarray | ( | ) |
Decrements refcount, frees array memory, if necessary.
void jarray::addhash | ( | SHA1 & | sha | ) |
Add this array (both shape and values) to the hash.
sha | hash to add the array to. |
bool jarray::allocate | ( | elementType | type, | |
const I | rank, | |||
const I * | shape | |||
) | [protected] |
Allocates new array in memory.
The memory if either malloc-ed, or, if J engine is initialized, allocated via jtga function of J engine.
type | type of the new array (one of T_XXXX). | |
rank | rank of the new array. | |
shape | shape of the new array. |
Referenced by jarray_of_type< T >::jarray_of_type().
Assigns another array to this one (increments refcount and frees memory, if necessary).
other | array to assign to this one. |
Referenced by jarray_of_type< T >::jarray_of_type(), and operator=().
I* jarray::data | ( | ) | const [inline] |
Returns pointer to the beginning of the array data.
References hdr.
Referenced by jarray_of_type< T >::operator()(), and jarray_of_type< T >::operator[]().
jarray::I jarray::esize | ( | ) | const |
Size (in bytes) of the single element of this array.
static jarray::I jarray::esize | ( | elementType | type | ) | [static] |
Size (in bytes) of the particular data type.
type | one of T_XXX constants). |
int jarray::extent | ( | int | dimension | ) | const [inline] |
Returns the extent of the specified dimension, element of shape.
dimension | the axis, whose size is requested. |
References rank(), and shape().
Referenced by jarray_of_type< T >::operator()().
int jarray::get | ( | T & | v | ) | [inline] |
Attempts to fit the whole array into the specified type.
Currently, this works for literal arrays, which can be fitted into C++ strings.
v | place to store the array. |
int jarray::get | ( | std::vector< T > & | v | ) | const [inline] |
Fits ravel of the array into the specified STL vector.
The type must be convertible. Does copy.
v | the STL vector to hold the copy of the array. |
References ERR_CONV, hdr, jarray::header::n, T_B01, T_CMPX, T_FL, T_INT, T_LIT, and jarray::header::type.
int jarray::get | ( | T & | v, | |
const int | i | |||
) | const [inline] |
Obtains the value of a specified element of ravel.
The type must be convertible.
v | the place to store the value. | |
i | zero-based index of the element in ravel. |
References ERR_CONV, hdr, T_B01, T_CMPX, T_FL, T_INT, T_LIT, and jarray::header::type.
Referenced by jarray_of_type< T >::jarray_of_type().
I jarray::getHeader | ( | bool | give_up_ownership = true |
) | const [inline, protected] |
References jarray::header::flag, and hdr.
void jarray::grab | ( | ) | const [protected] |
Increments refcount.
bool jarray::isValid | ( | ) | const [inline] |
Shortcut to assign.
other | array to assign to this one. |
References assign().
bool jarray::operator== | ( | const jarray & | rhs | ) | const |
Performs by-element comparison and return true if two arrays are the same.
rhs | array to compare to. |
const I jarray::rank | ( | ) | const [inline] |
Rank (dimensionality) of the array.
References hdr, and jarray::header::rank.
Referenced by extent(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::operator()(), shape(), and size().
void jarray::release | ( | ) | [protected] |
Decrements refcount and frees memory, if necessary.
int jarray::set | ( | const int | i, | |
const T | v | |||
) | [inline] |
void jarray::shape | ( | std::vector< I > & | shape | ) | const [inline] |
Copies array shape into STL vector.
shape | the vector to hold the requested shape. |
References hdr, rank(), and jarray::header::shape.
I* jarray::shape | ( | ) | const [inline] |
Returns pointer to the first element of the shape.
References hdr, and jarray::header::shape.
Referenced by extent(), and jarray_of_type< T >::jarray_of_type().
const int jarray::size | ( | ) | const [inline] |
Number of elements in ravel.
References hdr, rank(), and jarray::header::shape.
Referenced by jarray_of_type< T >::jarray_of_type().
const I jarray::type | ( | ) | const [inline] |
Returns array type.
One of T_XXX constants.
References hdr, and jarray::header::type.
Referenced by jarray_of_type< T >::jarray_of_type().
bool jarray::write | ( | std::ostream & | out | ) |
Writes binary representation of this array into the specified output stream.
out | the stream to write the array to. |
friend class jengine [friend] |
header* jarray::hdr [protected] |