1 #ifndef CSM_WOLRD_UNIVERSALID_H
2 #define CSM_WOLRD_UNIVERSALID_H
3 
4 #include <string>
5 #include <iosfwd>
6 #include <vector>
7 
8 #include <QMetaType>
9 
10 namespace CSMWorld
11 {
12     class UniversalId
13     {
14         public:
15 
16             enum Class
17             {
18                 Class_None = 0,
19                 Class_Record = 1,
20                 Class_RefRecord = 2, // referenceable record
21                 Class_SubRecord = 4,
22                 Class_RecordList = 8,
23                 Class_Collection = 16, // multiple types of records combined
24                 Class_Transient = 32, // not part of the world data or the project data
25                 Class_NonRecord = 64, // record like data that is not part of the world
26                 Class_Resource = 128, ///< \attention Resource IDs are unique only within the
27                                 /// respective collection
28                 Class_ResourceList = 256
29             };
30 
31             enum ArgumentType
32             {
33                 ArgumentType_None,
34                 ArgumentType_Id,
35                 ArgumentType_Index
36             };
37 
38             /// \note A record list type must always be immediately followed by the matching
39             /// record type, if this type is of class SubRecord or Record.
40             enum Type
41             {
42                 Type_None = 0,
43                 Type_Globals,
44                 Type_Global,
45                 Type_VerificationResults,
46                 Type_Gmsts,
47                 Type_Gmst,
48                 Type_Skills,
49                 Type_Skill,
50                 Type_Classes,
51                 Type_Class,
52                 Type_Factions,
53                 Type_Faction,
54                 Type_Races,
55                 Type_Race,
56                 Type_Sounds,
57                 Type_Sound,
58                 Type_Scripts,
59                 Type_Script,
60                 Type_Regions,
61                 Type_Region,
62                 Type_Birthsigns,
63                 Type_Birthsign,
64                 Type_Spells,
65                 Type_Spell,
66                 Type_Cells,
67                 Type_Cell,
68                 Type_Cell_Missing, //For cells that does not exist yet.
69                 Type_Referenceables,
70                 Type_Referenceable,
71                 Type_Activator,
72                 Type_Potion,
73                 Type_Apparatus,
74                 Type_Armor,
75                 Type_Book,
76                 Type_Clothing,
77                 Type_Container,
78                 Type_Creature,
79                 Type_Door,
80                 Type_Ingredient,
81                 Type_CreatureLevelledList,
82                 Type_ItemLevelledList,
83                 Type_Light,
84                 Type_Lockpick,
85                 Type_Miscellaneous,
86                 Type_Npc,
87                 Type_Probe,
88                 Type_Repair,
89                 Type_Static,
90                 Type_Weapon,
91                 Type_References,
92                 Type_Reference,
93                 Type_RegionMap,
94                 Type_Filters,
95                 Type_Filter,
96                 Type_Topics,
97                 Type_Topic,
98                 Type_Journals,
99                 Type_Journal,
100                 Type_TopicInfos,
101                 Type_TopicInfo,
102                 Type_JournalInfos,
103                 Type_JournalInfo,
104                 Type_Scene,
105                 Type_Preview,
106                 Type_LoadErrorLog,
107                 Type_Enchantments,
108                 Type_Enchantment,
109                 Type_BodyParts,
110                 Type_BodyPart,
111                 Type_Meshes,
112                 Type_Mesh,
113                 Type_Icons,
114                 Type_Icon,
115                 Type_Musics,
116                 Type_Music,
117                 Type_SoundsRes,
118                 Type_SoundRes,
119                 Type_Textures,
120                 Type_Texture,
121                 Type_Videos,
122                 Type_Video,
123                 Type_DebugProfiles,
124                 Type_DebugProfile,
125                 Type_SoundGens,
126                 Type_SoundGen,
127                 Type_MagicEffects,
128                 Type_MagicEffect,
129                 Type_Lands,
130                 Type_Land,
131                 Type_LandTextures,
132                 Type_LandTexture,
133                 Type_Pathgrids,
134                 Type_Pathgrid,
135                 Type_StartScripts,
136                 Type_StartScript,
137                 Type_Search,
138                 Type_MetaDatas,
139                 Type_MetaData,
140                 Type_RunLog
141             };
142 
143             enum { NumberOfTypes = Type_RunLog+1 };
144 
145         private:
146 
147             Class mClass;
148             ArgumentType mArgumentType;
149             Type mType;
150             std::string mId;
151             int mIndex;
152 
153         public:
154 
155             UniversalId (const std::string& universalId);
156 
157             UniversalId (Type type = Type_None);
158 
159             UniversalId (Type type, const std::string& id);
160             ///< Using a type for a non-ID-argument UniversalId will throw an exception.
161 
162             UniversalId (Type type, int index);
163             ///< Using a type for a non-index-argument UniversalId will throw an exception.
164 
165             Class getClass() const;
166 
167             ArgumentType getArgumentType() const;
168 
169             Type getType() const;
170 
171             const std::string& getId() const;
172             ///< Calling this function for a non-ID type will throw an exception.
173 
174             int getIndex() const;
175             ///< Calling this function for a non-index type will throw an exception.
176 
177             bool isEqual (const UniversalId& universalId) const;
178 
179             bool isLess (const UniversalId& universalId) const;
180 
181             std::string getTypeName() const;
182 
183             std::string toString() const;
184 
185             std::string getIcon() const;
186             ///< Will return an empty string, if no icon is available.
187 
188             static std::vector<Type> listReferenceableTypes();
189 
190             static std::vector<Type> listTypes (int classes);
191 
192             /// If \a type is a SubRecord, RefRecord or Record type return the type of the table
193             /// that contains records of type \a type.
194             /// Otherwise return Type_None.
195             static Type getParentType (Type type);
196     };
197 
198     bool operator== (const UniversalId& left, const UniversalId& right);
199     bool operator!= (const UniversalId& left, const UniversalId& right);
200 
201     bool operator< (const UniversalId& left, const UniversalId& right);
202 
203     std::ostream& operator< (std::ostream& stream, const UniversalId& universalId);
204 }
205 
206 Q_DECLARE_METATYPE (CSMWorld::UniversalId)
207 
208 #endif
209