ROSE  0.11.96.11
Public Types | Public Member Functions | List of all members
Sawyer::Attribute::Storage< SyncTag > Class Template Reference

Description

template<class SyncTag = Sawyer::SingleThreadedTag>
class Sawyer::Attribute::Storage< SyncTag >

API and storage for attributes.

This is the interface inherited by objects that can store attributes. See the namespace for usage and examples.

This attribute container can either synchronize access to its members in a multi-threaded environment, or not synchronize. Synchronization can be disabled, in which case the container is slightly faster but the user must synchronize at a higher level. The default is to synchronize access if Sawyer is configured with multi-thread support. The SyncTag template argument should be either MultiThreadedTag or SingleThreadedTag.

Definition at line 208 of file Attribute.h.

#include <Attribute.h>

Public Types

typedef SynchronizationTraits< SyncTag > Sync
 

Public Member Functions

 Storage ()
 Default constructor. More...
 
 Storage (const Storage &other)
 Copy constructor. More...
 
Storageoperator= (const Storage &other)
 Assignment operator. More...
 
bool attributeExists (Id id) const
 Check attribute existence. More...
 
void eraseAttribute (Id id)
 Erase an attribute. More...
 
void clearAttributes ()
 Erase all attributes. More...
 
template<typename T >
void setAttribute (Id id, const T &value)
 Store an attribute. More...
 
template<typename T >
bool setAttributeMaybe (Id id, const T &value)
 Store an attribute if not already present. More...
 
template<typename T >
getAttribute (Id id) const
 Get an attribute that is known to exist. More...
 
template<typename T >
attributeOrElse (Id id, const T &dflt) const
 Return an attribute or a specified value. More...
 
template<typename T >
attributeOrDefault (Id id) const
 Return an attribute or a default-constructed value. More...
 
template<typename T >
Sawyer::Optional< T > optionalAttribute (Id id) const
 Return the attribute as an optional value. More...
 
size_t nAttributes () const
 Number of attributes stored. More...
 
std::vector< IdattributeIds () const
 Returns ID numbers for all IDs stored in this container. More...
 

Constructor & Destructor Documentation

◆ Storage() [1/2]

template<class SyncTag = Sawyer::SingleThreadedTag>
Sawyer::Attribute::Storage< SyncTag >::Storage ( )
inline

Default constructor.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 221 of file Attribute.h.

◆ Storage() [2/2]

template<class SyncTag = Sawyer::SingleThreadedTag>
Sawyer::Attribute::Storage< SyncTag >::Storage ( const Storage< SyncTag > &  other)
inline

Copy constructor.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 227 of file Attribute.h.

Member Function Documentation

◆ operator=()

template<class SyncTag = Sawyer::SingleThreadedTag>
Storage& Sawyer::Attribute::Storage< SyncTag >::operator= ( const Storage< SyncTag > &  other)
inline

Assignment operator.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 235 of file Attribute.h.

◆ attributeExists()

template<class SyncTag = Sawyer::SingleThreadedTag>
bool Sawyer::Attribute::Storage< SyncTag >::attributeExists ( Id  id) const
inline

Check attribute existence.

Returns true if an attribute with the specified identification number exists in this object, false otherwise.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 246 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::exists().

Here is the call graph for this function:

◆ eraseAttribute()

template<class SyncTag = Sawyer::SingleThreadedTag>
void Sawyer::Attribute::Storage< SyncTag >::eraseAttribute ( Id  id)
inline

Erase an attribute.

Causes the attribute to not be stored anymore. Does nothing if the attribute was not stored to begin with. Upon return, the attributeExists method will return false for this id.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 257 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::erase().

Here is the call graph for this function:

◆ clearAttributes()

template<class SyncTag = Sawyer::SingleThreadedTag>
void Sawyer::Attribute::Storage< SyncTag >::clearAttributes ( )
inline

Erase all attributes.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 265 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::clear().

Here is the call graph for this function:

◆ setAttribute()

template<class SyncTag = Sawyer::SingleThreadedTag>
template<typename T >
void Sawyer::Attribute::Storage< SyncTag >::setAttribute ( Id  id,
const T &  value 
)
inline

Store an attribute.

Stores the specified value for the specified attribute, overwriting any previously stored value for the specified key. The attribute type can be almost anything and can be changed for each call, but the same type must be used when retrieving the attribute.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 278 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::insert().

Here is the call graph for this function:

◆ setAttributeMaybe()

template<class SyncTag = Sawyer::SingleThreadedTag>
template<typename T >
bool Sawyer::Attribute::Storage< SyncTag >::setAttributeMaybe ( Id  id,
const T &  value 
)
inline

Store an attribute if not already present.

Stores the specified value if the specified attribute does not yet exist. Returns true if the value was stored, false if not stored. The attribute type can be almost anything and can be changed for each call, but the same type must be used when retrieving the attribute.

Thread safety: Ths method is thread safe when synchronization is enabled.

Definition at line 291 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::exists(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::insert().

Here is the call graph for this function:

◆ getAttribute()

template<class SyncTag = Sawyer::SingleThreadedTag>
template<typename T >
T Sawyer::Attribute::Storage< SyncTag >::getAttribute ( Id  id) const
inline

Get an attribute that is known to exist.

Returns the value for the attribute with the specified id. The attribute must exist or a DoesNotExist exception is thrown. The type must match the type used when the attribute was stored, or a WrongQueryType exception is thrown.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 308 of file Attribute.h.

References Sawyer::checkBoost(), Sawyer::Container::Map< K, T, Cmp, Alloc >::find(), Sawyer::Container::Map< K, T, Cmp, Alloc >::getOptional(), Sawyer::Attribute::name(), Sawyer::Container::Map< K, T, Cmp, Alloc >::nodes(), and Sawyer::Optional< T >::orDefault().

Here is the call graph for this function:

◆ attributeOrElse()

template<class SyncTag = Sawyer::SingleThreadedTag>
template<typename T >
T Sawyer::Attribute::Storage< SyncTag >::attributeOrElse ( Id  id,
const T &  dflt 
) const
inline

Return an attribute or a specified value.

If the attribute exists, return its value, otherwise return the specified value. Throws WrongQueryType if the stored attribute's value type doesn't match the type of the provided default value (if no value is stored then the provided default type isn't checked).

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 331 of file Attribute.h.

References Sawyer::checkBoost(), Sawyer::Container::Map< K, T, Cmp, Alloc >::getOptional(), and Sawyer::Optional< T >::orElse().

Here is the call graph for this function:

◆ attributeOrDefault()

template<class SyncTag = Sawyer::SingleThreadedTag>
template<typename T >
T Sawyer::Attribute::Storage< SyncTag >::attributeOrDefault ( Id  id) const
inline

Return an attribute or a default-constructed value.

Returns the attribute value if it exists, or a default-constructed value otherwise. Throws WrongQueryType if the stored attribute's value type doesn't match the specified type (if no value is stored then the default type isn't checked).

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 345 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::find(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::nodes().

Here is the call graph for this function:

◆ optionalAttribute()

template<class SyncTag = Sawyer::SingleThreadedTag>
template<typename T >
Sawyer::Optional<T> Sawyer::Attribute::Storage< SyncTag >::optionalAttribute ( Id  id) const
inline

Return the attribute as an optional value.

Returns the attribute value if it exists, or returns nothing.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 359 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::find(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::nodes().

Here is the call graph for this function:

◆ nAttributes()

template<class SyncTag = Sawyer::SingleThreadedTag>
size_t Sawyer::Attribute::Storage< SyncTag >::nAttributes ( ) const
inline

Number of attributes stored.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 370 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::size().

Here is the call graph for this function:

◆ attributeIds()

template<class SyncTag = Sawyer::SingleThreadedTag>
std::vector<Id> Sawyer::Attribute::Storage< SyncTag >::attributeIds ( ) const
inline

Returns ID numbers for all IDs stored in this container.

Thread safety: This method is thread safe when synchronization is enabled.

Definition at line 378 of file Attribute.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::keys(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::size().

Here is the call graph for this function:

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