jarray Class Reference

C++ representation of J array. More...

#include <jarray.h>

Inheritance diagram for jarray:
Inheritance graph
[legend]
Collaboration diagram for jarray:
Collaboration graph
[legend]

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.
Ishape () 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.
Idata () 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).
jarrayassign (const jarray &other)
 Assigns another array to this one (increments refcount and frees memory, if necessary).
jarrayoperator= (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

headerhdr
 Pointer to the array header, NULL for invalid array.

Friends

class jengine

Detailed Description

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).


Member Typedef Documentation

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


Member Enumeration Documentation

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.

error codes

Enumerator:
ERR_CONV 

data type conversion error

ERR_SHAPE 

shape mismatch


Constructor & Destructor Documentation

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.

Parameters:
in stream to read the array from.
jarray::jarray ( void *  hdr_  ) 

Instantiates on top of an existing J array.

Parameters:
hdr_ pointer to J array header.
jarray::jarray ( elementType  type,
I  rank,
I shape 
)

Creates new multidimensional array of the given J type.

Parameters:
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.

Parameters:
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.

Parameters:
str string the new array will contain.
jarray::jarray ( const jarray other  ) 

Makes a copy of another array (increments refcount).

Parameters:
other the array to copy.
jarray::~jarray (  ) 

Decrements refcount, frees array memory, if necessary.


Member Function Documentation

void jarray::addhash ( SHA1 &  sha  ) 

Add this array (both shape and values) to the hash.

Parameters:
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.

Parameters:
type type of the new array (one of T_XXXX).
rank rank of the new array.
shape shape of the new array.
Returns:
true if success.

Referenced by jarray_of_type< T >::jarray_of_type().

jarray& jarray::assign ( const jarray other  ) 

Assigns another array to this one (increments refcount and frees memory, if necessary).

Parameters:
other array to assign to this one.
Returns:
reference to this array.

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.

Returns:
pointer to 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.

Parameters:
type one of T_XXX constants).
Returns:
size of the array element.
int jarray::extent ( int  dimension  )  const [inline]

Returns the extent of the specified dimension, element of shape.

Parameters:
dimension the axis, whose size is requested.
Returns:
dimension along the specified axis.

References rank(), and shape().

Referenced by jarray_of_type< T >::operator()().

template<class T >
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.

Parameters:
v place to store the array.
Returns:
0 on success.
template<class T >
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.

Parameters:
v the STL vector to hold the copy of the array.
Returns:
0 on success.

References ERR_CONV, hdr, jarray::header::n, T_B01, T_CMPX, T_FL, T_INT, T_LIT, and jarray::header::type.

template<class T >
int jarray::get ( T &  v,
const int  i 
) const [inline]

Obtains the value of a specified element of ravel.

The type must be convertible.

Parameters:
v the place to store the value.
i zero-based index of the element in ravel.
Returns:
0 on success.

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]

Returns true if the array is valid.

Returns:
true if the array is valid.

References hdr.

jarray& jarray::operator= ( const jarray other  )  [inline]

Shortcut to assign.

Parameters:
other array to assign to this one.
Returns:
reference to this array.

References assign().

bool jarray::operator== ( const jarray rhs  )  const

Performs by-element comparison and return true if two arrays are the same.

Parameters:
rhs array to compare to.
Returns:
true if arrays are the same.
const I jarray::rank (  )  const [inline]

Rank (dimensionality) of the array.

Returns:
rank 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.

template<class T >
int jarray::set ( const int  i,
const T  v 
) [inline]

Assigns the value of the specified element of ravel.

The type must be convertible.

Parameters:
i zero-based index of the element to assign.
v the value to put into the array.
Returns:
0 on success.

References ERR_CONV, hdr, T_B01, T_CMPX, T_FL, T_INT, T_LIT, and jarray::header::type.

void jarray::shape ( std::vector< I > &  shape  )  const [inline]

Copies array shape into STL vector.

Parameters:
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.

Returns:
pointer to 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.

Returns:
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.

Returns:
type of the array elements.

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.

Parameters:
out the stream to write the array to.
Returns:
true if successfully written.

Friends And Related Function Documentation

friend class jengine [friend]

Field Documentation

header* jarray::hdr [protected]

Pointer to the array header, NULL for invalid array.

Referenced by data(), get(), getHeader(), isValid(), rank(), set(), shape(), size(), and type().


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