|
jplus-0.4.7
|
C++ representation of J array. More...
#include <src/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 | |
| I | getRefcount () const |
| returns the array refcount | |
| 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 (jengine *je_, 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. | |
| jengine * | getEngine () const |
| Returns pointer to jengine, managing memory of this array. | |
| jarray (jengine *je_, void *hdr_) | |
| Instantiates on top of an existing J array. | |
| jarray (jengine *je_, elementType type, I rank, I *shape) | |
| Creates new multidimensional array of the given J type. | |
| jarray (jengine *je_, elementType type, const std::vector< I > &shape) | |
| Creates new multidimensional array of the given J type. | |
| jarray (jengine *je_, 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 (jengine *je_, 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. | |
| jengine * | je |
| Pointer to jengine, managing the memory of this 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).
Constants for possible array element types.
| Enumerator | |
|---|---|
| T_B01 | B boolean |
| T_LIT | C literal (character) |
| T_INT | I integer |
| T_FL | D double (IEEE floating point) |
| T_CMPX | Z complex |
| jarray::jarray | ( | ) |
Invalid array, a valid array can be assigned to it.
| jarray::jarray | ( | jengine * | je_, |
| std::istream & | in | ||
| ) |
Loads the array from binary representation in a stream.
The representation can be created by the write method.
| je_ | jengine to own the array's memory. |
| in | stream to read the array from. |
Instantiates on top of an existing J array.
| je_ | jengine to own the array memory. |
| hdr_ | pointer to J array header. |
| jarray::jarray | ( | jengine * | je_, |
| elementType | type, | ||
| I | rank, | ||
| I * | shape | ||
| ) |
Creates new multidimensional array of the given J type.
| je_ | jengine to own the array memory. |
| type | the type of new array (one of T_XXX). |
| rank | rank of the new array. |
| shape | pointer to elements of shape. |
| jarray::jarray | ( | jengine * | je_, |
| elementType | type, | ||
| const std::vector< I > & | shape | ||
| ) |
Creates new multidimensional array of the given J type.
| je_ | jengine to own the array memory. |
| type | the array type (one of T_XXX). |
| shape | the STL vector, holding elements of shape. |
Creates T_LIT vector from C++ string.
| je_ | jengine to own the array memory. |
| str | string the new array will contain. |
Makes a copy of another array (increments refcount).
| other | the array to copy. |
| jarray::~jarray | ( | ) |
Decrements refcount, frees array memory, if necessary.
Add this array (both shape and values) to the hash.
| sha | hash to add the array to. |
Allocates new array in memory.
The memory if either malloc-ed (if the first argument is null), or, if passed non-null je pointer, allocated via jtga function of J engine.
| je_ | jengine to manage the memory of this array. |
| 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(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), and 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=().
|
inline |
Returns pointer to the beginning of the array data.
References hdr, and jarray::header::offset.
Referenced by jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), 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 |
Size (in bytes) of the particular data type.
| type | one of T_XXX constants). |
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()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), and jarray_of_type< T >::operator()().
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, jarray::header::offset, T_B01, T_CMPX, T_FL, T_INT, T_LIT, and jarray::header::type.
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. |
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, jarray::header::offset, T_B01, T_CMPX, T_FL, T_INT, T_LIT, and jarray::header::type.
Referenced by jarray_of_type< T >::jarray_of_type().
|
inline |
Returns pointer to jengine, managing memory of this array.
References je.
Referenced by jarray_of_type< T >::jarray_of_type().
References jarray::header::flag, and hdr.
|
inline |
|
protected |
Increments refcount.
|
inline |
|
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. |
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 >::jarray_of_type(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), jarray_of_type< T >::operator()(), shape(), and size().
|
protected |
Decrements refcount and frees memory, if necessary.
|
inline |
Assigns the value of the specified element of ravel.
The type must be convertible.
| i | zero-based index of the element to assign. |
| v | the value to put into the array. |
References ERR_CONV, hdr, jarray::header::offset, T_B01, T_CMPX, T_FL, T_INT, T_LIT, and jarray::header::type.
Referenced by jarray_of_type< T >::jarray_of_type().
|
inline |
Returns pointer to the first element of the shape.
References hdr, and jarray::header::shape.
Referenced by extent(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), jarray_of_type< T >::jarray_of_type(), and shape().
Copies array shape into STL vector.
| shape | the vector to hold the requested shape. |
References hdr, rank(), shape(), and jarray::header::shape.
Number of elements in ravel.
References hdr, rank(), and jarray::header::shape.
Referenced by jarray_of_type< T >::jarray_of_type().
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. |
|
protected |
|
protected |
Pointer to jengine, managing the memory of this array.
Referenced by getEngine().