|
shards
Version of the Day
|
Multi-dimensional array view of a contiguous block of member data with the array dimension ordinates documented by "tags". More...
Classes | |
| 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, array_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::Array< Scalar, RankZero, void, void, void, void, void, void, void, void > |
| Specialization for an array with Rank = 0. More... | |
Defines | |
| #define | SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION(ADT) |
| Macro for declaration of a simple ArrayDimTag. | |
| #define | SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION(ADT) |
| Macro for implementing the body of a simple ArrayDimTag. | |
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... | |
Multi-dimensional array view of a contiguous block of member data with the array dimension ordinates documented by "tags".
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: SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( Points ) // And then in a source file: SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( Points )
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.
| #define SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION | ( | ADT | ) |
class ADT : public shards::ArrayDimTag { \ public: \ const char * name() const ; \ static const ADT & tag(); \ private: \ ~ADT(); \ ADT(); \ ADT( const ADT & ); \ ADT & operator = ( const ADT & ); \ };
Macro for declaration of a simple ArrayDimTag.
| ADT | name of the tag. |
Definition at line 186 of file Shards_Array.hpp.
| #define SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION | ( | ADT | ) |
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.
| ADT | name of the tag. |
Definition at line 201 of file Shards_Array.hpp.
| enum shards::ArrayOrder |
Define Natural (C-language) or Fortran ordering of array dimensions. A RankZero array does not have an ordering.
Definition at line 82 of file Shards_Array.hpp.