shards  Version of the Day
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups
Multidimensional Array with Tagged Dimensions

Multi-dimensional array view of a contiguous block of member data with the array dimension ordinates documented by "tags". More...

Classes

class  shards::Array< Scalar, Order, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7, Tag8 >
 The preferred multi-dimensional Array interface with compile-time user-defined dimension ordinates. More...
 
class  shards::ArrayDimTag
 Abstract base class for array dimension tags supplied to the Array template class. More...
 
class  shards::ArrayDimension
 An anonymous array dimension tag, which is NOT the recommended usage. More...
 
class  shards::Array< Scalar, array_order, void, void, void, void, void, void, void, void >
 The multi-dimensional Array interface with runtime user-defined dimension ordinates. Typically used when runtime-polymorphic arrays are passed to functions. More...
 
class  shards::Array< Scalar, RankZero, void, void, void, void, void, void, void, void >
 Specialization for an array with Rank = 0. More...
 

Macros

#define SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION(ADT)
 Macro for declaration of a simple ArrayDimTag. More...
 
#define SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION(ADT)
 Macro for implementing the body of a simple ArrayDimTag. More...
 

Enumerations

enum  shards::ArrayOrder {
  shards::NaturalOrder,
  shards::FortranOrder,
  shards::RankZero
}
 Define Natural (C-language) or Fortran ordering of array dimensions. A RankZero array does not have an ordering. More...
 

Detailed Description

Multi-dimensional array view of a contiguous block of member data with the array dimension ordinates documented by "tags".

Author
H. Carter Edwards hcedw.nosp@m.ar@s.nosp@m.andia.nosp@m..gov

Trivial Example of a Function accepting a 2D Array

Given the user-defined array dimension tags Cartesian3D and Points define a function to find the centroid of an array of points.

void centroid( const Array<double,FortranOrder,Cartesian3D,Points> points ,
const Array<double,FortranOrder,Cartesian3D> x )
{
const unsigned nspace = points.dimension<0>();
const unsigned npoints = points.dimension<1>();
for ( unsigned id = 0 ; ip < nspace ; ++id ) {
x(id) = 0 ;
}
for ( unsigned ip = 0 ; ip < npoints ; ++ip ) {
for ( unsigned id = 0 ; id < nspace ; ++id ) {
x(id) += points( id , ip );
}
}
for ( unsigned id = 0 ; ip < nspace ; ++id ) {
x(id) /= npoints ;
}
}

Example of User-defined Array Dimension Tags

struct Cartesian3D : public ArrayDimTag {
enum { Size = 3 }; // Default size for this dimension.
const char * name() const ; // Supply the pure-virtual function.
static const Cartesian3D & tag(); // Runtime singleton for this tag.
};
// Simple tag without a default dimension size:
// And then in a source file:

Example of Creating an Array
Given a block of memory for the collection of points, wrap it in an Array.

double * chunk = ... ; // Chunk of memory from somewhere
unsigned npoints = ... ; // containing a number of points
Array<double,FortranOrder,Cartesian3D,Points> points( chunk , npoints );

The points array has dimension<0> set to Cartesian3D::Size and dimension<1> set to npoints. If the npoints argument where omitted then a compilation error would be generated due to the missing Points::Size enumeration.

Macro Definition Documentation

#define SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION (   ADT)
Value:
class ADT : public shards::ArrayDimTag { \
public: \
const char * name() const ; \
static const ADT & tag(); \
private: \
~ADT(); \
ADT(); \
ADT( const ADT & ); \
ADT & operator = ( const ADT & ); \
};
Abstract base class for array dimension tags supplied to the Array template class.
virtual const char * name() const =0
Name of the tag, typically the name of the derived class.

Macro for declaration of a simple ArrayDimTag.

Parameters
ADTname of the tag.

Definition at line 186 of file Shards_Array.hpp.

#define SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION (   ADT)
Value:
ADT::ADT() {} \
ADT::~ADT() {} \
const char * ADT::name() const { static const char n[] = # ADT; return n; } \
const ADT & ADT::tag() { static const ADT self ; return self ; }

Macro for implementing the body of a simple ArrayDimTag.

Parameters
ADTname of the tag.

Definition at line 201 of file Shards_Array.hpp.

Enumeration Type Documentation

Define Natural (C-language) or Fortran ordering of array dimensions. A RankZero array does not have an ordering.

Enumerator
NaturalOrder 

Use the Natural or C-language ordering for multi-dimensions where the right-most dimension is stride-one.

FortranOrder 

Use the Reverse or Fortran-language ordering for multi-dimensions where the left-most dimension is stride-one.

RankZero 

Special tag to indicate that an array specification has degenerated to rank-zero, i.e. is no longer an array.

Definition at line 82 of file Shards_Array.hpp.