Gorgon Game Engine
GID.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <string>
6 #include <stdint.h>
7 
8 namespace Gorgon {
9  namespace Resource {
14  static const unsigned long CurrentVersion = 0x00010000;
15 
16 
17  //Gorgon IDs for known resource types
18  namespace GID {
19 
23  class Type {
24  public:
26  constexpr Type() : value() { }
27 
29  explicit constexpr Type(uint32_t value) : value(value) { }
30 
32  constexpr uint32_t AsInteger() const {
33  return value;
34  }
35 
37  const char *AsData() const {
38  return (const char*)&value;
39  }
40 
42  constexpr bool IsEmpty() const { return value==0; }
43 
45  constexpr bool operator == (const Type &type) const { return type.value==value; }
46 
48  constexpr bool operator != (const Type &type) const { return type.value!=value; }
49 
51  constexpr bool operator < (const Type &type) const { return type.value<value; }
52 
54  constexpr Byte Module() const {
55  return value>>24;
56  }
57 
59  constexpr Byte Object() const {
60  return (value>>16) & 0xff;
61  }
62 
64  constexpr Byte Property() const {
65  return value & 0xffff;
66  }
67 
70  std::string Name() const;
71 
72  private:
73  uint32_t value;
74  };
75 
79 
81  constexpr Type None {0x00000000};
82 
84  constexpr Type File {0x000000FF};
85 
87  constexpr Type GameFile {0x030100FF};
88 
91  constexpr Type Folder {0x01010000};
93  constexpr Type Folder_Names {0x01010101};
95  constexpr Type Folder_Name {0x01010102};
97  constexpr Type Folder_Props {0x01010103};
98 
101  constexpr Type LinkNode {0x01020000};
103  constexpr Type LinkNode_Target {0x01020010};
105  constexpr Type Null {0x01030000};
107 
111 
113  constexpr Type Guid {0x00000010};
115  constexpr Type SGuid {0x00000011};
117  constexpr Type Name {0x00000012};
118 
120  constexpr Type LZMA {0xF0030100};
122  constexpr Type FLAC {0xF0040100};
124  constexpr Type JPEG {0xF0030300};
126  constexpr Type PNG {0xF0030400};
128 
132 
134  constexpr Type Text {0x02010000};
135 
137  constexpr Type HTML {0x02010101};
138 
140  constexpr Type URL {0x02010102};
141 
143  constexpr Type FileList {0x02010103};
144 
146  constexpr Type URIList {0x02010104};
147 
149  constexpr Type Image {0x02020000};
151  constexpr Type Image_Props {0x02020101};
153  constexpr Type Image_Cmp_Props {0x02020102};
155  constexpr Type Image_Data {0x02020501};
157  constexpr Type Image_Cmp_Data {0x02020601};
159  constexpr Type Image_Palette {0x02020502};
161  constexpr Type Image_NULL {0x0202A100};
162 
164  constexpr Type Data {0x02030000};
165 
166  constexpr Type Data_Names {0x02030101};
167  constexpr Type Data_Name {0x02030102};
168 
169  constexpr Type Data_Text {0x02030C01};
170  constexpr Type Data_Int {0x02030C02};
171  constexpr Type Data_Float {0x02030C03};
172  constexpr Type Data_Point {0x02030C04};
173  constexpr Type Data_Pointf {0x02030C09};
174  constexpr Type Data_Rectangle {0x02030C05};
175  constexpr Type Data_Link {0x02030C07};
176  constexpr Type Data_Font {0x03300C01};
177  constexpr Type Data_Color {0x02030D02};
178  constexpr Type Data_Size {0x02030D03};
179  constexpr Type Data_Bounds {0x02030D04};
180  constexpr Type Data_Margin {0x02030D05};
181  constexpr Type Data_Object {0x02030D06};
182 
184 
187  constexpr Type Animation {0x03100000};
188  constexpr Type Animation_Image {0x03110000};
189  constexpr Type Animation_Durations {0x03100101};
190  constexpr Type Animation_Names {0x03100102};
191  constexpr Type Animation_Name {0x03100103};
192 
193  constexpr Type LegacyPointer {0x03D10000};
194  constexpr Type LegacyPointer_Props {0x03D10101};
195 
196  constexpr Type Pointer {0x03D20000};
197  constexpr Type Pointer_Props {0x03D20101};
198 
199  constexpr Type Font {0x03200000};
200  constexpr Type Font_Charmap {0x03200101};
201  constexpr Type Font_Names {0x03200102};
202  constexpr Type Font_Name {0x03200103};
203  constexpr Type Font_Image {0x03210000};
204  constexpr Type Font_Props {0x03200804};
205  constexpr Type Font_Charmap_II {0x03200805};
206  constexpr Type Font_BitmapProps {0x03200806};
207  constexpr Type Font_BitmapKerning {0x03200807};
208  constexpr Type Font_FreeTypeProps {0x03200104};
209  constexpr Type Font_FreeTypeData {0x03200105};
210 
211  constexpr Type FontTheme {0x03300000};
212  constexpr Type FontTheme_Font {0x03301001};
213  constexpr Type FontTheme_Shadow {0x03301002};
214  constexpr Type FontTheme_Props {0x03300804};
216 
219  constexpr Type Sound {0x04010000};
220  constexpr Type Sound_Props {0x04010101};
221  constexpr Type Sound_Wave {0x04010801};
222  constexpr Type Sound_Cmp_Wave {0x04010802};
223  constexpr Type Sound_Cmp_Props {0x04010803};
224  constexpr Type Sound_Fmt {0x04010104};
225  constexpr Type Sound_Channels {0x04010105};
226 
227  constexpr Type Blob {0x04020000};
228  constexpr Type Blob_Props {0x04020101};
229  constexpr Type Blob_Data {0x04020801};
230  constexpr Type Blob_Cmp_Data {0x04020802};
232 
234  constexpr Type Line {0x05110000};
235  constexpr Type Line_Props {0x05110101};
236  constexpr Type Line_Props_II {0x05110102};
237 
238  constexpr Type Rectangle {0x05120000};
239  constexpr Type Rectangle_Props {0x05120101};
240  constexpr Type Rectangle_Props_II {0x05120102};
241 
242  constexpr Type MaskedObject {0x05170000};
243 
244  constexpr Type TintedObject {0x05180000};
245  constexpr Type TintedObject_Props {0x05180101};
246 
247  constexpr Type ScalableObject {0x05190000};
248  constexpr Type ScalableObject_Props {0x05190101};
249 
250  constexpr Type StackedObject {0x051A0000};
251  constexpr Type StackedObject_Props {0x051A0101};
253  }
254  }
255 
256  namespace String {
258  inline std::string From(const Resource::GID::Type &value) {
259  static char hextable[]={"0123456789ABCDEF"};
260 
261  std::string ret;
262  ret.resize(8);
263 
264  uint32_t v=value.AsInteger();
265  for(int i=1;i<=8;i++) {
266  ret[8-i]=hextable[v%16];
267  v=v>>4;
268  }
269 
270  return ret;
271  }
272  }
273 
274  namespace Resource {
275  namespace GID {
277  inline std::ostream &operator <<(std::ostream &out, const Resource::GID::Type &value) {
278  out<<String::From(value);
279 
280  return out;
281  }
282 
283  inline std::string Type::Name() const {
284  //use the following regex to translate list of gids to the following code:
285  // constexpr Type ([^\s]+)\s*\{(0x[0-9A-Fa-f]+)\};
286  // case \2: return "\1";
287  switch(value) {
288  case 0x00000000: return "None";
289  case 0x000000FF: return "File";
290  case 0x030100FF: return "GameFile";
291  case 0x01010000: return "Folder";
292  case 0x01010101: return "Folder Names";
293  case 0x01010102: return "Folder Name";
294  case 0x01010103: return "Folder Props";
295  case 0x01020000: return "LinkNode";
296  case 0x01020010: return "LinkNode Target";
297  case 0x01030000: return "Null";
298  case 0x00000010: return "Guid";
299  case 0x00000011: return "SGuid";
300  case 0x00000012: return "Name";
301  case 0xF0030100: return "LZMA";
302  case 0xF0040100: return "FLAC";
303  case 0xF0030300: return "JPEG";
304  case 0xF0030400: return "PNG";
305  case 0x02010000: return "Text";
306  case 0x02010101: return "HTML";
307  case 0x02010102: return "URL";
308  case 0x02010103: return "File list";
309  case 0x02010104: return "URI list";
310  case 0x02020000: return "Image";
311  case 0x02020101: return "Image Props";
312  case 0x02020102: return "Image Cmp Props";
313  case 0x02020501: return "Image Data";
314  case 0x02020601: return "Image Cmp Data";
315  case 0x02020502: return "Image Palette";
316  case 0x0202A100: return "Image NULL";
317  case 0x02030000: return "Data";
318  case 0x02030101: return "Data Names";
319  case 0x02030102: return "Data Name";
320  case 0x02030C01: return "Data Text";
321  case 0x02030C02: return "Data Int";
322  case 0x02030C03: return "Data Float";
323  case 0x02030C04: return "Data Point";
324  case 0x02030C09: return "Data Pointf";
325  case 0x02030C05: return "Data Rectangle";
326  case 0x02030C07: return "Data Link";
327  case 0x03300C01: return "Data Font";
328  case 0x02030D02: return "Data Color";
329  case 0x02030D03: return "Data Size";
330  case 0x02030D04: return "Data Bounds";
331  case 0x02030D05: return "Data Margin";
332  case 0x02030D06: return "Data Object";
333  case 0x03100000: return "Animation";
334  case 0x03110000: return "Animation Image";
335  case 0x03100101: return "Animation Durations";
336  case 0x03100102: return "Animation Names";
337  case 0x03100103: return "Animation Name";
338  case 0x03D10000: return "LegacyPointer";
339  case 0x03D10101: return "LegacyPointer Props";
340  case 0x03D20000: return "Pointer";
341  case 0x03D20101: return "Pointer Props";
342  case 0x03200000: return "Font";
343  case 0x03200101: return "Font Charmap";
344  case 0x03200102: return "Font Names";
345  case 0x03200103: return "Font Name";
346  case 0x03210000: return "Font Image";
347  case 0x03200804: return "Font Props";
348  case 0x03200805: return "Font Charmap II";
349  case 0x03200806: return "Font BitmapProps";
350  case 0x03300000: return "FontTheme";
351  case 0x03301001: return "FontTheme Font";
352  case 0x03301002: return "FontTheme Shadow";
353  case 0x03300804: return "FontTheme Props";
354  case 0x04010000: return "Sound";
355  case 0x04010101: return "Sound Props";
356  case 0x04010801: return "Sound Wave";
357  case 0x04010802: return "Sound Cmp Wave";
358  case 0x04010803: return "Sound Cmp Props";
359  case 0x04010104: return "Sound Fmt";
360  case 0x04010105: return "Sound Channels";
361  case 0x04020000: return "Blob";
362  case 0x04020101: return "Blob Props";
363  case 0x04020801: return "Blob Data";
364  case 0x04020802: return "Blob Cmp Data";
365  case 0x05110000: return "Line";
366  case 0x05110101: return "Line Props";
367  case 0x05110102: return "Line Props II";
368  case 0x05120000: return "Rectangle";
369  case 0x05120101: return "Rectangle Props";
370  case 0x05120102: return "Rectangle Props II";
371  case 0x05170000: return "MaskedObject";
372  case 0x05180000: return "TintedObject";
373  case 0x05180101: return "TintedObject Props";
374  case 0x05190000: return "ScalableObject";
375  case 0x05190101: return "ScalableObject Props";
376  case 0x051A0000: return "StackedObject";
377  case 0x051A0101: return "StackedObject Props";
378  default: return String::From(*this);
379  }
380  }
381  }
382  }
383 }
Gorgon::Resource::GID::Font_Charmap_II
constexpr Type Font_Charmap_II
Definition: GID.h:205
Gorgon::Resource::GID::operator<<
std::ostream & operator<<(std::ostream &out, const Resource::GID::Type &value)
Inserts a GID to a stream.
Definition: GID.h:277
Gorgon::Resource::GID::Font_BitmapProps
constexpr Type Font_BitmapProps
Definition: GID.h:206
Gorgon::Resource::GID::Font_Charmap
constexpr Type Font_Charmap
Definition: GID.h:200
Gorgon::Resource::GID::PNG
constexpr Type PNG
PNG compression.
Definition: GID.h:126
Gorgon::String::From
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
Gorgon::Resource::GID::Type::AsInteger
constexpr uint32_t AsInteger() const
Returns the value of the GID as an integer.
Definition: GID.h:32
Gorgon::Resource::GID::ScalableObject_Props
constexpr Type ScalableObject_Props
Definition: GID.h:248
Gorgon::Resource::GID::Image_Props
constexpr Type Image_Props
Image properties.
Definition: GID.h:151
Gorgon::Resource::GID::Image_Data
constexpr Type Image_Data
Uncompressed image data.
Definition: GID.h:155
Gorgon::Resource::GID::Data_Names
constexpr Type Data_Names
Definition: GID.h:166
Gorgon::Resource::GID::LinkNode
constexpr Type LinkNode
Link node resource Gorgon::Resource::LinkNode.
Definition: GID.h:101
Gorgon::Resource::GID::Guid
constexpr Type Guid
Definition: GID.h:113
Gorgon::Resource::GID::Data_Rectangle
constexpr Type Data_Rectangle
Definition: GID.h:174
Gorgon::Resource::GID::Sound_Props
constexpr Type Sound_Props
Definition: GID.h:220
Gorgon::Resource::GID::Sound_Cmp_Props
constexpr Type Sound_Cmp_Props
Definition: GID.h:223
Gorgon::Resource::GID::Data_Color
constexpr Type Data_Color
Definition: GID.h:177
Gorgon::Resource::Line
This is a line resource, it stores a Graphics::LineProvider.
Definition: Line.h:16
Gorgon::Resource::GID::Text
constexpr Type Text
Stores text data, no longer a resource.
Definition: GID.h:134
Gorgon::Resource::GID::Type::AsData
const char * AsData() const
Returns the value of the GID as a character array.
Definition: GID.h:37
Gorgon::Resource::GID::LegacyPointer_Props
constexpr Type LegacyPointer_Props
Definition: GID.h:194
Gorgon::Resource::GID::Data_Pointf
constexpr Type Data_Pointf
Definition: GID.h:173
Gorgon::Resource::GID::Data_Margin
constexpr Type Data_Margin
Definition: GID.h:180
Gorgon::Resource::GID::Data_Point
constexpr Type Data_Point
Definition: GID.h:172
Gorgon::Resource::GID::URIList
constexpr Type URIList
List of URIs, not a resource.
Definition: GID.h:146
Gorgon::Resource::GID::Folder_Props
constexpr Type Folder_Props
Properties of a folder.
Definition: GID.h:97
Gorgon::Resource::GID::Font_FreeTypeProps
constexpr Type Font_FreeTypeProps
Definition: GID.h:208
Gorgon::Resource::GID::Animation_Name
constexpr Type Animation_Name
Definition: GID.h:191
Gorgon::Resource::GID::URL
constexpr Type URL
URL data, not a resource.
Definition: GID.h:140
Gorgon::Resource::GID::FontTheme_Font
constexpr Type FontTheme_Font
Definition: GID.h:212
Gorgon::Resource::GID::Image_Cmp_Data
constexpr Type Image_Cmp_Data
Compressed image data.
Definition: GID.h:157
Gorgon::Resource::GID::LinkNode_Target
constexpr Type LinkNode_Target
Stores the target of the link.
Definition: GID.h:103
Gorgon::Resource::GID::Type::Type
constexpr Type()
Default constructor creates an empty type.
Definition: GID.h:26
Gorgon::Resource::GID::Image_Cmp_Props
constexpr Type Image_Cmp_Props
Image compression properties.
Definition: GID.h:153
Gorgon::Resource::GID::Sound_Wave
constexpr Type Sound_Wave
Definition: GID.h:221
Gorgon::Resource::Blob
This is sound resource.
Definition: Blob.h:15
Gorgon::Resource::TintedObject
This is a tinted object resource.
Definition: TintedObject.h:16
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Resource::GID::Font_BitmapKerning
constexpr Type Font_BitmapKerning
Definition: GID.h:207
Gorgon::Resource::GID::TintedObject_Props
constexpr Type TintedObject_Props
Definition: GID.h:245
Gorgon::Resource::GID::StackedObject_Props
constexpr Type StackedObject_Props
Definition: GID.h:251
Gorgon::Resource::GID::Type::operator==
constexpr bool operator==(const Type &type) const
Compares two GIDs.
Definition: GID.h:45
Gorgon::Resource::StackedObject
This is a stacked object resource.
Definition: StackedObject.h:15
Gorgon::Resource::GID::Rectangle_Props_II
constexpr Type Rectangle_Props_II
Definition: GID.h:240
Gorgon::Resource::GID::FLAC
constexpr Type FLAC
LZMA compression.
Definition: GID.h:122
Gorgon::Resource::GID::Image_Palette
constexpr Type Image_Palette
Image palette, not active yet.
Definition: GID.h:159
Gorgon::Resource::GID::Font_Names
constexpr Type Font_Names
Definition: GID.h:201
Gorgon::Resource::GID::Data_Text
constexpr Type Data_Text
Definition: GID.h:169
Gorgon::Resource::GID::Folder_Name
constexpr Type Folder_Name
Definition: GID.h:95
Gorgon::Resource::GID::Line_Props_II
constexpr Type Line_Props_II
Definition: GID.h:236
Gorgon::Resource::File
This class represents a logical resource file.
Definition: File.h:53
Gorgon::Resource::GID::Name
constexpr Type Name
Name of a resource, names are not required to be unique.
Definition: GID.h:117
Gorgon::Resource::Pointer
Pointer resource that can be used to create a new pointer to be displayed.
Definition: Pointer.h:25
Gorgon::Resource::GID::None
constexpr Type None
Empty, different from Null resource.
Definition: GID.h:81
Gorgon::Resource::GID::FileList
constexpr Type FileList
List of local files, not a resource.
Definition: GID.h:143
Gorgon::Resource::GID::FontTheme_Shadow
constexpr Type FontTheme_Shadow
Definition: GID.h:213
Gorgon::Resource::GID::Blob_Cmp_Data
constexpr Type Blob_Cmp_Data
Definition: GID.h:230
Gorgon::Resource::GID::Line_Props
constexpr Type Line_Props
Definition: GID.h:235
Gorgon::Resource::GID::Font_Name
constexpr Type Font_Name
Definition: GID.h:202
Gorgon::Resource::GID::Animation_Image
constexpr Type Animation_Image
Definition: GID.h:188
Gorgon::Resource::GID::FontTheme
constexpr Type FontTheme
Definition: GID.h:211
Gorgon::Resource::GID::Type::Module
constexpr Byte Module() const
Returns the module identifier.
Definition: GID.h:54
Gorgon::Resource::GID::Type::IsEmpty
constexpr bool IsEmpty() const
Checks if this type information is empty.
Definition: GID.h:42
Gorgon::Resource::GID::Blob_Data
constexpr Type Blob_Data
Definition: GID.h:229
Gorgon::Resource::GID::Type::operator!=
constexpr bool operator!=(const Type &type) const
Compares two GIDs.
Definition: GID.h:48
Gorgon::Resource::GID::Sound_Fmt
constexpr Type Sound_Fmt
Definition: GID.h:224
Gorgon::Resource::ScalableObject
This is a tinted object resource.
Definition: ScalableObject.h:16
Gorgon::Resource::GID::Data_Int
constexpr Type Data_Int
Definition: GID.h:170
Gorgon::Resource::Rectangle
Definition: Rectangle.h:11
Gorgon::Resource::GID::Type::Name
std::string Name() const
Return the name of a known GID.
Definition: GID.h:283
Gorgon::Resource::GID::Animation_Durations
constexpr Type Animation_Durations
Definition: GID.h:189
Gorgon::Resource::GID::Sound_Cmp_Wave
constexpr Type Sound_Cmp_Wave
Definition: GID.h:222
Gorgon::Byte
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
Gorgon::Resource::GID::Blob_Props
constexpr Type Blob_Props
Definition: GID.h:228
Gorgon::Resource::GID::Data_Bounds
constexpr Type Data_Bounds
Definition: GID.h:179
Gorgon::Resource::GID::Sound_Channels
constexpr Type Sound_Channels
Definition: GID.h:225
Gorgon::Resource::GID::Image_NULL
constexpr Type Image_NULL
Denotes the image is null.
Definition: GID.h:161
Gorgon::Resource::GID::Font_Image
constexpr Type Font_Image
Definition: GID.h:203
Gorgon::Resource::GID::Font_FreeTypeData
constexpr Type Font_FreeTypeData
Definition: GID.h:209
Gorgon::Resource::GID::FontTheme_Props
constexpr Type FontTheme_Props
Definition: GID.h:214
Gorgon::Resource::GID::Rectangle_Props
constexpr Type Rectangle_Props
Definition: GID.h:239
Gorgon::Resource::GID::Type::Property
constexpr Byte Property() const
Returns the property part of the GID.
Definition: GID.h:64
Gorgon::Resource::GID::GameFile
constexpr Type GameFile
Denotes this file is a game file.
Definition: GID.h:87
Gorgon::Resource::GID::JPEG
constexpr Type JPEG
JPEG compression.
Definition: GID.h:124
Gorgon::Resource::Null
This is a null resource, it can be used in places where a resource is required but it is not wanted.
Definition: Null.h:17
Gorgon::Resource::GID::Data_Link
constexpr Type Data_Link
Definition: GID.h:175
Gorgon::Resource::GID::HTML
constexpr Type HTML
HTML data, not a resource.
Definition: GID.h:137
Gorgon::Resource::GID::LZMA
constexpr Type LZMA
LZMA compression.
Definition: GID.h:120
Gorgon::Resource::MaskedObject
This is a masked object resource.
Definition: MaskedObject.h:15
Gorgon::Resource::Data
Definition: Data.h:14
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::SGuid
This class represents a short globally unique identifier.
Definition: SGuid.h:22
Gorgon::Resource::Font
Font resource.
Definition: Font.h:16
Gorgon::Resource::GID::Data_Name
constexpr Type Data_Name
Definition: GID.h:167
Gorgon::Resource::GID::LegacyPointer
constexpr Type LegacyPointer
Definition: GID.h:193
Gorgon::Resource::GID::Font_Props
constexpr Type Font_Props
Definition: GID.h:204
Gorgon::Resource::GID::Data_Size
constexpr Type Data_Size
Definition: GID.h:178
Gorgon::Resource::GID::Pointer_Props
constexpr Type Pointer_Props
Definition: GID.h:197
Gorgon::Resource::GID::Type::Object
constexpr Byte Object() const
Returns the object identifier.
Definition: GID.h:59
Gorgon::Resource::GID::Animation_Names
constexpr Type Animation_Names
Definition: GID.h:190
Gorgon::Resource::GID::Data_Float
constexpr Type Data_Float
Definition: GID.h:171
Gorgon::Resource::Folder
This is basic folder resource, it contains other resources.
Definition: Folder.h:14
Gorgon::Resource::GID::Type::operator<
constexpr bool operator<(const Type &type) const
For std::less.
Definition: GID.h:51
Gorgon::Resource::Image
This resource contains images.
Definition: Image.h:23
Gorgon::Resource::GID::Data_Object
constexpr Type Data_Object
Definition: GID.h:181
Gorgon::Resource::Animation
This class represents an animation resource.
Definition: Animation.h:19
Gorgon::Resource::GID::Type::Type
constexpr Type(uint32_t value)
Constructor to create a new GID from the given value.
Definition: GID.h:29
Gorgon::Resource::GID::Folder_Names
constexpr Type Folder_Names
Definition: GID.h:93
Gorgon::Resource::Sound
This is sound resource.
Definition: Sound.h:17
Gorgon::Resource::GID::Data_Font
constexpr Type Data_Font
Definition: GID.h:176