ROSE
0.11.96.11
|
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... | |
Storage & | operator= (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 > | |
T | getAttribute (Id id) const |
Get an attribute that is known to exist. More... | |
template<typename T > | |
T | attributeOrElse (Id id, const T &dflt) const |
Return an attribute or a specified value. More... | |
template<typename T > | |
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< Id > | attributeIds () const |
Returns ID numbers for all IDs stored in this container. More... | |
|
inline |
Default constructor.
Thread safety: This method is thread safe when synchronization is enabled.
Definition at line 221 of file Attribute.h.
|
inline |
Copy constructor.
Thread safety: This method is thread safe when synchronization is enabled.
Definition at line 227 of file Attribute.h.
|
inline |
Assignment operator.
Thread safety: This method is thread safe when synchronization is enabled.
Definition at line 235 of file Attribute.h.
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().