ROSE 0.11.145.192
|
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>
Public Types | |
typedef SynchronizationTraits< SyncTag > | Sync |
Public Member Functions | |
Storage () | |
Default constructor. | |
Storage (const Storage &other) | |
Copy constructor. | |
Storage & | operator= (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 > | |
T | getAttribute (Id id) const |
Get an attribute that is known to exist. | |
template<typename T > | |
Sawyer::Optional< T > | getAttributeMaybe (const Id id) const |
Return an attribute if it exists, or else nothing. | |
template<typename T > | |
T | attributeOrElse (Id id, const T &dflt) const |
Return an attribute or a specified value. | |
template<typename T > | |
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< Id > | attributeIds () const |
Returns ID numbers for all IDs stored in this container. | |
typedef SynchronizationTraits<SyncTag> Sawyer::Attribute::Storage< SyncTag >::Sync |
Definition at line 217 of file Attribute.h.
|
inline |
Default constructor.
Thread safety: This method is thread safe when synchronization is enabled.
Definition at line 228 of file Attribute.h.
|
inline |
Definition at line 229 of file Attribute.h.
|
inline |
Copy constructor.
Thread safety: This method is thread safe when synchronization is enabled.
Definition at line 234 of file Attribute.h.
|
inline |
Assignment operator.
Thread safety: This method is thread safe when synchronization is enabled.
Definition at line 242 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 253 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 264 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 272 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 285 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 298 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 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().
|
inline |
Return an attribute if it exists, or else nothing.
Thread safety: This method is thread safe when synchronization is enabled.
Definition at line 334 of file Attribute.h.
References Sawyer::checkBoost(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::getOptional().
|
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 352 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 366 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 380 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 391 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 399 of file Attribute.h.
References Sawyer::Container::Map< K, T, Cmp, Alloc >::keys(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::size().