AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
|
A View object describes data, which may be owned by the view object (e.g., via an attached Buffer) or owned externally. More...
#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/develop/src/axom/sidre/core/View.hpp>
Public Member Functions | |
template<typename DataType > | |
DataType | getData () |
Lightweight templated wrapper around getData() that can be used when you are calling getData(), but not assigning the return type. More... | |
void * | getVoidPtr () const |
Returns a void pointer to the view's data. More... | |
View query and accessor methods | |
IndexType | getIndex () const |
Return index of View within owning Group. More... | |
const std::string & | getName () const |
Return const reference to name of View. More... | |
std::string | getPath () const |
Return path of View's owning Group object. More... | |
std::string | getPathName () const |
Return full path of View object, including its name. More... | |
Group * | getOwningGroup () |
Return pointer to non-const Group that owns View object. More... | |
const Group * | getOwningGroup () const |
Return pointer to const Group that owns View object. More... | |
bool | hasBuffer () const |
Return true if view has a an associated Buffer object (e.g., view is not opaque, it has been created with a buffer, it has been allocated, etc.); false otherwise. More... | |
Buffer * | getBuffer () |
Return pointer to non-const Buffer associated with View. More... | |
const Buffer * | getBuffer () const |
Return pointer to const Buffer associated with View. More... | |
bool | isExternal () const |
Return true if view holds external data; false otherwise. More... | |
bool | isAllocated () const |
Return true if view is described and refers to a buffer that has been allocated. More... | |
bool | isApplied () const |
Return true if data description (schema) has been applied to data in buffer associated with view; false otherwise. More... | |
bool | isDescribed () const |
Return true if data description exists. It may/may not have been applied to the data yet. ( Check isApplied() for that. ) More... | |
bool | isEmpty () const |
Return true if view is empty. More... | |
bool | isOpaque () const |
Convenience function that returns true if view is opaque (i.e., has access to data but has no knowledge of the data type or structure); false otherwise. More... | |
bool | isScalar () const |
Return true if view contains a scalar value. More... | |
bool | isString () const |
Return true if view contains a string value. More... | |
TypeID | getTypeID () const |
Return type of data for this View object. Return NO_TYPE_ID for an undescribed view. More... | |
IndexType | getTotalBytes () const |
Return total number of bytes associated with this View object. More... | |
IndexType | getNumElements () const |
Return total number of elements described by this View object. More... | |
IndexType | getBytesPerElement () const |
Return number of bytes per element in the described view. More... | |
IndexType | getOffset () const |
Return the offset in number of elements for the data described by this View object. More... | |
IndexType | getStride () const |
Return the stride in number of elements for the data described by this View object. More... | |
int | getNumDimensions () const |
Return dimensionality of this View's data. More... | |
int | getShape (int ndims, IndexType *shape) const |
Return number of dimensions in data view and fill in shape information of this data view object. More... | |
const Schema & | getSchema () const |
Return const reference to schema describing data. More... | |
Node & | getNode () |
Return non-const reference to Conduit node holding data. More... | |
const Node & | getNode () const |
Return const reference to Conduit node holding data. More... | |
bool | isEquivalentTo (const View *other) const |
Returns boolean telling whether two Views have equivalent internal description, in terms of name, datatype, and current state of the object. Values of the data are not checked. More... | |
bool | isUpdateableFrom (const View *other) const |
Returns true if both Views are either associated with a buffer or external, they span the same number of bytes and have unit stride. More... | |
View allocation methods | |
View * | allocate (int allocID=INVALID_ALLOCATOR_ID) |
Allocate data for a view, previously described. More... | |
View * | allocate (TypeID type, IndexType num_elems, int allocID=INVALID_ALLOCATOR_ID) |
Allocate data for view given type and number of elements. More... | |
View * | allocate (TypeID type, int ndims, const IndexType *shape, int allocID) |
Allocate data for view given type and shape. More... | |
View * | allocate (const DataType &dtype, int allocID=INVALID_ALLOCATOR_ID) |
Allocate data for view described by a Conduit data type object. More... | |
View * | reallocate (IndexType num_elems) |
Reallocate data for view to given number of elements (type stays the same). More... | |
View * | reallocate (const DataType &dtype) |
Reallocate data for view as specified by Conduit data type object. More... | |
View * | deallocate () |
Deallocate data for view. More... | |
View * | reshapeArray (int ndims, const IndexType *shape) |
Reshape the array without changing its size. More... | |
View * | attachBuffer (Buffer *buff) |
Attach Buffer object to data view. More... | |
View * | attachBuffer (TypeID type, IndexType num_elems, Buffer *buff) |
Describe the data view and attach Buffer object. More... | |
View * | attachBuffer (TypeID type, int ndims, const IndexType *shape, Buffer *buff) |
Describe the data view and attach Buffer object. More... | |
Buffer * | detachBuffer () |
Detach this view from its Buffer. More... | |
void | clear () |
Clear data and metadata from a View. More... | |
Methods to apply View description to data. | |
View * | apply () |
Apply view description to data. More... | |
View * | apply (IndexType num_elems, IndexType offset=0, IndexType stride=1) |
Apply data description defined by number of elements, and optionally offset and stride to data view (type remains the same). More... | |
View * | apply (TypeID type, IndexType num_elems, IndexType offset=0, IndexType stride=1) |
Apply data description defined by type and number of elements, and optionally offset and stride to data view. More... | |
View * | apply (TypeID type, int ndims, const IndexType *shape) |
Apply data description defined by type and shape information to data view. More... | |
View * | apply (const DataType &dtype) |
Apply data description of given Conduit data type to data view. More... | |
Methods to set data in the view (scalar, string, or external data). | |
template<typename ScalarType > | |
View * | setScalar (ScalarType value) |
Set the view to hold the given scalar. More... | |
View * | setScalar (Node &value) |
Set the view to hold the given scalar. More... | |
View * | importArrayNode (const Node &array) |
View * | setString (const std::string &value) |
Set the view to hold the given string. More... | |
View * | setExternalDataPtr (void *external_ptr) |
Set view to hold external data. More... | |
View * | setExternalDataPtr (TypeID type, IndexType num_elems, void *external_ptr) |
Set view to hold described external data. More... | |
View * | setExternalDataPtr (TypeID type, int ndims, const IndexType *shape, void *external_ptr) |
Set view to hold described external data. More... | |
View * | updateFrom (const View *other) |
Update the data in this View with the data in other if isUpdateableFrom( other ). Otherwise nothing is done. More... | |
Methods to retrieve data in a view. | |
Node::Value | getArray () |
Return a pointer or conduit array object to the view's array data. More... | |
const char * | getString () const |
Returns a pointer to the string contained in the view. More... | |
Node::ConstValue | getScalar () const |
Returns a copy of the scalar value contained in the view. More... | |
Node::Value | getData () |
Return data held by view and cast it to any compatible type allowed by Conduit (return type depends on type caller assigns it to). More... | |
Node::ConstValue | getData () const |
View print methods. | |
void | print () const |
Print JSON description of data view to stdout. More... | |
void | print (std::ostream &os) const |
Print JSON description of data view to an ostream. More... | |
void | copyToConduitNode (Node &n) const |
Copy data view description to given Conduit node. More... | |
void | createNativeLayout (Node &n) const |
Copy data view native layout to given Conduit node. More... | |
void | copyMetadataToNode (Node &n) const |
Copy metadata of the View to the given Conduit node. More... | |
bool | rename (const std::string &new_name) |
Change the name of this View. More... | |
Friends | |
class | Group |
class | Buffer |
Attribute Value query and accessor methods | |
Attribute * | getAttribute (IndexType idx) |
Get an Attribute. More... | |
const Attribute * | getAttribute (IndexType idx) const |
Attribute * | getAttribute (const std::string &name) |
const Attribute * | getAttribute (const std::string &name) const |
bool | hasAttributeValue (IndexType idx) const |
Return true if the attribute has been explicitly set; else false. More... | |
bool | hasAttributeValue (const std::string &name) const |
Return true if the attribute has been explicitly set; else false. More... | |
bool | hasAttributeValue (const Attribute *attr) const |
Return true if the attribute has been explicitly set; else false. More... | |
bool | setAttributeToDefault (IndexType idx) |
Set Attribute to its default value. More... | |
bool | setAttributeToDefault (const std::string &name) |
bool | setAttributeToDefault (const Attribute *attr) |
template<typename ScalarType > | |
bool | setAttributeScalar (IndexType idx, ScalarType value) |
Set Attribute to a scalar value. More... | |
template<typename ScalarType > | |
bool | setAttributeScalar (const std::string &name, ScalarType value) |
template<typename ScalarType > | |
bool | setAttributeScalar (const Attribute *attr, ScalarType value) |
bool | setAttributeString (IndexType indx, const std::string &value) |
Set Attribute to a string value. More... | |
bool | setAttributeString (const std::string &name, const std::string &value) |
bool | setAttributeString (const Attribute *attr, const std::string &value) |
Node::ConstValue | getAttributeScalar (IndexType idx) const |
Return scalar Attribute value. More... | |
Node::ConstValue | getAttributeScalar (const std::string &name) const |
Node::ConstValue | getAttributeScalar (const Attribute *attr) const |
template<typename DataType > | |
DataType | getAttributeScalar (IndexType idx) |
Lightweight templated wrapper around getAttributeScalar() that can be used when you are calling getAttributeScalar(), but not assigning the return type. More... | |
template<typename DataType > | |
DataType | getAttributeScalar (const std::string &name) |
Lightweight templated wrapper around getAttributeScalar() that can be used when you are calling getAttributeScalar(), but not assigning the return type. More... | |
template<typename DataType > | |
DataType | getAttributeScalar (const Attribute *attr) |
Lightweight templated wrapper around getAttributeScalar() that can be used when you are calling getAttributeScalar(), but not assigning the return type. More... | |
const char * | getAttributeString (IndexType idx) const |
Return a string attribute. More... | |
const char * | getAttributeString (const std::string &name) const |
const char * | getAttributeString (const Attribute *attr) const |
const Node & | getAttributeNodeRef (IndexType idx) const |
Return reference to an Attribute node. More... | |
const Node & | getAttributeNodeRef (const std::string &name) const |
const Node & | getAttributeNodeRef (const Attribute *attr) const |
IndexType | getFirstValidAttrValueIndex () const |
Return first valid Attribute index for a set Attribute in View object (i.e., smallest index over all Attributes). More... | |
IndexType | getNextValidAttrValueIndex (IndexType idx) const |
Return next valid Attribute index for a set Attribute in View object after given index (i.e., smallest index over all Attribute indices larger than given one). More... | |
A View object describes data, which may be owned by the view object (e.g., via an attached Buffer) or owned externally.
The View class has the following properties:
|
inline |
Return index of View within owning Group.
If View is detached, return sidre::InvalidIndex.
|
inline |
Return const reference to name of View.
std::string axom::sidre::View::getPath | ( | ) | const |
Return path of View's owning Group object.
std::string axom::sidre::View::getPathName | ( | ) | const |
Return full path of View object, including its name.
If a DataStore contains a Group tree structure a/b/c/d/e, with group d owning a view v, the following results are expected:
Method Call | Result |
---|---|
v->getName() | v |
v->getPath() | a/b/c/d |
v->getPathName() | a/b/c/d/v |
|
inline |
|
inline |
|
inline |
Return true if view has a an associated Buffer object (e.g., view is not opaque, it has been created with a buffer, it has been allocated, etc.); false otherwise.
|
inline |
|
inline |
|
inline |
Return true if view holds external data; false otherwise.
bool axom::sidre::View::isAllocated | ( | ) | const |
Return true if view is described and refers to a buffer that has been allocated.
|
inline |
Return true if data description (schema) has been applied to data in buffer associated with view; false otherwise.
|
inline |
Return true if data description exists. It may/may not have been applied to the data yet. ( Check isApplied() for that. )
|
inline |
Return true if view is empty.
|
inline |
Convenience function that returns true if view is opaque (i.e., has access to data but has no knowledge of the data type or structure); false otherwise.
References isApplied().
|
inline |
Return true if view contains a scalar value.
|
inline |
Return true if view contains a string value.
|
inline |
Return type of data for this View object. Return NO_TYPE_ID for an undescribed view.
References isDescribed(), and axom::sidre::NO_TYPE_ID.
|
inline |
Return total number of bytes associated with this View object.
|
inline |
Return total number of elements described by this View object.
|
inline |
Return number of bytes per element in the described view.
IndexType axom::sidre::View::getOffset | ( | ) | const |
Return the offset in number of elements for the data described by this View object.
IndexType axom::sidre::View::getStride | ( | ) | const |
Return the stride in number of elements for the data described by this View object.
|
inline |
Return dimensionality of this View's data.
int axom::sidre::View::getShape | ( | int | ndims, |
IndexType * | shape | ||
) | const |
Return number of dimensions in data view and fill in shape information of this data view object.
ndims - maximum number of dimensions to return. shape - user supplied buffer assumed to be ndims long.
Return the number of dimensions of the view. Return -1 if shape is too short to hold all dimensions.
|
inline |
Return const reference to schema describing data.
|
inline |
Return non-const reference to Conduit node holding data.
|
inline |
Return const reference to Conduit node holding data.
bool axom::sidre::View::isEquivalentTo | ( | const View * | other | ) | const |
Returns boolean telling whether two Views have equivalent internal description, in terms of name, datatype, and current state of the object. Values of the data are not checked.
bool axom::sidre::View::isUpdateableFrom | ( | const View * | other | ) | const |
Returns true if both Views are either associated with a buffer or external, they span the same number of bytes and have unit stride.
View* axom::sidre::View::allocate | ( | int | allocID = INVALID_ALLOCATOR_ID | ) |
Allocate data for a view, previously described.
View* axom::sidre::View::allocate | ( | TypeID | type, |
IndexType | num_elems, | ||
int | allocID = INVALID_ALLOCATOR_ID |
||
) |
Allocate data for view given type and number of elements.
Allocate data for view given type and shape.
If shape is nullptr, this is a no-op.
View* axom::sidre::View::allocate | ( | const DataType & | dtype, |
int | allocID = INVALID_ALLOCATOR_ID |
||
) |
Allocate data for view described by a Conduit data type object.
Reallocate data for view to given number of elements (type stays the same).
Reallocate data for view as specified by Conduit data type object.
View* axom::sidre::View::deallocate | ( | ) |
Deallocate data for view.
Reshape the array without changing its size.
The View state must be either BUFFER or EXTERNAL. The new shape must have the same size as the current. If either conditions are not met, a warning is issued and this is a no-op.
Attach Buffer object to data view.
If the view has no description, then the buffer's description is copied into the view.
Note that, in general, the view cannot be used to access data in buffer until one of the apply() methods is called. However, if the view has a valid data description with a total number of bytes that is <= number of bytes held in the buffer, then apply() will be called internally.
If data view already has a buffer, or it is an external view, a scalar view, or a string view, this method does nothing.
If data view already has a buffer and buff is nullptr, the attached buffer will be detached. After the view is detached from the buffer, if the buffer has no views attached to it, then it will be destroyed.
Describe the data view and attach Buffer object.
References attachBuffer().
|
inline |
Describe the data view and attach Buffer object.
If shape is nullptr, this is a no-op.
References attachBuffer(), SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
Buffer* axom::sidre::View::detachBuffer | ( | ) |
Detach this view from its Buffer.
If the view has no buffer, the method does nothing.
void axom::sidre::View::clear | ( | ) |
View* axom::sidre::View::apply | ( | ) |
Apply view description to data.
If view holds a scalar or a string, the method does nothing.
Apply data description defined by number of elements, and optionally offset and stride to data view (type remains the same).
If view holds a scalar or a string, is external and does not have a sufficient data description to get type information, or given number of elements < 0, or offset < 0, the method does nothing.
View* axom::sidre::View::apply | ( | TypeID | type, |
IndexType | num_elems, | ||
IndexType | offset = 0 , |
||
IndexType | stride = 1 |
||
) |
Apply data description defined by type and number of elements, and optionally offset and stride to data view.
If view holds a scalar or a string, or type is NO_TYPE_ID, or given number of elements < 0, or offset < 0, the method does nothing.
Apply data description defined by type and shape information to data view.
If view holds a scalar or a string, or type is NO_TYPE_ID, or given number of dimensions < 0, or pointer to shape is null, the method does nothing.
Apply data description of given Conduit data type to data view.
If view holds a scalar or a string, the method does nothing.
|
inline |
Set the view to hold the given scalar.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
Set the view to hold the given scalar.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
Set the view to hold the given string.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
View* axom::sidre::View::setExternalDataPtr | ( | void * | external_ptr | ) |
Set view to hold external data.
Data is undescribed (i.e., view is opaque) until an apply methods is called on the view.
If external_ptr is nullptr, the view will be EMPTY. Any existing description is unchanged.
|
inline |
Set view to hold described external data.
If external_ptr is nullptr, the view will be EMPTY.
References setExternalDataPtr().
|
inline |
Set view to hold described external data.
If external_ptr is nullptr, the view will be EMPTY.
If shape is nullptr, this is a no-op.
References setExternalDataPtr(), SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
Return a pointer or conduit array object to the view's array data.
Return value depends on variable type caller assigns it to. For example, if view holds an integer array, the following usage is possible:
int* a = view->getArray(); // Get array as int pointer int_array a = view->getArray(); // Get array as Conduit array struct.
References getData().
|
inline |
Returns a pointer to the string contained in the view.
If the view is not a STRING, then nullptr is returned.
|
inline |
Returns a copy of the scalar value contained in the view.
References getData(), SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
Return data held by view and cast it to any compatible type allowed by Conduit (return type depends on type caller assigns it to).
If view does not contain allocated data, an empty Node::Value will be returned.
References isAllocated(), isDescribed(), SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
References isAllocated(), isDescribed(), SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
void* axom::sidre::View::getVoidPtr | ( | ) | const |
Returns a void pointer to the view's data.
To access the first data element, you will need to cast to the appropriate type and add the offset. E.g. if the underlying data is an array of integers you can access the first element as follows:
void* vptr = view->getVoidPtr(); int* iptr = static_cast<int*>(vptr) + view->getOffset();
void axom::sidre::View::print | ( | ) | const |
Print JSON description of data view to stdout.
void axom::sidre::View::print | ( | std::ostream & | os | ) | const |
Print JSON description of data view to an ostream.
void axom::sidre::View::copyToConduitNode | ( | Node & | n | ) | const |
Copy data view description to given Conduit node.
void axom::sidre::View::createNativeLayout | ( | Node & | n | ) | const |
Copy data view native layout to given Conduit node.
The native layout is a Conduit Node hierarchy that maps the Conduit Node data externally to the Sidre View data so that it can be filled in from the data in the file (independent of file format) and can be accessed as a Conduit tree.
void axom::sidre::View::copyMetadataToNode | ( | Node & | n | ) | const |
bool axom::sidre::View::rename | ( | const std::string & | new_name | ) |
Change the name of this View.
The name of this view is changed to the new name. This also changes the name for this view held by the owning group.
Warnings will occur and the name will not be changed under these conditions: If the new name is an empty string, if the new name contains a path delimiter (usually '/'), or if the new name is identical to a name that is already held by the parent for another Group or View object.
new_name | The new name for this view. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Attribute* axom::sidre::View::getAttribute | ( | const std::string & | name | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
const Attribute* axom::sidre::View::getAttribute | ( | const std::string & | name | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return true if the attribute has been explicitly set; else false.
References getAttribute().
|
inline |
Return true if the attribute has been explicitly set; else false.
References getAttribute().
|
inline |
Return true if the attribute has been explicitly set; else false.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
Set Attribute to its default value.
[in] | idx | Attribute identifier |
This causes hasAttributeValue to return false for the attribute.
References getAttribute().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References getAttribute().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
Set Attribute to a scalar value.
If no such Attribute exists, this is a no-op.
References getAttribute().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References getAttribute().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
bool axom::sidre::View::setAttributeString | ( | IndexType | indx, |
const std::string & | value | ||
) |
bool axom::sidre::View::setAttributeString | ( | const std::string & | name, |
const std::string & | value | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool axom::sidre::View::setAttributeString | ( | const Attribute * | attr, |
const std::string & | value | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return scalar Attribute value.
[in] | idx | Attribute identifier. |
If no such Attribute exists, return empty scalar value.
References getAttribute().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References getAttribute().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
Lightweight templated wrapper around getAttributeScalar() that can be used when you are calling getAttributeScalar(), but not assigning the return type.
References getAttribute().
|
inline |
Lightweight templated wrapper around getAttributeScalar() that can be used when you are calling getAttributeScalar(), but not assigning the return type.
References getAttribute().
|
inline |
Lightweight templated wrapper around getAttributeScalar() that can be used when you are calling getAttributeScalar(), but not assigning the return type.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
const char* axom::sidre::View::getAttributeString | ( | IndexType | idx | ) | const |
const char* axom::sidre::View::getAttributeString | ( | const std::string & | name | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
const char* axom::sidre::View::getAttributeString | ( | const Attribute * | attr | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Return reference to an Attribute node.
[in] | idx | Attribute identifier |
If the value has not been explicitly set, return the current default.
References getAttribute().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References getAttribute().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References SIDRE_VIEW_LOG_PREPEND, and SLIC_CHECK_MSG.
|
inline |
Return first valid Attribute index for a set Attribute in View object (i.e., smallest index over all Attributes).
sidre::InvalidIndex is returned if View has no Attributes set.
Return next valid Attribute index for a set Attribute in View object after given index (i.e., smallest index over all Attribute indices larger than given one).
sidre::InvalidIndex is returned if there is no valid index greater than given one. getNextAttrValueIndex(InvalidIndex) returns InvalidIndex.
|
friend |
|
friend |