#ifndef SARRAY_H_
#define SARRAY_H_
#include <sarray/Range.h>
#include <set>
/** @short missing value */
extern const double JAGS_NA;
/**
* SArrays represent multi-dimensional arrays of double precision floats
* @short multi-dimensional array
*/
class SArray
{
Range const _range;
double *_value;
bool _fixed;
bool _discrete;
//Forbid copying
SArray &operator=(SArray const &rhs);
public:
/**
* Constructor for SArrays.
*
* On construction, the elements of the value array are all equal to
* JAGS_NA and the SArray is uninitialized.
*
* @param dim Dimension of SArray to be constructed
*/
SArray(Index const &dim);
SArray(SArray const &orig);
~SArray();
/**
* Set value of SArray.
*
* It is an error to set the value of a fixed SArray.
*
* @param value Array of values to be assigned
* @param length Length of value argument. It is an error if this
* does not match the length of the SArray.
* @exception logic_error length_error
*/
void setValue(double const *value, unsigned long length);
/**
* Sets the value of a single element of SArray
*
* @param value Scalar value to be assigned
* @param offset Distance along the value array
*/
void setValue(double value, unsigned long offset);
/**
* The value of the SArray in vector form.
*
* Values are given in column order, like the S language (i.e. with
* the left hand index moving fastest).
* @return A pointer to the beginning of the value array
*/
inline double const *value() const;
/**
* Sets the SArray to be fixed (true) or not (false).
*
* Fixed SArrays cannot change their value. It is an error to fix
* an SArray that contains missing values.
*/
void setFixed(bool fix);
/**
* Indicates whether the SArray is fixed, and so cannot change
* its value.
*/
bool isFixed() const;
/**
* Determines whether the array should contain integer-values (true)
* or real valued (false).
*
* Currently, the integer-value flag of an SArray is purely semantic:
* the storage type of the values is always double, and the values
* are never checked to see if they are consistent with the integer-value
* flag.
*/
void setDiscreteValued(bool flag);
/**
* Indicates whether the SArray should contain integer-values or
* real values.
*/
bool isDiscreteValued() const;
/**
* Returns the range associated with the SArray
*/
Range const &range() const;
/**
* It is convenient to inline these functions so that an SArray
* can be thought of as having some of the dimension attributes
* of its associated range.
*/
unsigned long length() const { return range().length(); }
unsigned int ndim(bool drop) const { return range().ndim(drop); }
Index const &dim(bool drop) const { return range().dim(drop); }
};
inline double const *SArray::value() const
{
return _value;
}
#endif /* SARRAY_H_ */
syntax highlighted by Code2HTML, v. 0.9.1