ROSE  0.9.9.109
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>

Inheritance diagram for Sawyer::Attribute::Storage< SyncTag >:
Inheritance graph
[legend]

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

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.


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