2015-01-31 10:07:48 +00:00
|
|
|
/*-----------------------------------------------------------------------------------------------
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Copyright (c) 2014-2020 Kim Kulling
|
2015-01-31 10:07:48 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
-----------------------------------------------------------------------------------------------*/
|
2020-10-25 09:34:43 +00:00
|
|
|
#include <openddlparser/OpenDDLStream.h>
|
2015-01-31 10:07:48 +00:00
|
|
|
#include <openddlparser/Value.h>
|
2015-02-14 15:11:46 +00:00
|
|
|
|
2015-01-31 10:07:48 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
BEGIN_ODDLPARSER_NS
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
static Value::Iterator end(nullptr);
|
2015-10-01 18:29:15 +00:00
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value::Iterator::Iterator() :
|
|
|
|
m_start(nullptr),
|
|
|
|
m_current(nullptr) {
|
2015-05-31 18:36:55 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value::Iterator::Iterator(Value *start) :
|
|
|
|
m_start(start),
|
|
|
|
m_current(start) {
|
2015-05-31 18:36:55 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value::Iterator::Iterator(const Iterator &rhs) :
|
|
|
|
m_start(rhs.m_start),
|
|
|
|
m_current(rhs.m_current) {
|
2015-10-01 18:29:15 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2015-05-31 18:36:55 +00:00
|
|
|
Value::Iterator::~Iterator() {
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::Iterator::hasNext() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
if (nullptr == m_current) {
|
2015-05-31 18:36:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-10-25 09:34:43 +00:00
|
|
|
return (nullptr != m_current->getNext());
|
2015-05-31 18:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Value *Value::Iterator::getNext() {
|
2020-10-25 09:34:43 +00:00
|
|
|
if (!hasNext()) {
|
|
|
|
return nullptr;
|
2015-05-31 18:36:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value *v(m_current->getNext());
|
2015-05-31 18:36:55 +00:00
|
|
|
m_current = v;
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
const Value::Iterator Value::Iterator::operator++(int) {
|
|
|
|
if (nullptr == m_current) {
|
2015-10-01 18:29:15 +00:00
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_current = m_current->getNext();
|
2020-10-25 09:34:43 +00:00
|
|
|
Iterator inst(m_current);
|
2015-10-01 18:29:15 +00:00
|
|
|
|
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value::Iterator &Value::Iterator::operator++() {
|
|
|
|
if (nullptr == m_current) {
|
2015-10-01 18:29:15 +00:00
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_current = m_current->getNext();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
bool Value::Iterator::operator==(const Iterator &rhs) const {
|
|
|
|
return (m_current == rhs.m_current);
|
2015-10-01 18:29:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value *Value::Iterator::operator->() const {
|
|
|
|
if (nullptr == m_current) {
|
|
|
|
return nullptr;
|
2015-10-01 18:29:15 +00:00
|
|
|
}
|
|
|
|
return m_current;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value::Value(ValueType type) :
|
|
|
|
m_type(type),
|
|
|
|
m_size(0),
|
|
|
|
m_data(nullptr),
|
|
|
|
m_next(nullptr) {
|
2015-01-31 10:07:48 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
Value::~Value() {
|
2020-10-25 09:34:43 +00:00
|
|
|
if (m_data != nullptr) {
|
|
|
|
if (m_type == ValueType::ddl_ref) {
|
|
|
|
Reference *tmp = (Reference *)m_data;
|
2021-09-07 13:04:08 +00:00
|
|
|
if (tmp != nullptr) {
|
2017-06-19 19:07:18 +00:00
|
|
|
delete tmp;
|
2021-09-07 13:04:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-06-19 19:07:18 +00:00
|
|
|
delete[] m_data;
|
2021-09-07 13:04:08 +00:00
|
|
|
}
|
2017-06-19 19:07:18 +00:00
|
|
|
}
|
2021-09-07 13:04:08 +00:00
|
|
|
delete m_next;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setBool(bool value) {
|
|
|
|
assert(ValueType::ddl_bool == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::getBool() {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_bool == m_type);
|
|
|
|
return (*m_data == 1);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setInt8(int8 value) {
|
|
|
|
assert(ValueType::ddl_int8 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int8 Value::getInt8() {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_int8 == m_type);
|
|
|
|
return (int8)(*m_data);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setInt16(int16 value) {
|
|
|
|
assert(ValueType::ddl_int16 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int16 Value::getInt16() {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_int16 == m_type);
|
2015-10-31 08:43:34 +00:00
|
|
|
int16 i;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&i, m_data, m_size);
|
2015-10-31 08:43:34 +00:00
|
|
|
return i;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setInt32(int32 value) {
|
|
|
|
assert(ValueType::ddl_int32 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 Value::getInt32() {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_int32 == m_type);
|
2015-10-31 08:43:34 +00:00
|
|
|
int32 i;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&i, m_data, m_size);
|
2015-10-31 08:43:34 +00:00
|
|
|
return i;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setInt64(int64 value) {
|
|
|
|
assert(ValueType::ddl_int64 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int64 Value::getInt64() {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_int64 == m_type);
|
2015-10-31 08:43:34 +00:00
|
|
|
int64 i;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&i, m_data, m_size);
|
2015-10-31 08:43:34 +00:00
|
|
|
return i;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setUnsignedInt8(uint8 value) {
|
|
|
|
assert(ValueType::ddl_unsigned_int8 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8 Value::getUnsignedInt8() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_unsigned_int8 == m_type);
|
2015-10-31 08:43:34 +00:00
|
|
|
uint8 i;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&i, m_data, m_size);
|
2015-10-31 08:43:34 +00:00
|
|
|
return i;
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setUnsignedInt16(uint16 value) {
|
|
|
|
assert(ValueType::ddl_unsigned_int16 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
2015-05-05 20:26:40 +00:00
|
|
|
|
2015-04-14 10:04:39 +00:00
|
|
|
uint16 Value::getUnsignedInt16() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_unsigned_int16 == m_type);
|
2015-10-31 08:43:34 +00:00
|
|
|
uint16 i;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&i, m_data, m_size);
|
2015-10-31 08:43:34 +00:00
|
|
|
return i;
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setUnsignedInt32(uint32 value) {
|
|
|
|
assert(ValueType::ddl_unsigned_int32 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 Value::getUnsignedInt32() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_unsigned_int32 == m_type);
|
2015-10-31 08:43:34 +00:00
|
|
|
uint32 i;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&i, m_data, m_size);
|
2015-10-31 08:43:34 +00:00
|
|
|
return i;
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setUnsignedInt64(uint64 value) {
|
|
|
|
assert(ValueType::ddl_unsigned_int64 == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64 Value::getUnsignedInt64() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_unsigned_int64 == m_type);
|
2015-10-31 08:43:34 +00:00
|
|
|
uint64 i;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&i, m_data, m_size);
|
2015-10-31 08:43:34 +00:00
|
|
|
return i;
|
2015-04-14 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setFloat(float value) {
|
|
|
|
assert(ValueType::ddl_float == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float Value::getFloat() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
if (m_type == ValueType::ddl_float) {
|
2015-05-05 20:26:40 +00:00
|
|
|
float v;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&v, m_data, m_size);
|
|
|
|
return (float)v;
|
2015-05-05 20:26:40 +00:00
|
|
|
} else {
|
|
|
|
float tmp;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&tmp, m_data, 4);
|
|
|
|
return (float)tmp;
|
2015-05-05 20:26:40 +00:00
|
|
|
}
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setDouble(double value) {
|
|
|
|
assert(ValueType::ddl_double == m_type);
|
|
|
|
::memcpy(m_data, &value, m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double Value::getDouble() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
if (m_type == ValueType::ddl_double) {
|
2016-02-07 16:58:28 +00:00
|
|
|
double v;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&v, m_data, m_size);
|
|
|
|
return (float)v;
|
|
|
|
} else {
|
2016-02-07 16:58:28 +00:00
|
|
|
double tmp;
|
2020-10-25 09:34:43 +00:00
|
|
|
::memcpy(&tmp, m_data, 4);
|
|
|
|
return (double)tmp;
|
2016-02-07 16:58:28 +00:00
|
|
|
}
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setString(const std::string &str) {
|
|
|
|
assert(ValueType::ddl_string == m_type);
|
|
|
|
::memcpy(m_data, str.c_str(), str.size());
|
|
|
|
m_data[str.size()] = '\0';
|
2015-02-14 15:11:46 +00:00
|
|
|
}
|
2016-02-07 16:58:28 +00:00
|
|
|
|
2015-02-14 15:11:46 +00:00
|
|
|
const char *Value::getString() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_string == m_type);
|
|
|
|
return (const char *)m_data;
|
2015-02-14 15:11:46 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setRef(Reference *ref) {
|
|
|
|
assert(ValueType::ddl_ref == m_type);
|
2016-02-07 16:58:28 +00:00
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
if (nullptr != ref) {
|
|
|
|
const size_t sizeInBytes(ref->sizeInBytes());
|
|
|
|
if (sizeInBytes > 0) {
|
|
|
|
if (nullptr != m_data) {
|
|
|
|
delete[] m_data;
|
2016-02-07 16:58:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
m_data = (unsigned char *)new Reference(*ref);
|
2016-02-07 16:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference *Value::getRef() const {
|
2020-10-25 09:34:43 +00:00
|
|
|
assert(ValueType::ddl_ref == m_type);
|
2016-02-07 16:58:28 +00:00
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
return (Reference *)m_data;
|
2016-02-07 16:58:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::dump(IOStreamBase &stream) {
|
|
|
|
switch (m_type) {
|
|
|
|
case ValueType::ddl_none:
|
|
|
|
stream.write("None\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_bool:
|
|
|
|
stream.write(std::to_string(getBool()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_int8:
|
|
|
|
stream.write(std::to_string(getInt8()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_int16:
|
|
|
|
stream.write(std::to_string(getInt16()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_int32:
|
|
|
|
stream.write(std::to_string(getInt32()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_int64:
|
|
|
|
stream.write(std::to_string(getInt64()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_unsigned_int8:
|
|
|
|
stream.write("Not supported\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_unsigned_int16:
|
|
|
|
stream.write("Not supported\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_unsigned_int32:
|
|
|
|
stream.write("Not supported\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_unsigned_int64:
|
|
|
|
stream.write("Not supported\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_half:
|
|
|
|
stream.write("Not supported\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_float:
|
|
|
|
stream.write(std::to_string(getFloat()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_double:
|
|
|
|
stream.write(std::to_string(getDouble()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_string:
|
|
|
|
stream.write(std::string(getString()) + "\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case ValueType::ddl_ref:
|
|
|
|
stream.write("Not supported\n");
|
2016-02-07 16:58:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void Value::setNext(Value *next) {
|
2015-01-31 10:07:48 +00:00
|
|
|
m_next = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *Value::getNext() const {
|
|
|
|
return m_next;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
size_t Value::size() const {
|
|
|
|
size_t result = 1;
|
|
|
|
Value *n = m_next;
|
|
|
|
while (n != nullptr) {
|
2016-01-08 15:46:13 +00:00
|
|
|
result++;
|
2020-10-25 09:34:43 +00:00
|
|
|
n = n->m_next;
|
2016-01-08 15:46:13 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value *ValueAllocator::allocPrimData(Value::ValueType type, size_t len) {
|
|
|
|
if (type == Value::ValueType::ddl_none || Value::ValueType::ddl_types_max == type) {
|
|
|
|
return nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
Value *data = new Value(type);
|
|
|
|
switch (type) {
|
|
|
|
case Value::ValueType::ddl_bool:
|
|
|
|
data->m_size = sizeof(bool);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_int8:
|
|
|
|
data->m_size = sizeof(int8);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_int16:
|
|
|
|
data->m_size = sizeof(int16);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_int32:
|
|
|
|
data->m_size = sizeof(int32);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_int64:
|
|
|
|
data->m_size = sizeof(int64);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_unsigned_int8:
|
|
|
|
data->m_size = sizeof(uint8);
|
2015-10-31 08:43:34 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_unsigned_int16:
|
|
|
|
data->m_size = sizeof(uint16);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_unsigned_int32:
|
|
|
|
data->m_size = sizeof(uint32);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_unsigned_int64:
|
|
|
|
data->m_size = sizeof(uint64);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_half:
|
|
|
|
data->m_size = sizeof(short);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_float:
|
|
|
|
data->m_size = sizeof(float);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_double:
|
|
|
|
data->m_size = sizeof(double);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_string:
|
|
|
|
data->m_size = sizeof(char) * (len + 1);
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_ref:
|
2017-06-19 19:07:18 +00:00
|
|
|
data->m_size = 0;
|
2015-01-31 10:07:48 +00:00
|
|
|
break;
|
2020-10-25 09:34:43 +00:00
|
|
|
case Value::ValueType::ddl_none:
|
|
|
|
case Value::ValueType::ddl_types_max:
|
2015-01-31 10:07:48 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
if (data->m_size) {
|
|
|
|
data->m_data = new unsigned char[data->m_size];
|
|
|
|
::memset(data->m_data, 0, data->m_size);
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:34:43 +00:00
|
|
|
void ValueAllocator::releasePrimData(Value **data) {
|
|
|
|
if (!data) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete *data;
|
2020-10-25 09:34:43 +00:00
|
|
|
*data = nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_ODDLPARSER_NS
|