EventAnalysis  1.3.0
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
EA::ObjectMap Class Reference

A map between strings and objects of ObjectWrapper kind. More...

#include <ObjectMap.h>

Inheritance diagram for EA::ObjectMap:
EA::DataStore EA::EventDataStore EA::OwningDataStore EA::PassDataStore EA::GlobalDataStore

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
 

Detailed Description

A map between strings and objects of ObjectWrapper kind.

This class maps names to actual objects of ObjectWrapper kind.

Member Typedef Documentation

◆ Aliases

using EA::ObjectMap::Aliases = std::vector<Alias>
private

◆ Map

using EA::ObjectMap::Map = std::unordered_map<std::string, ObjectWrapper>
private

Constructor & Destructor Documentation

◆ ~ObjectMap()

EA::ObjectMap::~ObjectMap ( )

Destructor.

Member Function Documentation

◆ _FindAlias()

Aliases::iterator EA::ObjectMap::_FindAlias ( const std::string &  aliasName)
inlineprivate

◆ _FindAliasesOf()

std::vector<Aliases::iterator> EA::ObjectMap::_FindAliasesOf ( const std::string &  objName)
inlineprivate

◆ AddObject() [1/6]

template<class DataType >
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.

Parameters
nameThe name of the object.
objReference to the object.
Returns
a code with the result of the operation.

◆ AddObject() [2/6]

template<class DataType >
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.

Parameters
nameThe name of the object.
objPointer to the object.
Returns
a code with the result of the operation.

◆ AddObject() [3/6]

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.

Parameters
nameThe name of the object.
objThe string literal.
Returns
a code with the result of the operation.

◆ AddObject() [4/6]

template<class DataType >
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.

Parameters
nameThe name of the object.
objPointer to the object.
Returns
a code with the result of the operation.

◆ AddObject() [5/6]

template<class DataType >
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.

Parameters
nameThe name of the object.
objPointer to the object.
Returns
a code with the result of the operation.

◆ AddObject() [6/6]

InsertionResult EA::ObjectMap::AddObject ( const std::string &  name,
ObjectWrapper &&  wrapper 
)
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

Parameters
nameThe name of the object to be added.
wrapperThe object wrapper.
Returns
a code with the result of the operation.

◆ Clean()

bool EA::ObjectMap::Clean ( )

Removes all the objects and aliases from the map.

Owned object will be deleted.

Returns
true if clean-up succeeded.

◆ CleanAliases()

bool EA::ObjectMap::CleanAliases ( )

Removes all the aliases from the map.

REmoves all the alias but not the aliased objects

Returns
true if clean-up succeeded.

◆ GetAliases()

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.

Parameters
nameThe name of the object.
Returns
The aliases of the object, or an empty vector if the given object has no alias.
a vector with the aliases of the objects in the map, or of all the objects if name is not given.

◆ GetNameOfAliasedObject()

const std::string & EA::ObjectMap::GetNameOfAliasedObject ( const std::string &  aliasName)

Gets the name of the object corresponding to an alias.

Parameters
aliasNameThe alias.
Returns
The name of the aliased object or a empty string if the alias does not exists or is currently not associated to any object.

◆ GetObject()

template<class DataType >
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.

Parameters
nameThe name of the desired object.
Returns
a pointer to the desired object (will be nullptr in case the object does not exists or there is a type mismatch).

◆ GetObjectClass()

std::string EA::ObjectMap::GetObjectClass ( const std::string &  objName)

Get the class name of an object in the store.

Parameters
objNameThe name of the desired object
Returns
the class name of the object, or an empty string if the given object is not found.

◆ GetObjects()

std::vector< std::string > EA::ObjectMap::GetObjects ( ) const

Returns the names of the objects in the map.

Returns
a vector with the names of the objects in the map.

◆ GetObjectWrapper()

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.

Parameters
objNameThe desired object.
Returns
a wrapper wrapping the desired object (wrapping nothing if the object has not been found).

◆ IsAlias()

bool EA::ObjectMap::IsAlias ( const std::string &  objName)

Checks if an object name is actually an alias.

Parameters
objNameThe name to be checked.
Returns
true if the given name is a currently defined alias.

◆ IsPresent()

bool EA::ObjectMap::IsPresent ( const std::string &  nameOrAlias) const

Checks if an object is present in the map.

Parameters
nameOrAliasThe name or the alias of the object.
Returns
true if the object is in the map, false otherwise

◆ RemoveObject()

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.

Parameters
nameThe name of the object to be deleted.
removeAliasedif name is an alias then the aliased object will be removed if this parameter is set to true.
Returns
true if the object has been removed from the map, false if the object is not present in the map

◆ SetAlias()

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:

  • The aliased object must be present in the data store
  • The alias cannot be equal to the name of an object that is already present in the store
  • It's not possible to define an alias for an alias
  • If the alias already exists and is currently assigned to another object then it will be reassigned to the new object
  • When an alias is reassigned the types of the old and new aliased objects must be identical.
Parameters
objNameThe aliased object.
objAliasThe alias to assign to the aliased object.
Returns
a code with the result of the operation.

Member Data Documentation

◆ _aliases

Aliases EA::ObjectMap::_aliases
private

◆ _map

Map EA::ObjectMap::_map
private

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