123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- #ifndef __cocos2d_libs__CCValue__
- #define __cocos2d_libs__CCValue__
- #include "platform/CCPlatformMacros.h"
- #include "base/ccMacros.h"
- #include <string>
- #include <vector>
- #include <unordered_map>
- NS_CC_BEGIN
- class Value;
- typedef std::vector<Value> ValueVector;
- typedef std::unordered_map<std::string, Value> ValueMap;
- typedef std::unordered_map<int, Value> ValueMapIntKey;
- CC_DLL extern const ValueVector ValueVectorNull;
- CC_DLL extern const ValueMap ValueMapNull;
- CC_DLL extern const ValueMapIntKey ValueMapIntKeyNull;
- class CC_DLL Value
- {
- public:
-
- static const Value Null;
-
- Value();
-
-
- explicit Value(unsigned char v);
-
-
- explicit Value(int v);
-
- explicit Value(unsigned int v);
-
- explicit Value(float v);
-
-
- explicit Value(double v);
-
-
- explicit Value(bool v);
-
-
- explicit Value(const char* v);
-
-
- explicit Value(const std::string& v);
-
-
- explicit Value(const ValueVector& v);
-
- explicit Value(ValueVector&& v);
-
-
- explicit Value(const ValueMap& v);
-
- explicit Value(ValueMap&& v);
-
-
- explicit Value(const ValueMapIntKey& v);
-
- explicit Value(ValueMapIntKey&& v);
-
- Value(const Value& other);
-
- Value(Value&& other);
-
-
- ~Value();
-
- Value& operator= (const Value& other);
-
- Value& operator= (Value&& other);
-
- Value& operator= (unsigned char v);
-
- Value& operator= (int v);
-
- Value& operator= (unsigned int v);
-
- Value& operator= (float v);
-
- Value& operator= (double v);
-
- Value& operator= (bool v);
-
- Value& operator= (const char* v);
-
- Value& operator= (const std::string& v);
-
- Value& operator= (const ValueVector& v);
-
- Value& operator= (ValueVector&& v);
-
- Value& operator= (const ValueMap& v);
-
- Value& operator= (ValueMap&& v);
-
- Value& operator= (const ValueMapIntKey& v);
-
- Value& operator= (ValueMapIntKey&& v);
-
- bool operator!= (const Value& v);
-
- bool operator!= (const Value& v) const;
-
- bool operator== (const Value& v);
-
- bool operator== (const Value& v) const;
-
- unsigned char asByte() const;
-
- int asInt() const;
-
- unsigned int asUnsignedInt() const;
-
- float asFloat() const;
-
- double asDouble() const;
-
- bool asBool() const;
-
- std::string asString() const;
-
- ValueVector& asValueVector();
-
- const ValueVector& asValueVector() const;
-
- ValueMap& asValueMap();
-
- const ValueMap& asValueMap() const;
-
- ValueMapIntKey& asIntKeyMap();
-
- const ValueMapIntKey& asIntKeyMap() const;
-
- bool isNull() const { return _type == Type::NONE; }
-
- enum class Type
- {
-
- NONE = 0,
-
- BYTE,
-
- INTEGER,
-
- UNSIGNED,
-
- FLOAT,
-
- DOUBLE,
-
- BOOLEAN,
-
- STRING,
-
- VECTOR,
-
- MAP,
-
- INT_KEY_MAP
- };
-
- Type getType() const { return _type; }
-
- std::string getDescription() const;
- private:
- void clear();
- void reset(Type type);
- union
- {
- unsigned char byteVal;
- int intVal;
- unsigned int unsignedVal;
- float floatVal;
- double doubleVal;
- bool boolVal;
- std::string* strVal;
- ValueVector* vectorVal;
- ValueMap* mapVal;
- ValueMapIntKey* intKeyMapVal;
- }_field;
- Type _type;
- };
- NS_CC_END
- #endif
|