diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llnametable.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llnametable.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llnametable.h b/linden/indra/llcommon/llnametable.h new file mode 100644 index 0000000..80b9be4 --- /dev/null +++ b/linden/indra/llcommon/llnametable.h | |||
@@ -0,0 +1,106 @@ | |||
1 | /** | ||
2 | * @file llnametable.h | ||
3 | * @brief LLNameTable class is a table to associate pointers with string names | ||
4 | * | ||
5 | * Copyright (c) 2000-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLNAMETABLE_H | ||
29 | #define LL_LLNAMETABLE_H | ||
30 | |||
31 | #include <map> | ||
32 | |||
33 | #include "string_table.h" | ||
34 | |||
35 | template <class DATA> | ||
36 | class LLNameTable | ||
37 | { | ||
38 | public: | ||
39 | LLNameTable() | ||
40 | : mNameMap() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | ~LLNameTable() | ||
45 | { | ||
46 | } | ||
47 | |||
48 | void addEntry(const std::string& name, DATA data) | ||
49 | { | ||
50 | addEntry(name.c_str(), data); | ||
51 | } | ||
52 | |||
53 | void addEntry(const char *name, DATA data) | ||
54 | { | ||
55 | char *tablename = gStringTable.addString(name); | ||
56 | mNameMap[tablename] = data; | ||
57 | } | ||
58 | |||
59 | BOOL checkName(const std::string& name) const | ||
60 | { | ||
61 | return checkName(name.c_str()); | ||
62 | } | ||
63 | |||
64 | // "logically const" even though it modifies the global nametable | ||
65 | BOOL checkName(const char *name) const | ||
66 | { | ||
67 | char *tablename = gStringTable.addString(name); | ||
68 | return mNameMap.count(tablename) ? TRUE : FALSE; | ||
69 | } | ||
70 | |||
71 | DATA resolveName(const std::string& name) const | ||
72 | { | ||
73 | return resolveName(name.c_str()); | ||
74 | } | ||
75 | |||
76 | // "logically const" even though it modifies the global nametable | ||
77 | DATA resolveName(const char *name) const | ||
78 | { | ||
79 | char *tablename = gStringTable.addString(name); | ||
80 | const_iter_t iter = mNameMap.find(tablename); | ||
81 | if (iter != mNameMap.end()) | ||
82 | return iter->second; | ||
83 | else | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | // O(N)! (currently only used in one place... (newsim/llstate.cpp)) | ||
88 | const char *resolveData(const DATA &data) const | ||
89 | { | ||
90 | const_iter_t iter = mNameMap.begin(); | ||
91 | const_iter_t end = mNameMap.end(); | ||
92 | for (; iter != end; ++iter) | ||
93 | { | ||
94 | if (iter->second == data) | ||
95 | return iter->first; | ||
96 | } | ||
97 | return NULL; | ||
98 | } | ||
99 | |||
100 | typedef std::map<const char *, DATA> name_map_t; | ||
101 | typedef typename std::map<const char *,DATA>::iterator iter_t; | ||
102 | typedef typename std::map<const char *,DATA>::const_iterator const_iter_t; | ||
103 | name_map_t mNameMap; | ||
104 | }; | ||
105 | |||
106 | #endif | ||