OpenVDB  6.1.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
AttributeSet Class Reference

Ordered collection of uniquely-named attribute arrays. More...

#include <AttributeSet.h>

Inherits Descriptor.

Classes

struct  Inserter
 Utility method to construct a NameAndType sequence. More...
 
struct  Util
 

Public Types

enum  { INVALID_POS = std::numeric_limits<size_t>::max() }
 
using Ptr = std::shared_ptr< AttributeSet >
 
using ConstPtr = std::shared_ptr< const AttributeSet >
 
using DescriptorPtr = std::shared_ptr< Descriptor >
 
using DescriptorConstPtr = std::shared_ptr< const Descriptor >
 
using Ptr = std::shared_ptr< Descriptor >
 
using NameAndType = Util::NameAndType
 
using NameAndTypeVec = Util::NameAndTypeVec
 
using GroupIndex = Util::GroupIndex
 
using NameToPosMap = Util::NameToPosMap
 
using ConstIterator = NameToPosMap::const_iterator
 

Public Member Functions

 AttributeSet ()
 
 AttributeSet (const AttributeSet &attributeSet, Index arrayLength)
 
 AttributeSet (const DescriptorPtr &descriptor, Index arrayLength=1)
 
 AttributeSet (const AttributeSet &)
 Shallow copy constructor, the descriptor and attribute arrays will be shared. More...
 
AttributeSetoperator= (const AttributeSet &)=delete
 Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow. More...
 
DescriptorPtr descriptorPtr () const
 Return a pointer to this attribute set's descriptor, which might be shared with other sets. More...
 
size_t size () const
 Return the number of attributes in this set. More...
 
size_t memUsage () const
 Return the number of bytes of memory used by this attribute set. More...
 
size_t find (const std::string &name) const
 Return the position of the attribute array whose name is name, or INVALID_POS if no match is found. More...
 
size_t replace (const std::string &name, const AttributeArray::Ptr &)
 Replace the attribute array whose name is name. More...
 
size_t replace (size_t pos, const AttributeArray::Ptr &)
 Replace the attribute array stored at position pos in this container. More...
 
Util::GroupIndex groupIndex (const Name &groupName) const
 Return the group index from the name of the group. More...
 
Util::GroupIndex groupIndex (const size_t offset) const
 
bool isShared (size_t pos) const
 Return true if the attribute array stored at position pos is shared. More...
 
void makeUnique (size_t pos)
 If the attribute array stored at position pos is shared, replace the array with a deep copy of itself that is not shared with anyone else. More...
 
AttributeArray::Ptr appendAttribute (const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr defaultValue=Metadata::Ptr())
 Append attribute attribute (simple method) More...
 
AttributeArray::Ptr appendAttribute (const Descriptor &expected, DescriptorPtr &replacement, const size_t pos, const Index strideOrTotalSize=1, const bool constantStride=true)
 
void dropAttributes (const std::vector< size_t > &pos)
 
void dropAttributes (const std::vector< size_t > &pos, const Descriptor &expected, DescriptorPtr &replacement)
 
void renameAttributes (const Descriptor &expected, const DescriptorPtr &replacement)
 
void reorderAttributes (const DescriptorPtr &replacement)
 
void resetDescriptor (const DescriptorPtr &replacement, const bool allowMismatchingDescriptors=false)
 
void read (std::istream &)
 Read the entire set from a stream. More...
 
void write (std::ostream &, bool outputTransient=false) const
 
void readDescriptor (std::istream &)
 This will read the attribute descriptor from a stream. More...
 
void writeDescriptor (std::ostream &, bool outputTransient=false) const
 
void readMetadata (std::istream &)
 This will read the attribute metadata from a stream. More...
 
void writeMetadata (std::ostream &, bool outputTransient=false, bool paged=false) const
 
void readAttributes (std::istream &)
 This will read the attribute data from a stream. More...
 
void writeAttributes (std::ostream &, bool outputTransient=false) const
 
bool operator== (const AttributeSet &other) const
 
bool operator!= (const AttributeSet &other) const
 
 Descriptor ()
 
 Descriptor (const Descriptor &)
 Copy constructor. More...
 
Ptr duplicateAppend (const Name &name, const NamePair &type) const
 Create a new descriptor as a duplicate with a new attribute appended. More...
 
Ptr duplicateDrop (const std::vector< size_t > &pos) const
 Create a new descriptor as a duplicate with existing attributes dropped. More...
 
size_t size () const
 Return the number of attributes in this descriptor. More...
 
size_t count (const NamePair &type) const
 Return the number of attributes with this attribute type. More...
 
size_t memUsage () const
 Return the number of bytes of memory used by this attribute set. More...
 
size_t find (const std::string &name) const
 Return the position of the attribute array whose name is name, or INVALID_POS if no match is found. More...
 
size_t rename (const std::string &fromName, const std::string &toName)
 Rename an attribute array. More...
 
const NamevalueType (size_t pos) const
 Return the name of the attribute array's type. More...
 
const NamePairtype (size_t pos) const
 Return the name of the attribute array's type. More...
 
MetaMapgetMetadata ()
 Retrieve metadata map. More...
 
const MetaMapgetMetadata () const
 
bool hasDefaultValue (const Name &name) const
 Return true if the attribute has a default value. More...
 
template<typename ValueType >
ValueType getDefaultValue (const Name &name) const
 Get a default value for an existing attribute. More...
 
void setDefaultValue (const Name &name, const Metadata &defaultValue)
 Set a default value for an existing attribute. More...
 
void removeDefaultValue (const Name &name)
 
void pruneUnusedDefaultValues ()
 
bool operator== (const Descriptor &) const
 Return true if this descriptor is equal to the given one. More...
 
bool operator!= (const Descriptor &rhs) const
 Return true if this descriptor is not equal to the given one. More...
 
bool hasSameAttributes (const Descriptor &rhs) const
 
const NameToPosMapmap () const
 Return a reference to the name-to-position map. More...
 
const NameToPosMapgroupMap () const
 Return a reference to the name-to-position group map. More...
 
bool hasGroup (const Name &group) const
 Return true if group exists. More...
 
void setGroup (const Name &group, const size_t offset)
 Define a group name to offset mapping. More...
 
void dropGroup (const Name &group)
 Drop any mapping keyed by group name. More...
 
void clearGroups ()
 Clear all groups. More...
 
size_t renameGroup (const std::string &fromName, const std::string &toName)
 Rename a group. More...
 
const Name uniqueGroupName (const Name &name) const
 Return a unique name for a group based on given name. More...
 
GroupIndex groupIndex (const Name &groupName) const
 Return the group index from the name of the group. More...
 
GroupIndex groupIndex (const size_t offset) const
 
const Name uniqueName (const Name &name) const
 Return a unique name for an attribute array based on given name. More...
 
void write (std::ostream &) const
 Serialize this descriptor to the given stream. More...
 
void read (std::istream &)
 Unserialize this transform from the given stream. More...
 
Descriptordescriptor ()
 Return a reference to this attribute set's descriptor, which might be shared with other sets. More...
 
const Descriptordescriptor () const
 Return a reference to this attribute set's descriptor, which might be shared with other sets. More...
 
const AttributeArraygetConst (const std::string &name) const
 Return a pointer to the attribute array whose name is name or a null pointer if no match is found. More...
 
const AttributeArrayget (const std::string &name) const
 Return a pointer to the attribute array whose name is name or a null pointer if no match is found. More...
 
AttributeArrayget (const std::string &name)
 Return a pointer to the attribute array whose name is name or a null pointer if no match is found. More...
 
const AttributeArraygetConst (size_t pos) const
 Return a pointer to the attribute array stored at position pos in this set. More...
 
const AttributeArrayget (size_t pos) const
 Return a pointer to the attribute array stored at position pos in this set. More...
 
AttributeArrayget (size_t pos)
 Return a pointer to the attribute array stored at position pos in this set. More...
 
size_t groupOffset (const Name &groupName) const
 Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set. More...
 
size_t groupOffset (const Util::GroupIndex &index) const
 Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set. More...
 
size_t groupOffset (const Name &groupName) const
 Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set. More...
 
size_t groupOffset (const GroupIndex &index) const
 Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set. More...
 

Static Public Member Functions

static Ptr create (const NamePair &)
 Create a new descriptor from a position attribute type and assumes "P" (for convenience). More...
 
static bool validName (const Name &name)
 Return true if the name is valid. More...
 
static void parseNames (std::vector< std::string > &includeNames, std::vector< std::string > &excludeNames, bool &includeAll, const std::string &nameStr)
 Extract each name from nameStr into includeNames, or into excludeNames if the name is prefixed with a caret. More...
 
static void parseNames (std::vector< std::string > &includeNames, std::vector< std::string > &excludeNames, const std::string &nameStr)
 Extract each name from nameStr into includeNames, or into excludeNames if the name is prefixed with a caret. More...
 

Protected Member Functions

void appendTo (NameAndTypeVec &attrs) const
 Append to a vector of names and types from this Descriptor in position order. More...
 
size_t insert (const std::string &name, const NamePair &typeName)
 

Static Protected Member Functions

static Ptr create (const NameAndTypeVec &, const NameToPosMap &, const MetaMap &)
 

Friends

class ::TestAttributeSet
 

Detailed Description

Ordered collection of uniquely-named attribute arrays.

An immutable object that stores name, type and AttributeSet position for a constant collection of attribute arrays.

Note
The attribute name is actually mutable, but the attribute type and position can not be changed after creation.

Member Typedef Documentation

using ConstIterator = NameToPosMap::const_iterator
using ConstPtr = std::shared_ptr<const AttributeSet>
using DescriptorConstPtr = std::shared_ptr<const Descriptor>
using DescriptorPtr = std::shared_ptr<Descriptor>
using Ptr = std::shared_ptr<AttributeSet>
using Ptr = std::shared_ptr<Descriptor>

Member Enumeration Documentation

anonymous enum
Enumerator
INVALID_POS 

Constructor & Destructor Documentation

AttributeSet ( const AttributeSet attributeSet,
Index  arrayLength 
)

Construct a new AttributeSet from the given AttributeSet.

Parameters
attributeSetthe old attribute set
arrayLengththe desired length of the arrays in the new AttributeSet
Note
This constructor is typically used to resize an existing AttributeSet as it transfers attribute metadata such as hidden and transient flags
AttributeSet ( const DescriptorPtr descriptor,
Index  arrayLength = 1 
)
explicit

Construct a new AttributeSet from the given Descriptor.

Parameters
descriptorstored in the new AttributeSet and used in construction
arrayLengththe desired length of the arrays in the new AttributeSet
Note
Descriptors do not store attribute metadata such as hidden and transient flags which live on the AttributeArrays, so for constructing from an existing AttributeSet use the AttributeSet(const AttributeSet&, Index) constructor instead
AttributeSet ( const AttributeSet )

Shallow copy constructor, the descriptor and attribute arrays will be shared.

Member Function Documentation

AttributeArray::Ptr appendAttribute ( const Name name,
const NamePair type,
const Index  strideOrTotalSize = 1,
const bool  constantStride = true,
Metadata::Ptr  defaultValue = Metadata::Ptr() 
)

Append attribute attribute (simple method)

AttributeArray::Ptr appendAttribute ( const Descriptor expected,
DescriptorPtr replacement,
const size_t  pos,
const Index  strideOrTotalSize = 1,
const bool  constantStride = true 
)

Append attribute attribute (descriptor-sharing) Requires current descriptor to match expected On append, current descriptor is replaced with replacement

void appendTo ( NameAndTypeVec attrs) const
protected

Append to a vector of names and types from this Descriptor in position order.

void clearGroups ( )

Clear all groups.

size_t count ( const NamePair type) const

Return the number of attributes with this attribute type.

static Ptr create ( const NamePair )
static

Create a new descriptor from a position attribute type and assumes "P" (for convenience).

static Ptr create ( const NameAndTypeVec ,
const NameToPosMap ,
const MetaMap  
)
staticprotected

Create a new descriptor from the given attribute and type name pairs and copy the group maps and metamap.

Descriptor& descriptor ( )
inline

Return a reference to this attribute set's descriptor, which might be shared with other sets.

const Descriptor& descriptor ( ) const
inline

Return a reference to this attribute set's descriptor, which might be shared with other sets.

Descriptor ( )
Descriptor ( const Descriptor &  )

Copy constructor.

DescriptorPtr descriptorPtr ( ) const
inline

Return a pointer to this attribute set's descriptor, which might be shared with other sets.

void dropAttributes ( const std::vector< size_t > &  pos)

Drop attributes with pos indices (simple method) Creates a new descriptor for this attribute set

void dropAttributes ( const std::vector< size_t > &  pos,
const Descriptor expected,
DescriptorPtr replacement 
)

Drop attributes with pos indices (descriptor-sharing method) Requires current descriptor to match expected On drop, current descriptor is replaced with replacement

void dropGroup ( const Name group)

Drop any mapping keyed by group name.

Ptr duplicateAppend ( const Name name,
const NamePair type 
) const

Create a new descriptor as a duplicate with a new attribute appended.

Ptr duplicateDrop ( const std::vector< size_t > &  pos) const

Create a new descriptor as a duplicate with existing attributes dropped.

size_t find ( const std::string &  name) const

Return the position of the attribute array whose name is name, or INVALID_POS if no match is found.

size_t find ( const std::string &  name) const

Return the position of the attribute array whose name is name, or INVALID_POS if no match is found.

const AttributeArray* get ( const std::string &  name) const

Return a pointer to the attribute array whose name is name or a null pointer if no match is found.

AttributeArray* get ( const std::string &  name)

Return a pointer to the attribute array whose name is name or a null pointer if no match is found.

const AttributeArray* get ( size_t  pos) const

Return a pointer to the attribute array stored at position pos in this set.

AttributeArray* get ( size_t  pos)

Return a pointer to the attribute array stored at position pos in this set.

const AttributeArray* getConst ( const std::string &  name) const

Return a pointer to the attribute array whose name is name or a null pointer if no match is found.

const AttributeArray* getConst ( size_t  pos) const

Return a pointer to the attribute array stored at position pos in this set.

ValueType getDefaultValue ( const Name name) const
inline

Get a default value for an existing attribute.

MetaMap& getMetadata ( )

Retrieve metadata map.

const MetaMap& getMetadata ( ) const
Util::GroupIndex groupIndex ( const Name groupName) const

Return the group index from the name of the group.

Util::GroupIndex groupIndex ( const size_t  offset) const

Return the group index from the offset of the group

Note
see offset description for groupOffset()
GroupIndex groupIndex ( const Name groupName) const

Return the group index from the name of the group.

GroupIndex groupIndex ( const size_t  offset) const

Return the group index from the offset of the group

Note
see offset description for groupOffset()
const NameToPosMap& groupMap ( ) const
inline

Return a reference to the name-to-position group map.

size_t groupOffset ( const Name groupName) const

Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set.

size_t groupOffset ( const Util::GroupIndex index) const

Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set.

size_t groupOffset ( const Name groupName) const

Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set.

size_t groupOffset ( const GroupIndex index) const

Return the group offset from the name or index of the group A group attribute array is a single byte (8-bit), each bit of which can denote a group. The group offset is the position of the bit that denotes the requested group if all group attribute arrays in the set (and only attribute arrays marked as group) were to be laid out linearly according to their order in the set.

bool hasDefaultValue ( const Name name) const

Return true if the attribute has a default value.

bool hasGroup ( const Name group) const

Return true if group exists.

bool hasSameAttributes ( const Descriptor rhs) const

Return true if this descriptor contains the same attributes as the given descriptor, ignoring attribute order

size_t insert ( const std::string &  name,
const NamePair typeName 
)
protected
bool isShared ( size_t  pos) const

Return true if the attribute array stored at position pos is shared.

void makeUnique ( size_t  pos)

If the attribute array stored at position pos is shared, replace the array with a deep copy of itself that is not shared with anyone else.

const NameToPosMap& map ( ) const
inline

Return a reference to the name-to-position map.

size_t memUsage ( ) const

Return the number of bytes of memory used by this attribute set.

size_t memUsage ( ) const

Return the number of bytes of memory used by this attribute set.

bool operator!= ( const AttributeSet other) const
inline
bool operator!= ( const Descriptor rhs) const
inline

Return true if this descriptor is not equal to the given one.

AttributeSet& operator= ( const AttributeSet )
delete

Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow.

bool operator== ( const AttributeSet other) const

Compare the descriptors and attribute arrays on the attribute sets Exit early if the descriptors do not match

bool operator== ( const Descriptor ) const

Return true if this descriptor is equal to the given one.

static void parseNames ( std::vector< std::string > &  includeNames,
std::vector< std::string > &  excludeNames,
bool &  includeAll,
const std::string &  nameStr 
)
static

Extract each name from nameStr into includeNames, or into excludeNames if the name is prefixed with a caret.

Parameters
nameStrthe input string of names
includeNameson exit, the list of names that are not prefixed with a caret
excludeNameson exit, the list of names that are prefixed with a caret
includeAllon exit, true if a "*" wildcard is present in the includeNames
static void parseNames ( std::vector< std::string > &  includeNames,
std::vector< std::string > &  excludeNames,
const std::string &  nameStr 
)
static

Extract each name from nameStr into includeNames, or into excludeNames if the name is prefixed with a caret.

void pruneUnusedDefaultValues ( )
void read ( std::istream &  )

Read the entire set from a stream.

void read ( std::istream &  )

Unserialize this transform from the given stream.

void readAttributes ( std::istream &  )

This will read the attribute data from a stream.

void readDescriptor ( std::istream &  )

This will read the attribute descriptor from a stream.

void readMetadata ( std::istream &  )

This will read the attribute metadata from a stream.

void removeDefaultValue ( const Name name)
size_t rename ( const std::string &  fromName,
const std::string &  toName 
)

Rename an attribute array.

void renameAttributes ( const Descriptor expected,
const DescriptorPtr replacement 
)

Re-name attributes in set to match a provided descriptor Replaces own descriptor with replacement

size_t renameGroup ( const std::string &  fromName,
const std::string &  toName 
)

Rename a group.

void reorderAttributes ( const DescriptorPtr replacement)

Re order attribute set to match a provided descriptor Replaces own descriptor with replacement

size_t replace ( const std::string &  name,
const AttributeArray::Ptr  
)

Replace the attribute array whose name is name.

Returns
The position of the updated attribute array or INVALID_POS if the given name does not exist or if the replacement failed because the new array type does not comply with the descriptor.
size_t replace ( size_t  pos,
const AttributeArray::Ptr  
)

Replace the attribute array stored at position pos in this container.

Returns
The position of the updated attribute array or INVALID_POS if replacement failed because the new array type does not comply with the descriptor.
void resetDescriptor ( const DescriptorPtr replacement,
const bool  allowMismatchingDescriptors = false 
)

Replace the current descriptor with a replacement Note the provided Descriptor must be identical to the replacement unless allowMismatchingDescriptors is true (default is false)

void setDefaultValue ( const Name name,
const Metadata defaultValue 
)

Set a default value for an existing attribute.

void setGroup ( const Name group,
const size_t  offset 
)

Define a group name to offset mapping.

size_t size ( ) const
inline

Return the number of attributes in this set.

size_t size ( ) const
inline

Return the number of attributes in this descriptor.

const NamePair& type ( size_t  pos) const

Return the name of the attribute array's type.

const Name uniqueGroupName ( const Name name) const

Return a unique name for a group based on given name.

const Name uniqueName ( const Name name) const

Return a unique name for an attribute array based on given name.

static bool validName ( const Name name)
static

Return true if the name is valid.

const Name& valueType ( size_t  pos) const

Return the name of the attribute array's type.

void write ( std::ostream &  ,
bool  outputTransient = false 
) const

Write the entire set to a stream.

Parameters
outputTransientif true, write out transient attributes
void write ( std::ostream &  ) const

Serialize this descriptor to the given stream.

void writeAttributes ( std::ostream &  ,
bool  outputTransient = false 
) const

This will write the attribute data to a stream.

Parameters
outputTransientif true, write out transient attributes
void writeDescriptor ( std::ostream &  ,
bool  outputTransient = false 
) const

This will write the attribute descriptor to a stream.

Parameters
outputTransientif true, write out transient attributes
void writeMetadata ( std::ostream &  ,
bool  outputTransient = false,
bool  paged = false 
) const

This will write the attribute metadata to a stream.

Parameters
outputTransientif true, write out transient attributes
pagedif true, data is written out in pages

Friends And Related Function Documentation

friend class ::TestAttributeSet
friend

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