llnametable.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLNAMETABLE_H
00033 #define LL_LLNAMETABLE_H
00034 
00035 #include <map>
00036 
00037 #include "string_table.h"
00038 
00039 template <class DATA>
00040 class LLNameTable
00041 {
00042 public:
00043         LLNameTable()
00044         :       mNameMap()
00045         {
00046         }
00047 
00048         ~LLNameTable() 
00049         { 
00050         }
00051 
00052         void addEntry(const std::string& name, DATA data)
00053         {
00054                 addEntry(name.c_str(), data);
00055         }
00056 
00057         void addEntry(const char *name, DATA data)
00058         {
00059                 char *tablename = gStringTable.addString(name);
00060                 mNameMap[tablename] = data;
00061         }
00062 
00063         BOOL checkName(const std::string& name) const
00064         {
00065                 return checkName(name.c_str());
00066         }
00067 
00068         // "logically const" even though it modifies the global nametable
00069         BOOL checkName(const char *name) const
00070         {
00071                 char *tablename = gStringTable.addString(name);
00072                 return mNameMap.count(tablename) ? TRUE : FALSE;
00073         }
00074 
00075         DATA resolveName(const std::string& name) const
00076         {
00077                 return resolveName(name.c_str());
00078         }
00079 
00080         // "logically const" even though it modifies the global nametable
00081         DATA resolveName(const char *name) const
00082         {
00083                 char *tablename = gStringTable.addString(name);
00084                 const_iter_t iter = mNameMap.find(tablename);
00085                 if (iter != mNameMap.end())
00086                         return iter->second;
00087                 else
00088                         return 0;
00089         }
00090 
00091         // O(N)! (currently only used in one place... (newsim/llstate.cpp))
00092         const char *resolveData(const DATA &data) const
00093         {
00094                 const_iter_t iter = mNameMap.begin();
00095                 const_iter_t end = mNameMap.end();
00096                 for (; iter != end; ++iter)
00097                 {
00098                         if (iter->second == data)
00099                                 return iter->first;
00100                 }
00101                 return NULL;
00102         }               
00103 
00104         typedef std::map<const char *, DATA> name_map_t;
00105         typedef typename std::map<const char *,DATA>::iterator iter_t;
00106         typedef typename std::map<const char *,DATA>::const_iterator const_iter_t;
00107         name_map_t              mNameMap;
00108 };
00109 
00110 #endif

Generated on Thu Jul 1 06:08:54 2010 for Second Life Viewer by  doxygen 1.4.7