44 typedef std::map< std::string, T >
IDMap;
52 for (
auto i :
myMap) {
66 bool add(
const std::string&
id, T item) {
67 const auto it =
myMap.lower_bound(
id);
68 if (it ==
myMap.end() || it->first !=
id) {
69 myMap.emplace_hint(it,
id, item);
80 bool remove(
const std::string&
id,
const bool del =
true) {
81 auto it =
myMap.find(
id);
82 if (it ==
myMap.end()) {
100 T
get(
const std::string&
id)
const {
101 auto it =
myMap.find(
id);
102 if (it ==
myMap.end()) {
111 for (
auto i :
myMap) {
119 return (
int)
myMap.size();
126 for (
auto i :
myMap) {
127 into.push_back(i.first);
132 bool changeID(
const std::string& oldId,
const std::string& newId) {
133 auto i =
myMap.find(oldId);
134 if (i ==
myMap.end()) {
140 myMap.insert(std::make_pair(newId, item));
146 typename IDMap::const_iterator
begin()
const {
147 return myMap.begin();
151 typename IDMap::const_iterator
end()
const {
A map of named object pointers.
void clear()
Removes all items from the container (deletes them, too)
NamedObjectCont()
Constructor.
IDMap myMap
The map from key to object.
std::map< std::string, T > IDMap
Definition of the key to pointer map type.
T get(const std::string &id) const
Retrieves an item.
void insertIDs(std::vector< std::string > &into) const
IDMap::const_iterator begin() const
Returns a reference to the begin iterator for the internal map.
IDMap::const_iterator end() const
Returns a reference to the end iterator for the internal map.
int size() const
Returns the number of stored items within the container.
bool changeID(const std::string &oldId, const std::string &newId)
change ID of a stored object
virtual ~NamedObjectCont()
Destructor.
bool remove(const std::string &id, const bool del=true)
Removes an item.
bool add(const std::string &id, T item)
Adds an item.