00001 #ifndef SOME_STRING_MAP_HEADER
00002 #define SOME_STRING_MAP_HEADER
00003
00004 #include <vector>
00005 #include <map>
00006 #include <string>
00007 #include <algorithm>
00008
00009 namespace SOME
00010 {
00016 class StringMap
00017 {
00018 private:
00019 struct string_pair
00020 {
00021 std::string key;
00022 std::string value;
00023 bool operator<(const string_pair& l)
00024 {
00025 return key < l.key;
00026 }
00027 };
00028 typedef std::vector < string_pair > entry_vector;
00029 entry_vector entries;
00030
00031 public:
00032
00033 std::string& operator[](const std::string& findkey)
00034 {
00035 static string_pair searcher;
00036 searcher.key = findkey;
00037 entry_vector::iterator iter = std::lower_bound(entries.begin(), entries.end(), searcher);
00038 if (iter == entries.end() || iter->key != findkey)
00039 {
00040 iter = entries.insert(iter, searcher);
00041 }
00042 return iter->value;
00043 }
00044
00045 std::map < std::string, std::string > getStdMap()
00046 {
00047 std::map < std::string, std::string > ret_map;
00048 for (entry_vector::size_type i = 0; i < entries.size(); i++)
00049 ret_map[entries[i].key] = entries[i].value;
00050 return ret_map;
00051 }
00052 };
00053
00054 }
00055
00056 #endif //SOME_STRING_MAP_HEADER