EventAnalysis
1.3.0
|
A map between strings and objects of ObjectWrapper kind. More...
#include <ObjectMap.h>
Classes | |
struct | Alias |
Public Member Functions | |
~ObjectMap () | |
Destructor. More... | |
template<class DataType > | |
InsertionResult | AddObject (const std::string &name, DataType &obj) |
Adds an object to the map. More... | |
template<class DataType > | |
InsertionResult | AddObject (const std::string &name, observer_ptr< DataType > obj) |
Adds an object to the map. More... | |
InsertionResult | AddObject (const std::string &name, const char *obj) |
Adds a string literal to the map. More... | |
template<class DataType > | |
InsertionResult | AddObject (const std::string &name, std::shared_ptr< DataType > obj) |
Adds an object to the map. More... | |
template<class DataType > | |
InsertionResult | AddObject (const std::string &name, std::unique_ptr< DataType > obj) |
Adds an object to the map. More... | |
InsertionResult | SetAlias (const std::string &objName, const std::string &objAlias) |
Set an alias for the given object. More... | |
template<class DataType > | |
ObjPtr< DataType > | GetObject (const std::string &name) |
Retrieves an object given its name. More... | |
ObjectWrapper | GetObjectWrapper (const std::string &objName) |
Get a wrapper for a given object. More... | |
const std::string & | GetNameOfAliasedObject (const std::string &aliasName) |
Gets the name of the object corresponding to an alias. More... | |
bool | RemoveObject (const std::string &name, bool removeAliased=false) |
Removes an object or an alias from the map. More... | |
std::vector< std::string > | GetObjects () const |
Returns the names of the objects in the map. More... | |
bool | IsPresent (const std::string &nameOrAlias) const |
Checks if an object is present in the map. More... | |
std::vector< std::string > | GetAliases (const std::string &name="") const |
Returns the aliases of the objects in the map. More... | |
bool | Clean () |
Removes all the objects and aliases from the map. More... | |
bool | CleanAliases () |
Removes all the aliases from the map. More... | |
std::string | GetObjectClass (const std::string &objName) |
Get the class name of an object in the store. More... | |
bool | IsAlias (const std::string &objName) |
Checks if an object name is actually an alias. More... | |
Protected Member Functions | |
InsertionResult | AddObject (const std::string &name, ObjectWrapper &&wrapper) |
Add an already wrapped object. More... | |
Private Types | |
using | Map = std::unordered_map< std::string, ObjectWrapper > |
using | Aliases = std::vector< Alias > |
Private Member Functions | |
Aliases::iterator | _FindAlias (const std::string &aliasName) |
std::vector< Aliases::iterator > | _FindAliasesOf (const std::string &objName) |
Private Attributes | |
Map | _map |
Aliases | _aliases |
A map between strings and objects of ObjectWrapper kind.
This class maps names to actual objects of ObjectWrapper kind.
|
private |
|
private |
EA::ObjectMap::~ObjectMap | ( | ) |
Destructor.
|
inlineprivate |
|
inlineprivate |
InsertionResult EA::ObjectMap::AddObject | ( | const std::string & | name, |
DataType & | obj | ||
) |
Adds an object to the map.
The object referenced by #obj is added to the map. The map will not own the object.
name | The name of the object. |
obj | Reference to the object. |
InsertionResult EA::ObjectMap::AddObject | ( | const std::string & | name, |
observer_ptr< DataType > | obj | ||
) |
Adds an object to the map.
The object pointed by #obj is added to the map. The map will not own the object.
name | The name of the object. |
obj | Pointer to the object. |
InsertionResult EA::ObjectMap::AddObject | ( | const std::string & | name, |
const char * | obj | ||
) |
Adds a string literal to the map.
Specialization for string literals. Stores the literal as an std::string, so when retrieving it with GetObject the template type std::string must be used.
name | The name of the object. |
obj | The string literal. |
InsertionResult EA::ObjectMap::AddObject | ( | const std::string & | name, |
std::shared_ptr< DataType > | obj | ||
) |
Adds an object to the map.
The object pointed by obj is added to the map. The map will own the object.
name | The name of the object. |
obj | Pointer to the object. |
InsertionResult EA::ObjectMap::AddObject | ( | const std::string & | name, |
std::unique_ptr< DataType > | obj | ||
) |
Adds an object to the map.
The object pointed by #obj is added to the map. The map will own the object.
name | The name of the object. |
obj | Pointer to the object. |
|
protected |
Add an already wrapped object.
This protected method is intended to be used by derived classes which handles object wrappers directly. The wrapper is moved to the internal object map
name | The name of the object to be added. |
wrapper | The object wrapper. |
bool EA::ObjectMap::Clean | ( | ) |
Removes all the objects and aliases from the map.
Owned object will be deleted.
bool EA::ObjectMap::CleanAliases | ( | ) |
Removes all the aliases from the map.
REmoves all the alias but not the aliased objects
std::vector< std::string > EA::ObjectMap::GetAliases | ( | const std::string & | name = "" | ) | const |
Returns the aliases of the objects in the map.
Returns a list of aliases for the given object. If no object name is specified then a list of all the currently defined aliases for all the objects in the map will be returned.
name | The name of the object. |
name
is not given. const std::string & EA::ObjectMap::GetNameOfAliasedObject | ( | const std::string & | aliasName | ) |
Gets the name of the object corresponding to an alias.
aliasName | The alias. |
ObjPtr< DataType > EA::ObjectMap::GetObject | ( | const std::string & | name | ) |
Retrieves an object given its name.
The object with the given name is retrieved from the map. If the object cannot be found, or if its type does not match the template argument (neither exactly nor polymorphically), the returned pointer will point to nullptr.
name | The name of the desired object. |
std::string EA::ObjectMap::GetObjectClass | ( | const std::string & | objName | ) |
Get the class name of an object in the store.
objName | The name of the desired object |
std::vector< std::string > EA::ObjectMap::GetObjects | ( | ) | const |
Returns the names of the objects in the map.
ObjectWrapper EA::ObjectMap::GetObjectWrapper | ( | const std::string & | objName | ) |
Get a wrapper for a given object.
The returned wrapper wraps the requested object (or nothing if the object has not been found). In order to get access to the wrapped object use GetObject instead of this method.
objName | The desired object. |
bool EA::ObjectMap::IsAlias | ( | const std::string & | objName | ) |
Checks if an object name is actually an alias.
objName | The name to be checked. |
bool EA::ObjectMap::IsPresent | ( | const std::string & | nameOrAlias | ) | const |
Checks if an object is present in the map.
nameOrAlias | The name or the alias of the object. |
bool EA::ObjectMap::RemoveObject | ( | const std::string & | name, |
bool | removeAliased = false |
||
) |
Removes an object or an alias from the map.
If the object is owned by the map then it is also deleted. If #name is an alias then the aliased object is removed together with the alias only if #removeAliased is set to true.
name | The name of the object to be deleted. |
removeAliased | if name is an alias then the aliased object will be removed if this parameter is set to true. |
InsertionResult EA::ObjectMap::SetAlias | ( | const std::string & | objName, |
const std::string & | objAlias | ||
) |
Set an alias for the given object.
The alias is an alternative name for an object. It can be assigned to an object and then eventually moved to another one, like a "tag" for the desired object. Asking for an object passing the alias to GetObject or GetObjectWrapper rather than the name will result in the current tagged object being returned. The definition of an alias is subject to the following rules:
objName | The aliased object. |
objAlias | The alias to assign to the aliased object. |
|
private |
|
private |