OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
ncml_module::Shape Class Reference

A wrapper class for a vector of Array::dimension structs. More...

#include <Shape.h>

Collaboration diagram for ncml_module::Shape:
Collaboration graph

Classes

class  IndexIterator
 A custom iterator that enumerates all the points in the space defined by a Shape in row major order. More...
 

Public Types

typedef std::vector< unsigned int > IndexTuple
 

Public Member Functions

Shape::IndexIterator beginSpaceEnumeration () const
 Create a forward iterator that returns IndexTuple's in a row major order (leftmost dimension slowest varying) enumeration of all the points in this Shape. More...
 
Shape::IndexIterator endSpaceEnumeration () const
 The end of the enumeration for testing end conditions. More...
 
unsigned int getConstrainedSpaceSize () const
 Get the production of all dimension c_sizes. More...
 
unsigned int getNumDimensions () const
 
unsigned int getRowMajorIndex (const IndexTuple &indices, bool validate=true) const
 Return the row major linear index into a slowest varying dimension first flattening of the given UNCONSTRAINED space (ie use dim.size for each dimension's size) More...
 
unsigned int getUnconstrainedSpaceSize () const
 Get the product of all the dimension sizes. More...
 
bool isConstrained () const
 Are there constraints on the dimension? More...
 
bool operator!= (const Shape &rhs) const
 
Shapeoperator= (const Shape &rhs)
 
bool operator== (const Shape &rhs) const
 Return if this contains the same shape as rhs. More...
 
void print (std::ostream &strm) const
 Print the contents of this to the stream. More...
 
void setToUnconstrained ()
 Go through and set all the values to be the unconstrained values. More...
 
 Shape ()
 The empty shape, with no dimensions. More...
 
 Shape (const Shape &proto)
 
 Shape (const Array &copyDimsFrom)
 Create this Shape from the shape of the given Array. More...
 
std::string toString () const
 Make a string that prints the contents of this. More...
 
bool validateIndices (const IndexTuple &indices) const
 
 ~Shape ()
 

Static Public Member Functions

static bool areDimensionsEqual (const Array::dimension &lhs, const Array::dimension &rhs)
 Helper: More...
 
static void printDimension (std::ostream &strm, const Array::dimension &dim)
 Helper to print the dimension to a stream. More...
 

Friends

class IndexIterator
 

Detailed Description

A wrapper class for a vector of Array::dimension structs.

We add functionality for equality, getting space sizes for constrained and unconstrained cases, and a way to get row major absolute indices into a linear array rep of a multi-dimensional array (as C stores them).

Shape::IndexIterator: We also add an iterator for generating the full set of index tuples for all the points in a given Shape (constrained or not) using a row major order memory traversal (i.e. for the case of no constraints, we should advance linearly one element at a time through the memory when looking up an index tuple). Leftmost component of the tuple varies fastest. Again, these iterator work if there is a constraint on the dataset as well, generating one index tuple for each entry in the defined hyperslab, also in row major order so that the constrained elements can be shoved into a Vector _buf for shipping off the hyperslab.

Definition at line 59 of file Shape.h.

Member Typedef Documentation

typedef std::vector<unsigned int> ncml_module::Shape::IndexTuple

Definition at line 63 of file Shape.h.

Constructor & Destructor Documentation

ncml_module::Shape::Shape ( )

The empty shape, with no dimensions.

Empty shape.

Not valid for anything useful except IndexIterator

Definition at line 39 of file Shape.cc.

ncml_module::Shape::Shape ( const Shape proto)

Definition at line 56 of file Shape.cc.

ncml_module::Shape::Shape ( const Array &  copyDimsFrom)

Create this Shape from the shape of the given Array.

Definition at line 44 of file Shape.cc.

ncml_module::Shape::~Shape ( )

Definition at line 61 of file Shape.cc.

Member Function Documentation

bool ncml_module::Shape::areDimensionsEqual ( const Array::dimension &  lhs,
const Array::dimension &  rhs 
)
static

Helper:

Returns
whether all the fields of the two args are equal

Definition at line 133 of file Shape.cc.

Referenced by operator==().

Shape::IndexIterator ncml_module::Shape::beginSpaceEnumeration ( ) const

Create a forward iterator that returns IndexTuple's in a row major order (leftmost dimension slowest varying) enumeration of all the points in this Shape.

This uses constraints, so should return getConstrainedSpaceSize() values. If constraints are not set, the getConstrainedSpaceSize() == getUnconstrainedSpaceSize().

ASSUMES: this Shape CANNOT be mutated during the life of the return value!! Only const functions should be used for the life of the returned iterator.

Definition at line 172 of file Shape.cc.

References IndexIterator.

Referenced by ncml_module::NCMLArray< T >::createAndSetConstrainedValueBuffer().

Shape::IndexIterator ncml_module::Shape::endSpaceEnumeration ( ) const

The end of the enumeration for testing end conditions.

See also
beginSpaceEnumeration()

Definition at line 178 of file Shape.cc.

References IndexIterator.

Referenced by ncml_module::NCMLArray< T >::createAndSetConstrainedValueBuffer().

unsigned int ncml_module::Shape::getConstrainedSpaceSize ( ) const
inline

Get the production of all dimension c_sizes.

Definition at line 174 of file Shape.h.

Referenced by ncml_module::NCMLArray< T >::createAndSetConstrainedValueBuffer().

unsigned int ncml_module::Shape::getNumDimensions ( ) const
inline

Definition at line 153 of file Shape.h.

unsigned int ncml_module::Shape::getRowMajorIndex ( const IndexTuple indices,
bool  validate = true 
) const

Return the row major linear index into a slowest varying dimension first flattening of the given UNCONSTRAINED space (ie use dim.size for each dimension's size)

Parameters
indicesan array with an index into each dimension of the space.
validatewhether to do bounds checks or not. true means slightly slower, but safer. exceptions are only thrown if validate, unless a memory fault occurs from bad indices.

ASSUME: indices.size() is the dimensionality of the space, which MUST match _dims.size() or we throw.

Given there are d dimensions of size n_i for i in {0, d-1} and indices is the d-tuple (i_0, i_1, ..., 1_{d-1}) where each i_j is in [0, n_j - 1] the index is: i_{d-1} + n_{d-1} * (i_{d-2} + n_{d-2} * ( ... + n_1 * i_0) )

Exceptions
Ifthe dimensionality of indices does not match the dimensionality of _dims.
Ifany index in indices is out of bounds for the matching dimension in _dims.

Definition at line 155 of file Shape.cc.

References NCML_ASSERT, THROW_NCML_INTERNAL_ERROR, and validateIndices().

Referenced by ncml_module::NCMLArray< T >::createAndSetConstrainedValueBuffer().

Here is the call graph for this function:

unsigned int ncml_module::Shape::getUnconstrainedSpaceSize ( ) const
inline

Get the product of all the dimension sizes.

Definition at line 163 of file Shape.h.

Referenced by ncml_module::NCMLArray< T >::cacheValuesIfNeeded().

bool ncml_module::Shape::isConstrained ( ) const

Are there constraints on the dimension?

Definition at line 103 of file Shape.cc.

Referenced by ncml_module::NCMLBaseArray::isConstrained().

bool ncml_module::Shape::operator!= ( const Shape rhs) const
inline
Returns
!(*this == rhs)

Definition at line 142 of file Shape.h.

Shape & ncml_module::Shape::operator= ( const Shape rhs)

Definition at line 67 of file Shape.cc.

bool ncml_module::Shape::operator== ( const Shape rhs) const

Return if this contains the same shape as rhs.

They must match ALL fields of ALL dimensions to be equal!!

Definition at line 79 of file Shape.cc.

References areDimensionsEqual().

Here is the call graph for this function:

void ncml_module::Shape::print ( std::ostream &  strm) const

Print the contents of this to the stream.

Definition at line 192 of file Shape.cc.

References printDimension().

Referenced by operator<<(), and toString().

Here is the call graph for this function:

void ncml_module::Shape::printDimension ( std::ostream &  strm,
const Array::dimension &  dim 
)
static

Helper to print the dimension to a stream.

Definition at line 204 of file Shape.cc.

Referenced by print().

void ncml_module::Shape::setToUnconstrained ( )

Go through and set all the values to be the unconstrained values.

Definition at line 119 of file Shape.cc.

Referenced by ncml_module::NCMLBaseArray::cacheUnconstrainedDimensions().

std::string ncml_module::Shape::toString ( ) const

Make a string that prints the contents of this.

Definition at line 184 of file Shape.cc.

References print().

Here is the call graph for this function:

bool ncml_module::Shape::validateIndices ( const IndexTuple indices) const
Returns
whether all the indices are in the correct ranges for current dims and that the indices.size() matches the _dims.size().

Definition at line 216 of file Shape.cc.

Referenced by getRowMajorIndex().

Friends And Related Function Documentation

friend class IndexIterator
friend

Definition at line 124 of file Shape.h.

Referenced by beginSpaceEnumeration(), and endSpaceEnumeration().


The documentation for this class was generated from the following files: