123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934 |
- /****************************************************************************
- Copyright (c) 2013-2017 Chukong Technologies
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- #include "base/CCValue.h"
- #include <cmath>
- #include <sstream>
- #include <iomanip>
- #include "base/ccUtils.h"
- NS_CC_BEGIN
- const ValueVector ValueVectorNull;
- const ValueMap ValueMapNull;
- const ValueMapIntKey ValueMapIntKeyNull;
- const Value Value::Null;
- Value::Value()
- : _type(Type::NONE)
- {
- memset(&_field, 0, sizeof(_field));
- }
- Value::Value(unsigned char v)
- : _type(Type::BYTE)
- {
- _field.byteVal = v;
- }
- Value::Value(int v)
- : _type(Type::INTEGER)
- {
- _field.intVal = v;
- }
- Value::Value(unsigned int v)
- : _type(Type::UNSIGNED)
- {
- _field.unsignedVal = v;
- }
- Value::Value(float v)
- : _type(Type::FLOAT)
- {
- _field.floatVal = v;
- }
- Value::Value(double v)
- : _type(Type::DOUBLE)
- {
- _field.doubleVal = v;
- }
- Value::Value(bool v)
- : _type(Type::BOOLEAN)
- {
- _field.boolVal = v;
- }
- Value::Value(const char* v)
- : _type(Type::STRING)
- {
- _field.strVal = new (std::nothrow) std::string();
- if (v)
- {
- *_field.strVal = v;
- }
- }
- Value::Value(const std::string& v)
- : _type(Type::STRING)
- {
- _field.strVal = new (std::nothrow) std::string();
- *_field.strVal = v;
- }
- Value::Value(const ValueVector& v)
- : _type(Type::VECTOR)
- {
- _field.vectorVal = new (std::nothrow) ValueVector();
- *_field.vectorVal = v;
- }
- Value::Value(ValueVector&& v)
- : _type(Type::VECTOR)
- {
- _field.vectorVal = new (std::nothrow) ValueVector();
- *_field.vectorVal = std::move(v);
- }
- Value::Value(const ValueMap& v)
- : _type(Type::MAP)
- {
- _field.mapVal = new (std::nothrow) ValueMap();
- *_field.mapVal = v;
- }
- Value::Value(ValueMap&& v)
- : _type(Type::MAP)
- {
- _field.mapVal = new (std::nothrow) ValueMap();
- *_field.mapVal = std::move(v);
- }
- Value::Value(const ValueMapIntKey& v)
- : _type(Type::INT_KEY_MAP)
- {
- _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey();
- *_field.intKeyMapVal = v;
- }
- Value::Value(ValueMapIntKey&& v)
- : _type(Type::INT_KEY_MAP)
- {
- _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey();
- *_field.intKeyMapVal = std::move(v);
- }
- Value::Value(const Value& other)
- : _type(Type::NONE)
- {
- *this = other;
- }
- Value::Value(Value&& other)
- : _type(Type::NONE)
- {
- *this = std::move(other);
- }
- Value::~Value()
- {
- clear();
- }
- Value& Value::operator= (const Value& other)
- {
- if (this != &other) {
- reset(other._type);
- switch (other._type) {
- case Type::BYTE:
- _field.byteVal = other._field.byteVal;
- break;
- case Type::INTEGER:
- _field.intVal = other._field.intVal;
- break;
- case Type::UNSIGNED:
- _field.unsignedVal = other._field.unsignedVal;
- break;
- case Type::FLOAT:
- _field.floatVal = other._field.floatVal;
- break;
- case Type::DOUBLE:
- _field.doubleVal = other._field.doubleVal;
- break;
- case Type::BOOLEAN:
- _field.boolVal = other._field.boolVal;
- break;
- case Type::STRING:
- if (_field.strVal == nullptr)
- {
- _field.strVal = new std::string();
- }
- *_field.strVal = *other._field.strVal;
- break;
- case Type::VECTOR:
- if (_field.vectorVal == nullptr)
- {
- _field.vectorVal = new (std::nothrow) ValueVector();
- }
- *_field.vectorVal = *other._field.vectorVal;
- break;
- case Type::MAP:
- if (_field.mapVal == nullptr)
- {
- _field.mapVal = new (std::nothrow) ValueMap();
- }
- *_field.mapVal = *other._field.mapVal;
- break;
- case Type::INT_KEY_MAP:
- if (_field.intKeyMapVal == nullptr)
- {
- _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey();
- }
- *_field.intKeyMapVal = *other._field.intKeyMapVal;
- break;
- default:
- break;
- }
- }
- return *this;
- }
- Value& Value::operator= (Value&& other)
- {
- if (this != &other)
- {
- clear();
- switch (other._type)
- {
- case Type::BYTE:
- _field.byteVal = other._field.byteVal;
- break;
- case Type::INTEGER:
- _field.intVal = other._field.intVal;
- break;
- case Type::UNSIGNED:
- _field.unsignedVal = other._field.unsignedVal;
- break;
- case Type::FLOAT:
- _field.floatVal = other._field.floatVal;
- break;
- case Type::DOUBLE:
- _field.doubleVal = other._field.doubleVal;
- break;
- case Type::BOOLEAN:
- _field.boolVal = other._field.boolVal;
- break;
- case Type::STRING:
- _field.strVal = other._field.strVal;
- break;
- case Type::VECTOR:
- _field.vectorVal = other._field.vectorVal;
- break;
- case Type::MAP:
- _field.mapVal = other._field.mapVal;
- break;
- case Type::INT_KEY_MAP:
- _field.intKeyMapVal = other._field.intKeyMapVal;
- break;
- default:
- break;
- }
- _type = other._type;
- memset(&other._field, 0, sizeof(other._field));
- other._type = Type::NONE;
- }
- return *this;
- }
- Value& Value::operator= (unsigned char v)
- {
- reset(Type::BYTE);
- _field.byteVal = v;
- return *this;
- }
- Value& Value::operator= (int v)
- {
- reset(Type::INTEGER);
- _field.intVal = v;
- return *this;
- }
- Value& Value::operator= (unsigned int v)
- {
- reset(Type::UNSIGNED);
- _field.unsignedVal = v;
- return *this;
- }
- Value& Value::operator= (float v)
- {
- reset(Type::FLOAT);
- _field.floatVal = v;
- return *this;
- }
- Value& Value::operator= (double v)
- {
- reset(Type::DOUBLE);
- _field.doubleVal = v;
- return *this;
- }
- Value& Value::operator= (bool v)
- {
- reset(Type::BOOLEAN);
- _field.boolVal = v;
- return *this;
- }
- Value& Value::operator= (const char* v)
- {
- reset(Type::STRING);
- *_field.strVal = v ? v : "";
- return *this;
- }
- Value& Value::operator= (const std::string& v)
- {
- reset(Type::STRING);
- *_field.strVal = v;
- return *this;
- }
- Value& Value::operator= (const ValueVector& v)
- {
- reset(Type::VECTOR);
- *_field.vectorVal = v;
- return *this;
- }
- Value& Value::operator= (ValueVector&& v)
- {
- reset(Type::VECTOR);
- *_field.vectorVal = std::move(v);
- return *this;
- }
- Value& Value::operator= (const ValueMap& v)
- {
- reset(Type::MAP);
- *_field.mapVal = v;
- return *this;
- }
- Value& Value::operator= (ValueMap&& v)
- {
- reset(Type::MAP);
- *_field.mapVal = std::move(v);
- return *this;
- }
- Value& Value::operator= (const ValueMapIntKey& v)
- {
- reset(Type::INT_KEY_MAP);
- *_field.intKeyMapVal = v;
- return *this;
- }
- Value& Value::operator= (ValueMapIntKey&& v)
- {
- reset(Type::INT_KEY_MAP);
- *_field.intKeyMapVal = std::move(v);
- return *this;
- }
- bool Value::operator!= (const Value& v)
- {
- return !(*this == v);
- }
- bool Value::operator!= (const Value& v) const
- {
- return !(*this == v);
- }
- bool Value::operator== (const Value& v)
- {
- const auto &t = *this;
- return t == v;
- }
- bool Value::operator== (const Value& v) const
- {
- if (this == &v) return true;
- if (v._type != this->_type) return false;
- if (this->isNull()) return true;
- switch (_type)
- {
- case Type::BYTE: return v._field.byteVal == this->_field.byteVal;
- case Type::INTEGER: return v._field.intVal == this->_field.intVal;
- case Type::UNSIGNED:return v._field.unsignedVal == this->_field.unsignedVal;
- case Type::BOOLEAN: return v._field.boolVal == this->_field.boolVal;
- case Type::STRING: return *v._field.strVal == *this->_field.strVal;
- case Type::FLOAT: return std::abs(v._field.floatVal - this->_field.floatVal) <= FLT_EPSILON;
- case Type::DOUBLE: return std::abs(v._field.doubleVal - this->_field.doubleVal) <= DBL_EPSILON;
- case Type::VECTOR:
- {
- const auto &v1 = *(this->_field.vectorVal);
- const auto &v2 = *(v._field.vectorVal);
- const auto size = v1.size();
- if (size == v2.size())
- {
- for (size_t i = 0; i < size; i++)
- {
- if (v1[i] != v2[i]) return false;
- }
- return true;
- }
- return false;
- }
- case Type::MAP:
- {
- const auto &map1 = *(this->_field.mapVal);
- const auto &map2 = *(v._field.mapVal);
- for (const auto &kvp : map1)
- {
- auto it = map2.find(kvp.first);
- if (it == map2.end() || it->second != kvp.second)
- {
- return false;
- }
- }
- return true;
- }
- case Type::INT_KEY_MAP:
- {
- const auto &map1 = *(this->_field.intKeyMapVal);
- const auto &map2 = *(v._field.intKeyMapVal);
- for (const auto &kvp : map1)
- {
- auto it = map2.find(kvp.first);
- if (it == map2.end() || it->second != kvp.second)
- {
- return false;
- }
- }
- return true;
- }
- default:
- break;
- };
- return false;
- }
- /// Convert value to a specified type
- unsigned char Value::asByte() const
- {
- CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
- if (_type == Type::BYTE)
- {
- return _field.byteVal;
- }
- if (_type == Type::INTEGER)
- {
- return static_cast<unsigned char>(_field.intVal);
- }
- if (_type == Type::UNSIGNED)
- {
- return static_cast<unsigned char>(_field.unsignedVal);
- }
- if (_type == Type::STRING)
- {
- return static_cast<unsigned char>(atoi(_field.strVal->c_str()));
- }
- if (_type == Type::FLOAT)
- {
- return static_cast<unsigned char>(_field.floatVal);
- }
- if (_type == Type::DOUBLE)
- {
- return static_cast<unsigned char>(_field.doubleVal);
- }
- if (_type == Type::BOOLEAN)
- {
- return _field.boolVal ? 1 : 0;
- }
- return 0;
- }
- int Value::asInt() const
- {
- CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
- if (_type == Type::INTEGER)
- {
- return _field.intVal;
- }
- if (_type == Type::UNSIGNED)
- {
- CCASSERT(_field.unsignedVal < INT_MAX, "Can only convert values < INT_MAX");
- return (int)_field.unsignedVal;
- }
- if (_type == Type::BYTE)
- {
- return _field.byteVal;
- }
- if (_type == Type::STRING)
- {
- return atoi(_field.strVal->c_str());
- }
- if (_type == Type::FLOAT)
- {
- return static_cast<int>(_field.floatVal);
- }
- if (_type == Type::DOUBLE)
- {
- return static_cast<int>(_field.doubleVal);
- }
- if (_type == Type::BOOLEAN)
- {
- return _field.boolVal ? 1 : 0;
- }
- return 0;
- }
- unsigned int Value::asUnsignedInt() const
- {
- CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
- if (_type == Type::UNSIGNED)
- {
- return _field.unsignedVal;
- }
- if (_type == Type::INTEGER)
- {
- CCASSERT(_field.intVal >= 0, "Only values >= 0 can be converted to unsigned");
- return static_cast<unsigned int>(_field.intVal);
- }
- if (_type == Type::BYTE)
- {
- return static_cast<unsigned int>(_field.byteVal);
- }
- if (_type == Type::STRING)
- {
- // NOTE: strtoul is required (need to augment on unsupported platforms)
- return static_cast<unsigned int>(strtoul(_field.strVal->c_str(), nullptr, 10));
- }
- if (_type == Type::FLOAT)
- {
- return static_cast<unsigned int>(_field.floatVal);
- }
- if (_type == Type::DOUBLE)
- {
- return static_cast<unsigned int>(_field.doubleVal);
- }
- if (_type == Type::BOOLEAN)
- {
- return _field.boolVal ? 1u : 0u;
- }
- return 0u;
- }
- float Value::asFloat() const
- {
- CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
- if (_type == Type::FLOAT)
- {
- return _field.floatVal;
- }
- if (_type == Type::BYTE)
- {
- return static_cast<float>(_field.byteVal);
- }
- if (_type == Type::STRING)
- {
- return utils::atof(_field.strVal->c_str());
- }
- if (_type == Type::INTEGER)
- {
- return static_cast<float>(_field.intVal);
- }
- if (_type == Type::UNSIGNED)
- {
- return static_cast<float>(_field.unsignedVal);
- }
- if (_type == Type::DOUBLE)
- {
- return static_cast<float>(_field.doubleVal);
- }
- if (_type == Type::BOOLEAN)
- {
- return _field.boolVal ? 1.0f : 0.0f;
- }
- return 0.0f;
- }
- double Value::asDouble() const
- {
- CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
- if (_type == Type::DOUBLE)
- {
- return _field.doubleVal;
- }
- if (_type == Type::BYTE)
- {
- return static_cast<double>(_field.byteVal);
- }
- if (_type == Type::STRING)
- {
- return static_cast<double>(utils::atof(_field.strVal->c_str()));
- }
- if (_type == Type::INTEGER)
- {
- return static_cast<double>(_field.intVal);
- }
- if (_type == Type::UNSIGNED)
- {
- return static_cast<double>(_field.unsignedVal);
- }
- if (_type == Type::FLOAT)
- {
- return static_cast<double>(_field.floatVal);
- }
- if (_type == Type::BOOLEAN)
- {
- return _field.boolVal ? 1.0 : 0.0;
- }
- return 0.0;
- }
- bool Value::asBool() const
- {
- CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
- if (_type == Type::BOOLEAN)
- {
- return _field.boolVal;
- }
- if (_type == Type::BYTE)
- {
- return _field.byteVal == 0 ? false : true;
- }
- if (_type == Type::STRING)
- {
- return (*_field.strVal == "0" || *_field.strVal == "false") ? false : true;
- }
- if (_type == Type::INTEGER)
- {
- return _field.intVal == 0 ? false : true;
- }
- if (_type == Type::UNSIGNED)
- {
- return _field.unsignedVal == 0 ? false : true;
- }
- if (_type == Type::FLOAT)
- {
- return _field.floatVal == 0.0f ? false : true;
- }
- if (_type == Type::DOUBLE)
- {
- return _field.doubleVal == 0.0 ? false : true;
- }
- return false;
- }
- std::string Value::asString() const
- {
- CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
- if (_type == Type::STRING)
- {
- return *_field.strVal;
- }
- std::stringstream ret;
- switch (_type)
- {
- case Type::BYTE:
- ret << _field.byteVal;
- break;
- case Type::INTEGER:
- ret << _field.intVal;
- break;
- case Type::UNSIGNED:
- ret << _field.unsignedVal;
- break;
- case Type::FLOAT:
- ret << std::fixed << std::setprecision( 7 )<< _field.floatVal;
- break;
- case Type::DOUBLE:
- ret << std::fixed << std::setprecision( 16 ) << _field.doubleVal;
- break;
- case Type::BOOLEAN:
- ret << (_field.boolVal ? "true" : "false");
- break;
- default:
- break;
- }
- return ret.str();
- }
- ValueVector& Value::asValueVector()
- {
- CCASSERT(_type == Type::VECTOR, "The value type isn't Type::VECTOR");
- return *_field.vectorVal;
- }
- const ValueVector& Value::asValueVector() const
- {
- CCASSERT(_type == Type::VECTOR, "The value type isn't Type::VECTOR");
- return *_field.vectorVal;
- }
- ValueMap& Value::asValueMap()
- {
- CCASSERT(_type == Type::MAP, "The value type isn't Type::MAP");
- return *_field.mapVal;
- }
- const ValueMap& Value::asValueMap() const
- {
- CCASSERT(_type == Type::MAP, "The value type isn't Type::MAP");
- return *_field.mapVal;
- }
- ValueMapIntKey& Value::asIntKeyMap()
- {
- CCASSERT(_type == Type::INT_KEY_MAP, "The value type isn't Type::INT_KEY_MAP");
- return *_field.intKeyMapVal;
- }
- const ValueMapIntKey& Value::asIntKeyMap() const
- {
- CCASSERT(_type == Type::INT_KEY_MAP, "The value type isn't Type::INT_KEY_MAP");
- return *_field.intKeyMapVal;
- }
- static std::string getTabs(int depth)
- {
- std::string tabWidth;
- for (int i = 0; i < depth; ++i)
- {
- tabWidth += "\t";
- }
- return tabWidth;
- }
- static std::string visit(const Value& v, int depth);
- static std::string visitVector(const ValueVector& v, int depth)
- {
- std::stringstream ret;
- if (depth > 0)
- ret << "\n";
- ret << getTabs(depth) << "[\n";
- int i = 0;
- for (const auto& child : v)
- {
- ret << getTabs(depth+1) << i << ": " << visit(child, depth + 1);
- ++i;
- }
- ret << getTabs(depth) << "]\n";
- return ret.str();
- }
- template <class T>
- static std::string visitMap(const T& v, int depth)
- {
- std::stringstream ret;
- if (depth > 0)
- ret << "\n";
- ret << getTabs(depth) << "{\n";
- for (auto& iter : v)
- {
- ret << getTabs(depth + 1) << iter.first << ": ";
- ret << visit(iter.second, depth + 1);
- }
- ret << getTabs(depth) << "}\n";
- return ret.str();
- }
- static std::string visit(const Value& v, int depth)
- {
- std::stringstream ret;
- switch (v.getType())
- {
- case Value::Type::NONE:
- case Value::Type::BYTE:
- case Value::Type::INTEGER:
- case Value::Type::UNSIGNED:
- case Value::Type::FLOAT:
- case Value::Type::DOUBLE:
- case Value::Type::BOOLEAN:
- case Value::Type::STRING:
- ret << v.asString() << "\n";
- break;
- case Value::Type::VECTOR:
- ret << visitVector(v.asValueVector(), depth);
- break;
- case Value::Type::MAP:
- ret << visitMap(v.asValueMap(), depth);
- break;
- case Value::Type::INT_KEY_MAP:
- ret << visitMap(v.asIntKeyMap(), depth);
- break;
- default:
- CCASSERT(false, "Invalid type!");
- break;
- }
- return ret.str();
- }
- std::string Value::getDescription() const
- {
- std::string ret("\n");
- ret += visit(*this, 0);
- return ret;
- }
- void Value::clear()
- {
- // Free memory the old value allocated
- switch (_type)
- {
- case Type::BYTE:
- _field.byteVal = 0;
- break;
- case Type::INTEGER:
- _field.intVal = 0;
- break;
- case Type::UNSIGNED:
- _field.unsignedVal = 0u;
- break;
- case Type::FLOAT:
- _field.floatVal = 0.0f;
- break;
- case Type::DOUBLE:
- _field.doubleVal = 0.0;
- break;
- case Type::BOOLEAN:
- _field.boolVal = false;
- break;
- case Type::STRING:
- CC_SAFE_DELETE(_field.strVal);
- break;
- case Type::VECTOR:
- CC_SAFE_DELETE(_field.vectorVal);
- break;
- case Type::MAP:
- CC_SAFE_DELETE(_field.mapVal);
- break;
- case Type::INT_KEY_MAP:
- CC_SAFE_DELETE(_field.intKeyMapVal);
- break;
- default:
- break;
- }
- _type = Type::NONE;
- }
- void Value::reset(Type type)
- {
- if (_type == type)
- return;
- clear();
- // Allocate memory for the new value
- switch (type)
- {
- case Type::STRING:
- _field.strVal = new (std::nothrow) std::string();
- break;
- case Type::VECTOR:
- _field.vectorVal = new (std::nothrow) ValueVector();
- break;
- case Type::MAP:
- _field.mapVal = new (std::nothrow) ValueMap();
- break;
- case Type::INT_KEY_MAP:
- _field.intKeyMapVal = new (std::nothrow) ValueMapIntKey();
- break;
- default:
- break;
- }
- _type = type;
- }
- NS_CC_END
|