1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_REGISTRY_H
21
#define DRIZZLED_REGISTRY_H
32
std::map<std::string, T> item_map;
35
bool addItemEntry(std::string name, T item)
37
if (item_map.count(name) == 0)
45
bool addItem(std::string name, T item)
48
/* First, add with no transform */
49
if (addItemEntry(name, item))
52
/* Transform to lower, then add */
53
transform(name.begin(), name.end(),
54
name.begin(), ::tolower);
55
/* Ignore failures here - the original name could be all lower */
56
addItemEntry(name, item);
61
void removeItem(std::string name)
64
/* First, remove with no transform */
67
/* Transform to lower, then remove */
68
transform(name.begin(), name.end(),
69
name.begin(), ::tolower);
75
typedef typename std::set<T>::const_iterator const_iterator;
76
typedef typename std::set<T>::iterator iterator;
78
T find(const char *name, size_t length)
80
std::string find_str(name, length);
81
return find(find_str);
84
T find(std::string name)
87
typename std::map<std::string, T>::iterator find_iter;
88
find_iter= item_map.find(name);
89
if (find_iter != item_map.end())
90
return (*find_iter).second;
92
transform(name.begin(), name.end(),
93
name.begin(), ::tolower);
94
find_iter= item_map.find(name);
95
if (find_iter != item_map.end())
96
return (*find_iter).second;
108
if (item_set.insert(item).second == false)
111
if (addItem(item->getName(), item))
114
const std::vector<std::string>& aliases= item->getAliases();
115
if (!(failed) && (aliases.size() > 0))
117
typename std::vector<std::string>::const_iterator iter= aliases.begin();
118
while (iter != aliases.end())
120
if(addItem(*iter, item))
132
* Remove an item from the registry. We don't care about failure
136
removeItem(item->getName());
138
const std::vector<std::string>& aliases= item->getAliases();
139
if (aliases.size() > 0)
141
std::vector<std::string>::const_iterator iter= aliases.begin();
142
while (iter != aliases.end())
150
const_iterator begin()
152
return item_set.begin();
157
return item_set.end();
162
} /* namespace drizzled */
164
#endif /* DRIZZLED_REGISTRY_H */