ROSE 0.11.145.147
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 215 of file Attribute.h.

#include <Sawyer/Attribute.h>

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

Public Types

typedef SynchronizationTraits< SyncTag > Sync
 

Public Member Functions

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

Member Typedef Documentation

◆ Sync

template<class SyncTag = Sawyer::SingleThreadedTag>
typedef SynchronizationTraits<SyncTag> Sawyer::Attribute::Storage< SyncTag >::Sync

Definition at line 217 of file Attribute.h.

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 228 of file Attribute.h.

◆ ~Storage()

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

Definition at line 229 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 234 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 242 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 253 of file Attribute.h.

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

◆ 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 264 of file Attribute.h.

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

◆ 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 272 of file Attribute.h.

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

◆ 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 285 of file Attribute.h.

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

◆ 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 298 of file Attribute.h.

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

◆ 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 315 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().

◆ 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 338 of file Attribute.h.

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

◆ 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 352 of file Attribute.h.

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

◆ 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 366 of file Attribute.h.

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

◆ 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 377 of file Attribute.h.

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

◆ 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 385 of file Attribute.h.

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


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