5 #ifndef BPP_SEQ_CONTAINER_MAPPEDNAMEDCONTAINER_H
6 #define BPP_SEQ_CONTAINER_MAPPEDNAMEDCONTAINER_H
28 std::map<std::string, std::shared_ptr<T>>
mObjects_;
61 const std::shared_ptr<T>
getObject(
const std::string& name)
const override
65 throw Exception(
"MappedNamedContainer::getObject : unknown name " + name);
70 std::shared_ptr<T>
getObject(
const std::string& name)
override
74 throw Exception(
"MappedNamedContainer::getObject : unknown name " + name);
79 const T&
object(
const std::string& name)
const override
83 throw Exception(
"MappedNamedContainer::object : unknown name " + name);
88 T&
object(
const std::string& name)
override
92 throw Exception(
"MappedNamedContainer::object : unknown name " + name);
97 bool hasObject(
const std::string& name)
const override
110 void addObject(std::shared_ptr<T> newObject,
const std::string& name,
bool checkName =
false)
113 throw Exception(
"MappedNamedContainer::addObject : Object's name already exists in container : " + name);
114 std::string nn = name;
126 throw Exception(
"MappedNamedContainer::deleteObject : Object's name does not exist in container : " + name);
140 throw Exception(
"MappedNamedContainer::removeObject : Object's name does not exist in container : " + name);
142 std::shared_ptr<T> obj =
mObjects_[name];
152 std::vector<std::string> vNames;
156 vNames.push_back(it.first);
168 void changeName(
const std::string& okey,
const std::string& nkey)
174 throw Exception(
"MappedNamedContainer::changeName : Object's name does not exist in container : " + okey);
177 throw Exception(
"MappedNamedContainer::changeName : Object's new name already exists in container : " + nkey);
179 std::shared_ptr<T> obj =
mObjects_[okey];
200 void addObject_(std::shared_ptr<T> newObject,
const std::string& name,
bool checkName =
false)
const
203 throw Exception(
"MappedNamedContainer::addObject : Object's name already exists in container : " + name);
205 std::string nn = name;
206 const_cast<std::map<std::string, std::shared_ptr<T>
>&>(
mObjects_)[nn] = newObject;
MappedNamedContainer class.
void addObject(std::shared_ptr< T > newObject, const std::string &name, bool checkName=false)
Set an object.
void changeName(const std::string &okey, const std::string &nkey)
change the key of an object.
virtual std::vector< std::string > getObjectNames() const override
std::shared_ptr< T > removeObject(const std::string &name) override
Remove and returns an object.
MappedNamedContainer(const MappedNamedContainer &msc)
T & object(const std::string &name) override
void clear() override
Delete all objects in the container.
const T & object(const std::string &name) const override
virtual void nullify()
Nullify all elements.
void deleteObject(const std::string &name) override
Remove an object.
virtual ~MappedNamedContainer()
std::shared_ptr< T > getObject(const std::string &name) override
bool hasObject(const std::string &name) const override
Check if a object with a given name is present in the container.
std::map< std::string, std::shared_ptr< T > > mObjects_
MappedNamedContainer * clone() const override
bool isAvailableName(std::string objectName) const
const std::shared_ptr< T > getObject(const std::string &name) const override
Retrieve an object from the container.
size_t getSize() const override
Get the number of objects in the container.
MappedNamedContainer & operator=(const MappedNamedContainer &msc)
void addObject_(std::shared_ptr< T > newObject, const std::string &name, bool checkName=false) const
MappedNamedContainer(const std::map< std::string, std::shared_ptr< T >> &ms)
A Container template for objects that are accessible through names.
This alphabet is used to deal NumericAlphabet.