Debian Codegraph @

plugins/dm.objectives/SpecifierType.h

raw
1 #ifndef SPECIFIERTYPE_H_
2 #define SPECIFIERTYPE_H_
3
4 #include <map>
5 #include <string>
6 #include <set>
7
8 namespace objectives
9 {
10
11 class SpecifierType;
12
13 /**
14 * Set of SpecifierTypes type.
15 */
16 typedef std::set<SpecifierType> SpecifierTypeSet;
17
18 /**
19 * Type-safe enumeration of valid specifier types.
20 *
21 * Each Component can have up to 2 <b>specifiers</b>, which provide
22 * information about the target of the component depending on the component
23 * type. For example, a KILL component must specify an AI or group of AI
24 * to be killed.
25 *
26 * Each specifier consists of two parts, a specifier <b>type</b> and a
27 * specifier <b>value</b>. This enumeration provides the available specifier
28 * types, which are used by the game to determine the meaning of the
29 * associated specifier value.
30 *
31 * This class uses the typesafe enum idiom. A number of static const instances
32 * are defined, each of which can provide its ID and its name. Additionally the
33 * instances are registered in a map so that SpecifierType objects can be obtained
34 * for a given string name (as provided by a spawnarg).
35 */
36 class SpecifierType
37 {
38 // Static enum count
39 static int enumCount;
40
41 // Static map of named SpecifierType instances
42 typedef std::map<std::string, SpecifierType> SpecifierTypeMap;
43 static SpecifierTypeMap& getMap();
44
45 // The integer number of this SpecifierType
46 int _id;
47
48 // The string name of this SpecifierType (used as a spawnarg)
49 std::string _name;
50
51 // User-friendly display name of this SpecifierType
52 std::string _displayName;
53
54 private:
55
56 // Construct a named SpecifierType type
57 SpecifierType(const std::string& name, const std::string& displayName);
58
59 public:
60
61 /**
62 * Retrieve the SpecifierType instance corresponding to the given name.
63 *
64 * @param name
65 * The name of the SpecifierType instance to look up (e.g. "KILL").
66 *
67 * @return
68 * The named SpecifierType if found.
69 *
70 * @exception ObjectivesException
71 * Thrown if the named SpecifierType type does not exist.
72 */
73 static const SpecifierType& getSpecifierType(const std::string& name);
74
75 /**
76 * Retrieve the SpecifierType instance corresponding to the given ID.
77 *
78 * @param id
79 * The ID of the SpecifierType instance to look up.
80 *
81 * @return
82 * The named SpecifierType if found.
83 *
84 * @exception ObjectivesException
85 * Thrown if the named SpecifierType type does not exist.
86 */
87 static const SpecifierType& getSpecifierType(int id);
88
89 /**
90 * Get the string name of this SpecifierType type.
91 */
92 std::string getName() const {
93 return _name;
94 }
95
96 /**
97 * Get the user-friendly display name of this SpecifierType type.
98 */
99 std::string getDisplayName() const {
100 return _displayName;
101 }
102
103 /**
104 * Get the numeric ID of this SpecifierType type.
105 */
106 int getId() const {
107 return _id;
108 }
109
110 /**
111 * @name Static SpecifierType instances.
112 */
113
114 //@{
115
116 /** No specifier (used in-game to represent "any entity"). */
117 static const SpecifierType& SPEC_NONE();
118
119 /** Specify name of an entity. */
120 static const SpecifierType& SPEC_NAME();
121
122 /** Overall specifier for AI, inventory etc. */
123 static const SpecifierType& SPEC_OVERALL();
124
125 /** Type-specific group specifier. */
126 static const SpecifierType& SPEC_GROUP();
127
128 /** Specify a DEF-based class name. */
129 static const SpecifierType& SPEC_CLASSNAME();
130
131 /** Specify an SDK-level spawnclass. */
132 static const SpecifierType& SPEC_SPAWNCLASS();
133
134 /** Specify an AI type, such as "human". */
135 static const SpecifierType& SPEC_AI_TYPE();
136
137 /** Specify a numeric AI team ID. */
138 static const SpecifierType& SPEC_AI_TEAM();
139
140 /** Specify the combat/non-combat status of an AI. */
141 static const SpecifierType& SPEC_AI_INNOCENCE();
142
143 //@}
144
145 /**
146 * @name Static specifier sets
147 */
148
149 //@{
150
151 /** Set of all specifiers. */
152 static const SpecifierTypeSet& SET_ALL();
153
154 // The specifier set for the COMP_ITEM components
155 static const SpecifierTypeSet& SET_ITEM();
156
157 // The specifier set for the COMP_READABLE_* components
158 static const SpecifierTypeSet& SET_READABLE();
159
160 // The specifier set for COMP_LOCATION-style components
161 static const SpecifierTypeSet& SET_LOCATION();
162
163 /** Set for standard AI specifiers (all except SPEC_GROUP). */
164 static const SpecifierTypeSet& SET_STANDARD_AI();
165
166 //@}
167
168 };
169
170 /**
171 * Operator less function for SpecifierTypes.
172 *
173 * This function returns true if the first SpecifierType's ID is less than the
174 * second. It is required so that SpecifierType objects can be used as keys in a
175 * std::map.
176 */
177 inline bool operator< (const SpecifierType& first, const SpecifierType& second)
178 {
179 return first.getId() < second.getId();
180 }
181
182 /**
183 * Operator equals function for SpecifierTypes.
184 *
185 * Returns true if the two SpecifierTypes have the same internal name, false
186 * otherwise.
187 */
188 inline bool operator== (const SpecifierType& first, const SpecifierType& second)
189 {
190 return first.getName() == second.getName();
191 }
192 inline bool operator!= (const SpecifierType& first, const SpecifierType& second)
193 {
194 return !(first == second);
195 }
196
197 }
198
199 #endif /*SPECIFIERTYPE_H_*/