 |
Gorgon Game Engine
|
Go to the documentation of this file.
33 static const struct CreateNewTag { }
CreateNew;
40 explicit SGuid(
const CreateNewTag&) {
52 memcpy_s(
Bytes, 8, data, 8);
54 std::memcpy(
Bytes, data, 8);
62 SGuid(
unsigned long long data) {
68 SGuid(
unsigned serial,
unsigned random,
unsigned time) {
69 Set(serial, random, time);
73 explicit SGuid(std::istream &in) {
93 void Set(
unsigned serial,
unsigned random,
unsigned time) {
105 memcpy(
Bytes+0, &time , 2);
106 memcpy(
Bytes+2, &random, 3);
107 memcpy(
Bytes+5, &serial, 3);
114 time_t t=time(
nullptr);
118 Set(serial, random, (
unsigned)t);
122 operator std::string()
const {
123 static char hexlist[]=
"0123456789abcdef";
128 for(
int i=7;i>=0;i--) {
129 str[j++]=hexlist[
Bytes[i]/16];
130 str[j++]=hexlist[
Bytes[i]%16];
148 file.read((
char*)
Bytes, 8);
149 file.read((
char*)
Bytes, 8);
153 void Save(std::ostream &file)
const {
154 file.write((
char*)
Bytes, 8);
163 operator bool()
const {
172 void checknewserial()
const {
173 unsigned s=((
Integer>>40) & 0xffffff);
178 static unsigned serial;
183 stream<<(std::string)guid;
192 while(in.peek()==
' ' || in.peek()==
'\t' || in.peek()==
'\n')
198 for(
int i=15; i>=0; i--) {
203 if(c>=
'0' && c<=
'9') {
204 guid.
Bytes[i/2]+=(c-
'0')<<((i%2) ? 4 : 0);
206 else if(c>=
'a' && c<=
'f') {
207 guid.
Bytes[i/2]+=(c-
'a'+10)<<((i%2) ? 4 : 0);
209 else if(c==
'-' || c==
' ' || c==
'\t') i++;
211 if(!in.good())
break;
static const struct Gorgon::SGuid::CreateNewTag CreateNew
Definition: SGuid.cpp:9
static const SGuid Empty
Value for empty GUID.
Definition: SGuid.h:168
bool operator<(const SGuid &g) const
Compares two GUIDs.
Definition: SGuid.h:88
constexpr Type Data
Data resource.
Definition: GID.h:164
SGuid(const Byte data[8])
Creates a new GUID from the given data.
Definition: SGuid.h:46
void New()
Generates a new GUID and assign that GUID to this one.
Definition: SGuid.h:113
bool IsEmpty() const
Returns whether this GUID is empty.
Definition: SGuid.h:158
SGuid(unsigned long long data)
Creates a new GUID from the given data.
Definition: SGuid.h:62
void Set(unsigned serial, unsigned random, unsigned time)
Sets the GUID to the given components.
Definition: SGuid.h:93
contains implementation of a 8-byte short GUID.
uint64_t Integer
Single integer value representing this guid.
Definition: SGuid.h:29
void LoadLong(std::istream &file)
Loads a full length 16bit GUID from the given file. Used for back compatibility.
Definition: SGuid.h:147
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
SGuid(std::istream &in)
Reads a new GUID from the given stream.
Definition: SGuid.h:73
bool operator==(const SGuid &right) const
Compares two GUIDs.
Definition: SGuid.h:78
std::istream & operator>>(std::istream &in, TextualProperty< C_, T_, G_, S_ > &p)
Definition: Property.h:837
Byte Bytes[8]
Allows byte-by-byte addressing of the guid.
Definition: SGuid.h:27
constexpr Type SGuid
Identifies resources.
Definition: GID.h:115
SGuid(const CreateNewTag &)
Constructor to create a new guid.
Definition: SGuid.h:40
contains type definitions for Gorgon system
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
SGuid(unsigned serial, unsigned random, unsigned time)
Creates a new GUID from the given data.
Definition: SGuid.h:68
std::ostream & operator<<(std::ostream &out, const TextualProperty< C_, T_, G_, S_ > &p)
Definition: Property.h:823
This class represents a short globally unique identifier.
Definition: SGuid.h:22
void Load(std::istream &Data)
Loads the GUID from a given stream.
Definition: SGuid.h:140
void Save(std::ostream &file) const
Saves this GUID to file.
Definition: SGuid.h:153
SGuid()
Constructor for an empty guid.
Definition: SGuid.h:36
bool operator!=(const SGuid &right) const
Compares two GUIDs.
Definition: SGuid.h:83