29 #define _unused(x) ((void)(x)) 34 #include "SUAPI-CppWrapper/model/TypedValue.hpp" 35 #include "SUAPI-CppWrapper/Color.hpp" 36 #include "SUAPI-CppWrapper/Geometry.hpp" 37 #include "SUAPI-CppWrapper/String.hpp" 41 TypedValue::TypedValue():
42 m_typed_value(create_typed_value()),
47 TypedValue::TypedValue(SUTypedValueRef typed_val,
bool attached):
48 m_typed_value(typed_val),
64 case SUTypedValueType_Array:
70 case SUTypedValueType_Bool:
73 case SUTypedValueType_Byte:
76 case SUTypedValueType_Color:
79 case SUTypedValueType_Double:
82 case SUTypedValueType_Empty:
85 case SUTypedValueType_Float:
88 case SUTypedValueType_Int32:
91 case SUTypedValueType_Short:
93 throw "this part hasn't been made yet.";
95 case SUTypedValueType_String:
98 case SUTypedValueType_Time:
101 case SUTypedValueType_Vector3D:
109 SUTypedValueRef TypedValue::ref()
const {
110 return m_typed_value;
114 TypedValue::operator SUTypedValueRef() {
119 TypedValue::operator SUTypedValueRef*() {
120 return &m_typed_value;
125 if (SUIsValid(m_typed_value)) {
133 if (SUIsInvalid(m_typed_value) ||
134 get_type() == SUTypedValueType::SUTypedValueType_Empty) {
144 SUTypedValueRef TypedValue::create_typed_value() {
145 SUTypedValueRef typed_value = SU_INVALID;
146 SUResult res = SUTypedValueCreate(&typed_value);
147 assert(res == SU_ERROR_NONE); _unused(res);
152 TypedValue::~TypedValue() {
153 if (SUIsValid(m_typed_value) && !m_attached) {
154 SUResult res = SUTypedValueRelease(&m_typed_value);
155 assert(res == SU_ERROR_NONE); _unused(res);
162 throw std::logic_error(
"CW::TypedValue::get_type(): TypedValue is null");
164 SUTypedValueType type;
165 SUResult res = SUTypedValueGetType(m_typed_value, &type);
166 assert(res == SU_ERROR_NONE); _unused(res);
173 throw std::logic_error(
"CW::TypedValue::byte_value(): TypedValue is null");
175 if (
get_type() != SUTypedValueType_Byte) {
176 throw std::logic_error(
"CW::TypedValue::byte_value(): TypedValue is not SUTypedValueType_Byte type");
179 SUResult res = SUTypedValueGetByte(m_typed_value, &byte_val);
180 assert(res == SU_ERROR_NONE); _unused(res);
187 m_typed_value = create_typed_value();
189 SUResult res = SUTypedValueSetByte(m_typed_value, byte_val);
190 assert(res == SU_ERROR_NONE); _unused(res);
195 TypedValue::operator char()
const {
200 TypedValue::TypedValue(
const char byte_val):
209 throw std::logic_error(
"CW::TypedValue::int16_value(): TypedValue is null");
211 if (
get_type() != SUTypedValueType_Short) {
212 throw std::logic_error(
"CW::TypedValue::int16_value(): TypedValue is not SUTypedValueType_Short (Int16) type");
215 SUResult res = SUTypedValueGetInt16(m_typed_value, &int16_val);
216 assert(res == SU_ERROR_NONE); _unused(res);
223 m_typed_value = create_typed_value();
225 SUResult res = SUTypedValueSetInt16(m_typed_value, int16_val);
226 assert(res == SU_ERROR_NONE); _unused(res);
231 TypedValue::operator int16_t()
const {
237 TypedValue::TypedValue(
const int16_t int16_val):
246 throw std::logic_error(
"CW::TypedValue::int32_value(): TypedValue is null");
248 if (
get_type() != SUTypedValueType_Int32) {
249 throw std::logic_error(
"CW::TypedValue::int32_value(): TypedValue is not SUTypedValueType_Int32 type");
252 SUResult res = SUTypedValueGetInt32(m_typed_value, &int32_val);
253 assert(res == SU_ERROR_NONE); _unused(res);
260 m_typed_value = create_typed_value();
262 SUResult res = SUTypedValueSetInt32(m_typed_value, int32_val);
263 assert(res == SU_ERROR_NONE); _unused(res);
268 TypedValue::operator int32_t()
const {
273 TypedValue::TypedValue(
const int32_t int32_val):
282 throw std::logic_error(
"CW::TypedValue::float_value(): TypedValue is null");
284 if (
get_type() != SUTypedValueType_Float) {
285 throw std::logic_error(
"CW::TypedValue::float_value(): TypedValue is not SUTypedValueType_Float type");
288 SUResult res = SUTypedValueGetFloat(m_typed_value, &float_val);
289 assert(res == SU_ERROR_NONE); _unused(res);
296 m_typed_value = create_typed_value();
298 SUResult res = SUTypedValueSetFloat(m_typed_value, float_val);
299 assert(res == SU_ERROR_NONE); _unused(res);
304 TypedValue::operator float()
const {
309 TypedValue::TypedValue(
const float float_val):
318 throw std::logic_error(
"CW::TypedValue::double_value(): TypedValue is null");
320 if (
get_type() != SUTypedValueType_Double) {
321 throw std::logic_error(
"CW::TypedValue::double_value(): TypedValue is not SUTypedValueType_Double type");
324 SUResult res = SUTypedValueGetDouble(m_typed_value, &double_val);
325 assert(res == SU_ERROR_NONE); _unused(res);
332 m_typed_value = create_typed_value();
334 SUResult res = SUTypedValueSetDouble(m_typed_value, double_val);
335 assert(res == SU_ERROR_NONE); _unused(res);
340 TypedValue::operator double()
const {
345 TypedValue::TypedValue(
const double double_val):
354 throw std::logic_error(
"CW::TypedValue::bool_value(): TypedValue is null");
356 if (
get_type() != SUTypedValueType_Bool) {
357 throw std::logic_error(
"CW::TypedValue::bool_value(): TypedValue is not SUTypedValueType_Bool type");
360 SUResult res = SUTypedValueGetBool(m_typed_value, &bool_val);
361 assert(res == SU_ERROR_NONE); _unused(res);
368 m_typed_value = create_typed_value();
370 SUResult res = SUTypedValueSetBool(m_typed_value, bool_val);
371 assert(res == SU_ERROR_NONE); _unused(res);
376 TypedValue::operator bool()
const {
381 TypedValue::TypedValue(
const bool bool_val):
390 throw std::logic_error(
"CW::TypedValue::color_value(): TypedValue is null");
392 if (
get_type() != SUTypedValueType_Color) {
393 throw std::logic_error(
"CW::TypedValue::color_value(): TypedValue is not SUTypedValueType_Color type");
396 SUResult res = SUTypedValueGetColor(m_typed_value, &color_val);
397 assert(res == SU_ERROR_NONE); _unused(res);
398 return Color(color_val);
404 m_typed_value = create_typed_value();
406 SUColor color = color_val.ref();
407 SUResult res = SUTypedValueSetColor(m_typed_value, &color);
408 assert(res == SU_ERROR_NONE); _unused(res);
413 TypedValue::operator
Color()
const {
418 TypedValue::TypedValue(
const Color &color_val):
427 throw std::logic_error(
"CW::TypedValue::time_value(): TypedValue is null");
429 if (
get_type() != SUTypedValueType_Time) {
430 throw std::logic_error(
"CW::TypedValue::time_value(): TypedValue is not SUTypedValueType_Time type");
433 SUResult res = SUTypedValueGetTime(m_typed_value, &time_val);
434 assert(res == SU_ERROR_NONE); _unused(res);
441 m_typed_value = create_typed_value();
443 SUResult res = SUTypedValueSetTime(m_typed_value, time_val);
444 assert(res == SU_ERROR_NONE); _unused(res);
449 TypedValue::operator int64_t()
const {
454 TypedValue::TypedValue(
const int64_t time_val):
463 throw std::logic_error(
"CW::TypedValue::string_value(): TypedValue is null");
465 if (
get_type() != SUTypedValueType_String) {
466 throw std::logic_error(
"CW::TypedValue::string_value(): TypedValue is not SUTypedValueType_String type");
469 SUStringRef &string_ref = string;
470 SUResult res = SUTypedValueGetString(m_typed_value, &string_ref);
471 assert(res == SU_ERROR_NONE); _unused(res);
478 m_typed_value = create_typed_value();
480 std::string std_string = string_val;
481 SUResult res = SUTypedValueSetString(m_typed_value, std_string.c_str());
482 assert(res == SU_ERROR_NONE); _unused(res);
492 TypedValue::operator
String()
const {
497 TypedValue::operator std::string()
const {
502 TypedValue::TypedValue(
const char chars[]):
507 TypedValue::TypedValue(
const std::string&
string):
512 TypedValue::TypedValue(
const String&
string):
522 throw std::logic_error(
"CW::TypedValue::vector_value(): TypedValue is null");
524 if (
get_type() != SUTypedValueType_Vector3D) {
525 throw std::logic_error(
"CW::TypedValue::vector_value(): TypedValue is not SUTypedValueType_Vector3D type");
527 double vector3d_value[3];
528 SUResult res = SUTypedValueGetVector3d(m_typed_value, &vector3d_value[0]);
529 assert(res == SU_ERROR_NONE); _unused(res);
530 return Vector3D(vector3d_value[0], vector3d_value[1], vector3d_value[2]);
536 m_typed_value = create_typed_value();
538 double vector3d_value[3] = {vector_val.x, vector_val.y, vector_val.z};
539 SUResult res = SUTypedValueSetVector3d(m_typed_value, &vector3d_value[0]);
540 assert(res == SU_ERROR_NONE); _unused(res);
545 TypedValue::operator
Vector3D()
const {
550 TypedValue::TypedValue(
const Vector3D& vector):
559 throw std::logic_error(
"CW::TypedValue::typed_value_array(): TypedValue is null");
561 if (
get_type() != SUTypedValueType_Array) {
562 throw std::logic_error(
"CW::TypedValue::typed_value_array(): TypedValue is not SUTypedValueType_Array type");
565 SUResult res = SUTypedValueGetNumArrayItems(m_typed_value, &count);
566 assert(res == SU_ERROR_NONE);
567 std::vector<SUTypedValueRef> value_refs(count, SU_INVALID);
568 res = SUTypedValueGetArrayItems(m_typed_value, count, value_refs.data(), &count);
569 assert(res == SU_ERROR_NONE); _unused(res);
571 std::vector<TypedValue> temp_vals(count);
572 std::transform(value_refs.begin(), value_refs.end(), temp_vals.begin(),
573 [](
const SUTypedValueRef& value) {
576 std::vector<TypedValue> typed_vals(count);
578 for (
size_t i=0; i < typed_vals.size(); i++) {
579 typed_vals[i] = temp_vals[i];
587 m_typed_value = create_typed_value();
589 SUResult res = SU_ERROR_NONE;
590 std::vector<SUTypedValueRef> refs{typed_val_array.size(), SU_INVALID };
591 std::transform(typed_val_array.begin(), typed_val_array.end(), refs.begin(),
592 [](
const CW::TypedValue& typed_value) {
return typed_value.ref(); });
593 res = SUTypedValueSetArrayItems(m_typed_value, refs.size(), refs.data());
594 assert(res == SU_ERROR_NONE); _unused(res);
599 TypedValue::operator std::vector<TypedValue>()
const {
604 TypedValue::TypedValue(std::vector<TypedValue> &typed_val_array):
613 if (SUIsInvalid(val1.m_typed_value) || SUIsInvalid(val1.m_typed_value)) {
614 if (SUIsInvalid(val1.m_typed_value) && SUIsInvalid(val1.m_typed_value)) {
624 case SUTypedValueType_Array:
630 case SUTypedValueType_Bool:
636 case SUTypedValueType_Byte:
642 case SUTypedValueType_Color:
648 case SUTypedValueType_Double:
654 case SUTypedValueType_Empty:
658 case SUTypedValueType_Float:
664 case SUTypedValueType_Int32:
670 case SUTypedValueType_Short:
672 throw "this part hasn't been made yet.";
674 case SUTypedValueType_String:
681 case SUTypedValueType_Time:
687 case SUTypedValueType_Vector3D:
TypedValue & operator=(const TypedValue &other)
double double_value() const
bool m_attached
Indicates whether the Entity has been attached to a model.
float float_value() const
int64_t time_value() const
bool attached() const
Returns true if the entity is attached to another object.
std::vector< TypedValue > typed_value_array() const
Color color_value() const
int32_t int32_value() const
friend bool operator==(const TypedValue &val1, const TypedValue &val2)
SUTypedValueType get_type() const
Vector3D vector_value() const
String string_value() const
int16_t int16_value() const