mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
[12632] Revert previous commit (see Notes)
This commit is contained in:
parent
1cd806c02e
commit
ef445ea523
1462 changed files with 9689 additions and 7080 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
@file G3D/enumclass.h
|
||||
|
||||
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
#include "G3D/BinaryInput.h"
|
||||
#include "G3D/BinaryOutput.h"
|
||||
|
||||
/**
|
||||
/*
|
||||
\def G3D_DECLARE_ENUM_CLASS_METHODS
|
||||
|
||||
\brief Creates a series of methods that turn a class into a scoped enumeration.
|
||||
|
|
@ -22,112 +22,170 @@
|
|||
|
||||
Enum classes are initialized to their zero value by default.
|
||||
|
||||
You must implement the following method before calling G3D_DECLARE_ENUM_CLASS_METHODS, as either:
|
||||
|
||||
<pre>
|
||||
static const char* toString(int i, Value& v) {
|
||||
static const char* str[] = {"FUEL", "FOOD", "WATER", NULL}; // Whatever your enum values are
|
||||
static const Value val[] = {FUEL, FOOD, WATER}; // Whatever your enum values are
|
||||
const char* s = str[i];
|
||||
if (s) {
|
||||
v = val[i];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
</pre>
|
||||
|
||||
See GLG3D/GKey.h for an example.
|
||||
\sa G3D_DECLARE_ENUM_CLASS_HASHCODE
|
||||
*/
|
||||
#define G3D_DECLARE_ENUM_CLASS_METHODS(Classname)\
|
||||
inline Classname(char v) : value((Value)v) {}\
|
||||
private: \
|
||||
void fromString(const std::string& x) {\
|
||||
Value v;\
|
||||
const char* s;\
|
||||
int i = 0;\
|
||||
\
|
||||
inline Classname() : value((Value)0) {}\
|
||||
do {\
|
||||
s = toString(i, v);\
|
||||
if (x == s) {\
|
||||
value = v;\
|
||||
return;\
|
||||
}\
|
||||
++i;\
|
||||
} while (s);\
|
||||
}\
|
||||
\
|
||||
inline Classname(const Value v) : value(v) {}\
|
||||
public:\
|
||||
\
|
||||
explicit inline Classname(int v) : value((Value)v) {}\
|
||||
const char* toString() const {\
|
||||
const char* s;\
|
||||
int i = 0;\
|
||||
Value v = (Value)0;\
|
||||
while (true) {\
|
||||
s = toString(i, v);\
|
||||
if ((s == NULL) || (v == value)) {\
|
||||
return s;\
|
||||
}\
|
||||
++i;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
\
|
||||
explicit Classname(const std::string& x) : value((Value)0) {\
|
||||
fromString(x);\
|
||||
}\
|
||||
\
|
||||
Classname(const Any& a) : value((Value)0) {\
|
||||
fromString(a.string());\
|
||||
}\
|
||||
\
|
||||
operator Any() const {\
|
||||
return Any(toString());\
|
||||
}\
|
||||
\
|
||||
Classname(char v) : value((Value)v) {}\
|
||||
\
|
||||
Classname() : value((Value)0) {}\
|
||||
\
|
||||
Classname(const Value v) : value(v) {}\
|
||||
\
|
||||
explicit Classname(int v) : value((Value)v) {}\
|
||||
\
|
||||
/** Support cast back to the Value type, which is needed to allow implicit assignment inside unions. */\
|
||||
/*inline operator Value() const {
|
||||
return value;
|
||||
}*/\
|
||||
\
|
||||
inline operator int() const {\
|
||||
operator int() const {\
|
||||
return (int)value;\
|
||||
}\
|
||||
\
|
||||
inline bool operator== (const Classname other) const {\
|
||||
bool operator== (const Classname other) const {\
|
||||
return value == other.value;\
|
||||
}\
|
||||
\
|
||||
inline bool operator== (const Classname::Value other) const {\
|
||||
bool operator== (const Classname::Value other) const {\
|
||||
return value == other;\
|
||||
}\
|
||||
\
|
||||
inline bool operator!= (const Classname other) const {\
|
||||
bool operator!= (const Classname other) const {\
|
||||
return value != other.value;\
|
||||
}\
|
||||
\
|
||||
inline bool operator!= (const Classname::Value other) const {\
|
||||
bool operator!= (const Classname::Value other) const {\
|
||||
return value != other;\
|
||||
}\
|
||||
\
|
||||
inline bool operator< (const Classname other) const {\
|
||||
bool operator< (const Classname other) const {\
|
||||
return value < other.value;\
|
||||
}\
|
||||
\
|
||||
inline bool operator> (const Classname other) const {\
|
||||
bool operator> (const Classname other) const {\
|
||||
return value > other.value;\
|
||||
}\
|
||||
\
|
||||
inline bool operator>= (const Classname other) const {\
|
||||
bool operator>= (const Classname other) const {\
|
||||
return value >= other.value;\
|
||||
}\
|
||||
\
|
||||
inline bool operator<= (const Classname other) const {\
|
||||
bool operator<= (const Classname other) const {\
|
||||
return value <= other.value;\
|
||||
}\
|
||||
\
|
||||
inline bool operator< (const Value other) const {\
|
||||
bool operator< (const Value other) const {\
|
||||
return value < other;\
|
||||
}\
|
||||
\
|
||||
inline bool operator> (const Value other) const {\
|
||||
bool operator> (const Value other) const {\
|
||||
return value > other;\
|
||||
}\
|
||||
\
|
||||
inline bool operator<= (const Value other) const {\
|
||||
bool operator<= (const Value other) const {\
|
||||
return value <= other;\
|
||||
}\
|
||||
\
|
||||
inline bool operator>= (const Value other) const {\
|
||||
bool operator>= (const Value other) const {\
|
||||
return value >= other;\
|
||||
}\
|
||||
\
|
||||
inline Classname& operator-- () {\
|
||||
Classname& operator-- () {\
|
||||
value = (Value)((int)value - 1);\
|
||||
return *this;\
|
||||
}\
|
||||
\
|
||||
inline Classname& operator++ () {\
|
||||
Classname& operator++ () {\
|
||||
value = (Value)((int)value + 1);\
|
||||
return *this;\
|
||||
}\
|
||||
\
|
||||
inline Classname& operator+= (const int x) {\
|
||||
Classname& operator+= (const int x) {\
|
||||
value = (Value)((int)value + x);\
|
||||
return *this;\
|
||||
}\
|
||||
\
|
||||
inline Classname& operator-= (const int x) {\
|
||||
Classname& operator-= (const int x) {\
|
||||
value = (Value)((int)value - x);\
|
||||
return *this;\
|
||||
}\
|
||||
\
|
||||
inline Classname operator+ (const int x) const {\
|
||||
Classname operator+ (const int x) const {\
|
||||
return Classname((int)value + x);\
|
||||
}\
|
||||
\
|
||||
inline Classname operator- (const int x) const {\
|
||||
Classname operator- (const int x) const {\
|
||||
return Classname((int)value - x);\
|
||||
}\
|
||||
\
|
||||
inline unsigned int hashCode() const {\
|
||||
unsigned int hashCode() const {\
|
||||
return (unsigned int)value;\
|
||||
}\
|
||||
\
|
||||
inline void serialize(BinaryOutput& b) const {\
|
||||
void serialize(BinaryOutput& b) const {\
|
||||
b.writeInt32(value);\
|
||||
}\
|
||||
\
|
||||
inline void deserialize(BinaryInput& b) {\
|
||||
void deserialize(BinaryInput& b) {\
|
||||
value = (Value)b.readInt32();\
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue