2#ifndef _VRAY_INTEROP_HPP_
3#define _VRAY_INTEROP_HPP_
11 struct CharStringBuf {
12 static CharStringBuf* create(
int size) {
13 return static_cast<CharStringBuf*
>(Internal::CharStringBuf_create(size));
16 CharStringBuf* incRefCount() {
17 Internal::CharStringBuf_incRefCount(
this);
22 return Internal::CharStringBuf_decRefCount(
this);
26 return Internal::CharStringBuf_getRefCount(
this);
30 return Internal::CharStringBuf_resize(
this, s);
34 return Internal::CharStringBuf_getBuf(
this);
47 inline int vutils_strcpy_n(
char *dest,
const char *source,
int destSize) {
48 if (destSize <= 0)
return 0;
50 for (len = 0; (len<destSize - 1) && (source[len] !=
'\0'); len++) {
51 dest[len] = source[len];
62 inline int vutils_strlen_n(
const char *str,
int maxSize) {
64 while (len<maxSize && str[len] !=
'\0') len++;
73 inline int vutils_strcat_n(
char *dest,
const char *source,
int destSize) {
74 int len = vutils_strlen_n(dest, destSize);
75 return vutils_strcpy_n(dest + len, source, destSize - len);
84 inline int vutils_strcmp(
const char *strA,
const char *strB) {
87 while ((*a) !=
'\0' && (*a) == (*b)) { a++; b++; }
98 inline int vutils_strcmp_n(
const char *strA,
const char *strB,
int maxSize) {
100 const char *b = strB;
102 while ((*a) !=
'\0' && (*a) == (*b) && (n < maxSize)) { a++; b++; n++; }
112 if (buf) buf->decRefCount();
117 void splitBuffer(
int len,
int copyString) {
118 if (!buf) buf = CharStringBuf::create(len + 1);
119 else if (buf->getRefCount()>1) {
120 CharStringBuf *tmpBuf = CharStringBuf::create(len + 1);
122 vutils_strcpy_n(tmpBuf->ptr(), buf->ptr(), len + 1);
127 buf->resize(len + 1);
132 void setBuffer(CharStringBuf *newBuffer) {
134 if (newBuffer != buf) {
135 if (buf) buf->decRefCount();
136 if (!newBuffer) buf =
nullptr;
137 else buf = newBuffer->incRefCount();
142 void makeWriteable(
void) {
144 if (buf->getRefCount() <= 1)
return;
147 int len = length() + 1;
148 CharStringBuf *newBuffer = CharStringBuf::create(len + 1);
149 vutils_strcpy_n(newBuffer->ptr(), buf->ptr(), len + 1);
156 CharString(
void) :buf(nullptr) {}
159 CharString(
const char *val) :buf(nullptr) {
161 int len = (int)strlen(val);
162 buf = CharStringBuf::create(len + 1);
163 char* wptr = buf->ptr();
164 if (wptr) vutils_strcpy_n(wptr, val, len + 1);
169 CharString(
const CharString& r) :buf(nullptr) {
170 if (r.buf) buf = r.buf->incRefCount();
176 CharString(
const char *str,
int strLen) :buf(nullptr) {
181 CharString(
unsigned strLen) :buf(nullptr) {
184 buf = CharStringBuf::create(strLen + 1);
185 char* wptr = buf->ptr();
187 memset(wptr,
' ',
sizeof(
char)*(strLen + 1));
194 ~CharString(
void) { freeMem(); }
197 const char* ptr(
void)
const {
198 return buf ? buf->ptr() :
nullptr;
202 char* write_ptr(
void) {
203 if (!buf)
return nullptr;
209 CharString& operator=(
const char *newBuf) {
210 if (!newBuf) { freeMem();
return *
this; }
212 int len = (int)strlen(newBuf);
213 splitBuffer(len,
false);
214 char* wptr = buf->ptr();
215 if (wptr) vutils_strcpy_n(wptr, newBuf, len + 1);
220 CharString& operator=(
const CharString& str) {
226 void set(
const char* str,
int strLen) {
227 if (!str || strLen == 0) { freeMem();
return; }
229 splitBuffer(strLen,
false);
230 char* wptr = buf->ptr();
231 if (wptr) vutils_strcpy_n(wptr, str, strLen + 1);
235 void set(
const char* str) { *
this = str; }
238 void set(
const char* str1,
const char* str2) {
239 int sz1 = (int)((str1) ? strlen(str1) : 0);
240 int sz2 = (int)((str2) ? strlen(str2) : 0);
241 if (!str1 || !str2 || !sz1 || !sz2) { freeMem();
return; }
243 splitBuffer(sz1 + sz2,
false);
244 char* wptr = buf->ptr();
246 vutils_strcpy_n(wptr, str1, sz1 + sz2 + 1);
247 vutils_strcpy_n(wptr + sz1, str2, sz1 + sz2 + 1);
252 char operator[](
int index)
const {
return buf->ptr()[index]; }
255 int length(
void)
const {
return buf ? (int)strlen(buf->ptr()) : 0; }
260 void setLength(
int newLen,
char fillChar =
' ') {
261 if (newLen <= 0) { freeMem();
return; }
264 if (newLen == len)
return;
266 splitBuffer(newLen,
true);
267 char* wptr = buf->ptr();
269 if (newLen > len && fillChar != 0)
270 for (
int i = len; i < newLen; i++)
277 void append(
const char *str) {
279 if (!buf) *
this = str;
281 int strLen = (int)strlen(str);
282 int curLen = length();
283 splitBuffer(strLen + curLen,
true);
284 char* wptr = buf->ptr();
285 if (wptr) vutils_strcat_n(wptr, str, curLen + strLen + 1);
290 void append(
const CharString &str) {
295 void append(
const char *str,
int length) {
297 if (!buf) set(str, length);
299 int curLen = this->length();
300 splitBuffer(length + curLen,
true);
301 char* wptr = buf->ptr();
302 if (wptr) vutils_strcat_n(wptr, str, curLen + length + 1);
307 void swap(CharString &str)
noexcept {
308 CharStringBuf *temp = buf;
314 void clear(
void) { freeMem(); }
317 bool empty(
void)
const {
return (buf ==
nullptr) || (buf->ptr()[0] == 0); }
320 inline std::ostream& operator <<(std::ostream& stream,
const CharString& str) {
321 const char* ptr = str.ptr();
322 stream << (ptr ? ptr :
"<null string>");
328 inline CharString operator+(
const CharString &a,
const CharString &b) {
336 inline bool operator==(
const CharString &a,
const char *str) {
337 const char* ptr = a.ptr();
338 if (ptr == str)
return true;
339 if (ptr ==
nullptr || str ==
nullptr)
return false;
340 return strcmp(ptr, str) == 0;
345 inline bool operator!=(
const CharString &a,
const char *str) {
351 inline bool operator==(
const CharString &a,
const CharString &b) {
357 inline bool operator!=(
const CharString &a,
const CharString &b) {
363 inline bool operator<(
const CharString &a,
const CharString &b) {
364 const char* aptr = a.ptr();
365 const char* bptr = b.ptr();
366 if (bptr ==
nullptr)
return false;
367 if (aptr ==
nullptr)
return true;
368 return strcmp(aptr, bptr) < 0;
371 inline CharString makeCharString(
const char *a,
const char *b) {
377 inline CharString makeCharString(
const char *a,
const char *b,
const char *c) {
384 inline CharString makeCharString(
const char *a,
const char *b,
const char *c,
const char *d) {
394 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr);
397 T* allocMem(
int type,
int n);
398 void destroy(
int type, T* ptr,
int n);
399 static int unite(Type dataType,
int counterType) {
400 return dataType | (counterType << 16);
408 template<
class T>
struct PtrArray;
410 typedef PtrArray<int> IntRefList;
411 typedef PtrArray<float> FloatRefList;
412 typedef PtrArray<Vector> VectorRefList;
413 typedef PtrArray<Color> ColorRefList;
414 typedef PtrArray<TraceTransform> TransformRefList;
415 typedef PtrArray<CharString> CharStringRefList;
416 typedef PtrArray<Value> ValueRefList;
424 explicit ObjectID(InstanceId
id = 0)
428 explicit ObjectID(
const Plugin& plugin)
429 : id(plugin.getIntegerID())
432 explicit ObjectID(
const PluginRef& plugin)
433 : id(plugin.getIntegerID())
434 , subobj(plugin.getOutputName())
437 bool operator==(
const ObjectID &objID) {
438 return id == objID.id && subobj == objID.subobj;
440 bool operator!=(
const ObjectID &objID) {
441 return id != objID.id || subobj != objID.subobj;
445 struct RuntimeValue {
447 CharString valueName;
449 RuntimeValue() : obj() {}
450 RuntimeValue(
const RuntimeValue& rv) =
default;
451 RuntimeValue(RuntimeValue&& rv) =
default;
453 bool operator==(
const RuntimeValue& rv) {
454 return obj == rv.obj && valueName == rv.valueName;
456 bool operator!=(
const RuntimeValue& rv) {
457 return obj != rv.obj || valueName != rv.valueName;
465 TracePoint(
double x,
double y,
double z) : x(x), y(y), z(z) {}
466 explicit TracePoint(
double v) : x(v), y(v), z(v) {}
467 TracePoint(
const Vector &v) : x(v.x), y(v.y), z(v.z) {}
468 TracePoint(
const TracePoint& tp) =
default;
470 Vector toVector()
const {
return Vector(x, y, z); }
472 bool operator==(
const TracePoint& tp) {
473 return x != tp.x && y == tp.y && z == tp.z;
475 bool operator!=(
const TracePoint& tp) {
476 return x != tp.x || y != tp.y || z != tp.z;
478 std::string toString()
const;
481 inline std::ostream& operator <<(std::ostream& stream,
const TracePoint& vector) {
482 stream <<
"Vector(" << vector.x <<
", " << vector.y <<
", " << vector.z <<
")";
486 inline std::string TracePoint::toString()
const {
487 std::ostringstream stream;
492 struct TraceTransform {
498 explicit TraceTransform(
float f) : m(f), offs(0) {}
499 TraceTransform(
const Transform& t) : m(t.matrix), offs(t.offset) {}
500 TraceTransform(
const TraceTransform& tt) =
default;
502 Transform toTransform()
const {
return Transform(m, offs.toVector()); }
504 bool operator==(
const TraceTransform& tt) {
505 return m == tt.m && offs == tt.offs;
507 bool operator!=(
const TraceTransform& tt) {
508 return m != tt.m || offs != tt.offs;
510 std::string toString()
const;
513 inline std::ostream& operator <<(std::ostream& stream,
const TraceTransform& transform) {
514 stream <<
"Transform(" << transform.m <<
", " << transform.offs <<
")";
518 inline std::string TraceTransform::toString()
const {
519 std::ostringstream stream;
547 struct RefCounter<int> {
548 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr) {
549 return static_cast<RefCounter*
>(Internal::RefCounter_create(RefCounter<void>::unite(TYPE_INT, type), callbackFn, callbackData));
553 Internal::RefCounter_increment(
this, RefCounter<void>::unite(TYPE_INT, type));
557 return Internal::RefCounter_decrement(
this, RefCounter<void>::unite(TYPE_INT, type));
560 int* allocMem(
int type,
int n) {
561 return static_cast<int*
>(Internal::RefCounter_allocMem(
this, RefCounter<void>::unite(TYPE_INT, type), n));
564 void destroy(
int type,
int* ptr,
int n) {
565 Internal::RefCounter_release(
this, RefCounter<void>::unite(TYPE_INT, type), ptr, n);
570 struct RefCounter<float> {
571 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr) {
572 return static_cast<RefCounter*
>(Internal::RefCounter_create(RefCounter<void>::unite(TYPE_FLOAT, type), callbackFn, callbackData));
576 Internal::RefCounter_increment(
this, RefCounter<void>::unite(TYPE_FLOAT, type));
580 return Internal::RefCounter_decrement(
this, RefCounter<void>::unite(TYPE_FLOAT, type));
583 float* allocMem(
int type,
int n) {
584 return static_cast<float*
>(Internal::RefCounter_allocMem(
this, RefCounter<void>::unite(TYPE_FLOAT, type), n));
587 void destroy(
int type,
float* ptr,
int n) {
588 Internal::RefCounter_release(
this, RefCounter<void>::unite(TYPE_FLOAT, type), ptr, n);
593 struct RefCounter<Vector> {
594 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr) {
595 return static_cast<RefCounter*
>(Internal::RefCounter_create(RefCounter<void>::unite(TYPE_VECTOR, type), callbackFn, callbackData));
599 Internal::RefCounter_increment(
this, RefCounter<void>::unite(TYPE_VECTOR, type));
603 return Internal::RefCounter_decrement(
this, RefCounter<void>::unite(TYPE_VECTOR, type));
606 Vector* allocMem(
int type,
int n) {
607 return static_cast<Vector*
>(Internal::RefCounter_allocMem(
this, RefCounter<void>::unite(TYPE_VECTOR, type), n));
610 void destroy(
int type, Vector* ptr,
int n) {
611 Internal::RefCounter_release(
this, RefCounter<void>::unite(TYPE_VECTOR, type), ptr, n);
616 struct RefCounter<Color> {
617 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr) {
618 return static_cast<RefCounter*
>(Internal::RefCounter_create(RefCounter<void>::unite(TYPE_COLOR, type), callbackFn, callbackData));
622 Internal::RefCounter_increment(
this, RefCounter<void>::unite(TYPE_COLOR, type));
626 return Internal::RefCounter_decrement(
this, RefCounter<void>::unite(TYPE_COLOR, type));
629 Color* allocMem(
int type,
int n) {
630 return static_cast<Color*
>(Internal::RefCounter_allocMem(
this, RefCounter<void>::unite(TYPE_COLOR, type), n));
633 void destroy(
int type, Color* ptr,
int n) {
634 Internal::RefCounter_release(
this, RefCounter<void>::unite(TYPE_COLOR, type), ptr, n);
639 struct RefCounter<TraceTransform> {
640 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr) {
641 return static_cast<RefCounter*
>(Internal::RefCounter_create(RefCounter<void>::unite(TYPE_TRANSFORM, type), callbackFn, callbackData));
645 Internal::RefCounter_increment(
this, RefCounter<void>::unite(TYPE_TRANSFORM, type));
649 return Internal::RefCounter_decrement(
this, RefCounter<void>::unite(TYPE_TRANSFORM, type));
652 TraceTransform* allocMem(
int type,
int n) {
653 return static_cast<TraceTransform*
>(Internal::RefCounter_allocMem(
this, RefCounter<void>::unite(TYPE_TRANSFORM, type), n));
656 void destroy(
int type, TraceTransform* ptr,
int n) {
657 Internal::RefCounter_release(
this, RefCounter<void>::unite(TYPE_TRANSFORM, type), ptr, n);
662 struct RefCounter<CharString> {
663 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr) {
664 return static_cast<RefCounter*
>(Internal::RefCounter_create(RefCounter<void>::unite(TYPE_STRING, type), callbackFn, callbackData));
668 Internal::RefCounter_increment(
this, RefCounter<void>::unite(TYPE_STRING, type));
672 return Internal::RefCounter_decrement(
this, RefCounter<void>::unite(TYPE_STRING, type));
675 CharString* allocMem(
int type,
int n) {
676 return static_cast<CharString*
>(Internal::RefCounter_allocMem(
this, RefCounter<void>::unite(TYPE_STRING, type), n));
679 void destroy(
int type, CharString* ptr,
int n) {
680 Internal::RefCounter_release(
this, RefCounter<void>::unite(TYPE_STRING, type), ptr, n);
685 struct RefCounter<Value> {
686 static RefCounter* create(
int type, Internal::PtrArrayCustomCallbackFn callbackFn =
nullptr,
void* callbackData =
nullptr) {
687 return static_cast<RefCounter*
>(Internal::RefCounter_create(RefCounter<void>::unite(TYPE_LIST, type), callbackFn, callbackData));
691 Internal::RefCounter_increment(
this, RefCounter<void>::unite(TYPE_LIST, type));
695 return Internal::RefCounter_decrement(
this, RefCounter<void>::unite(TYPE_LIST, type));
698 Value* allocMem(
int type,
int n) {
699 return static_cast<Value*
>(Internal::RefCounter_allocMem(
this, RefCounter<void>::unite(TYPE_LIST, type), n));
702 void destroy(
int type, Value* ptr,
int n) {
703 Internal::RefCounter_release(
this, RefCounter<void>::unite(TYPE_LIST, type), ptr, n);
711 PtrArray(
void) { ptr =
nullptr; refCounter =
nullptr; length = 0; }
714 PtrArray(
const PtrArray &p) { copy(p); }
717 PtrArray(PtrArray &&p)
noexcept { m0ve(std::move(p)); }
720 PtrArray& operator=(
const PtrArray &p) {
729 PtrArray& operator=(PtrArray &&p)
noexcept {
738 bool operator==(
const PtrArray&& p) {
739 if (ptr == p.ptr)
return true;
740 if (!ptr || !p.ptr)
return false;
741 for (
int i = 0; i < length; ++i) {
742 if (ptr[i] != p.ptr[i])
return false;
748 explicit PtrArray(
int num) { allocArray(num); }
753 PtrArray(T *ptr,
int len) { init(ptr, len); }
758 explicit PtrArray(T (&arr)[len]) { init(arr, len); }
761 ~PtrArray(
void) { freeMem(); }
764 T& operator[](
int i) {
return ptr[i]; }
767 const T& operator[](
int i)
const {
return ptr[i]; }
770 bool operator!(
void)
const {
return (ptr ==
nullptr); }
773 operator T*(void) {
return ptr; }
776 operator const T*(void)
const {
return ptr; }
782 void init(T *ptr,
int len) {
783 type = Internal::ownerTypeNone;
785 refCounter =
nullptr;
792 if (refCounter->dec(type) == 0) {
793 refCounter->destroy(type, ptr, length);
796 refCounter =
nullptr;
799 type = Internal::ownerTypeNone;
803 T* get(
void) {
return ptr; }
804 const T* get(
void)
const {
return ptr; }
807 int size(
void)
const {
return length; }
808 int count(
void)
const {
return length; }
810 std::string toString()
const;
814 RefCounter<T> *refCounter;
817 Internal::PtrArrayOwnershipType type;
825 PtrArray(T *ptr,
int len, Internal::PtrArrayCustomCallbackFn callbackFn,
void* callbackData) { init(ptr, len, callbackFn, callbackData); }
833 void init(T *ptr,
int len, Internal::PtrArrayCustomCallbackFn callbackFn,
void* callbackData) {
834 type = Internal::ownerTypeCallback;
836 refCounter = RefCounter<T>::create(type, callbackFn, callbackData);
840 void copy(
const PtrArray &p) {
842 refCounter = p.refCounter;
845 if (refCounter) refCounter->inc(type);
848 void m0ve(PtrArray&& p) {
850 refCounter = p.refCounter;
855 p.refCounter =
nullptr;
857 p.type = Internal::ownerTypeNone;
860 void allocArray(
int num) {
861 type = Internal::ownerTypeOwnMem;
863 refCounter = RefCounter<T>::create(type);
864 ptr = refCounter->allocMem(type, length);
869 inline std::ostream& operator <<(std::ostream& stream,
const PtrArray<T>& list) {
871 if (list && list.count() > 0) {
873 while (i < list.count() - 1)
874 stream << list[i++] <<
", ";
882 inline std::string PtrArray<T>::toString()
const {
883 std::ostringstream stream;
891 CharString scenePath;
892 CharStringRefList stringList;
896 VALUE_TYPE valueType;
898 template<
typename TYPE> TYPE& as() {
return *
reinterpret_cast<TYPE *
>(data); }
899 template<
typename TYPE>
const TYPE& as()
const {
return *
reinterpret_cast<const TYPE *
>(data); }
902 void copy(
const Value &other)
907 switch (other.valueType) {
909 setDouble(other.getDouble());
912 setVector(other.getTracePoint());
915 setMatrix(other.getMatrix());
918 setColor(other.getColor());
921 setAColor(other.getAColor());
924 setTransform(other.getTransform());
927 setObject(other.getObject());
930 setObjectID(other.getObjectID());
933 setList(other.getList());
936 setListInt(other.getListInt());
939 setListFloat(other.getListFloat());
942 setListVector(other.getListVector());
945 setListColor(other.getListColor());
948 setListString(other.getListString());
953 setString(other.getString());
957 setRuntimeValue(other.getRuntimeValue());
979 as<ObjectID>().~ObjectID();
982 as<ValueRefList>().~PtrArray();
985 as<IntRefList>().~PtrArray();
988 as<FloatRefList>().~PtrArray();
991 as<VectorRefList>().~PtrArray();
994 as<ColorRefList>().~PtrArray();
997 as<StringValue>().stringList.~PtrArray();
998 as<StringValue>().scenePath.~CharString();
1002 as<StringValue>().str.~CharString();
1003 as<StringValue>().scenePath.~CharString();
1006 as<RuntimeValue>().~RuntimeValue();
1013 valueType = UNKNOWN;
1016 explicit Value(
double val) {
1018 new (data)
double(val);
1021 explicit Value(
const TracePoint &v) {
1023 new (data) TracePoint(v);
1026 explicit Value(
const Vector &v) {
1028 new (data) TracePoint(v);
1031 explicit Value(
const Matrix &mat) {
1033 new (data) Matrix(mat);
1036 explicit Value(
const Color &col) {
1038 new (data) Color(col);
1041 explicit Value(
const AColor &acol) {
1043 new (data) AColor(acol);
1046 explicit Value(
const TraceTransform &transform) {
1047 valueType = TRANSFORM;
1048 new (data) TraceTransform(transform);
1051 explicit Value(Object *obj) {
1053 new (data) Object*(obj);
1056 explicit Value(
const ObjectID &
id) {
1057 valueType = OBJECTID;
1058 new (data) ObjectID(
id);
1061 explicit Value(
const ValueRefList &lst) {
1063 new (data) ValueRefList(lst);
1066 explicit Value(
const RuntimeValue &rtVal) {
1067 valueType = RUNTIMEVALUE;
1068 new (data) RuntimeValue(rtVal);
1071 explicit Value(
const CharString &str) {
1073 new (&(as<StringValue>().str)) CharString(str);
1074 new (&(as<StringValue>().scenePath)) CharString();
1083 explicit Value(
const VectorRefList &list) {
1084 valueType = LISTVECTOR;
1085 new (data) VectorRefList(list);
1088 explicit Value(
const ColorRefList &list) {
1089 valueType = LISTCOLOR;
1090 new (data) ColorRefList(list);
1093 explicit Value(
const FloatRefList &list) {
1094 valueType = LISTFLOAT;
1095 new (data) FloatRefList(list);
1098 explicit Value(
const IntRefList &list) {
1099 valueType = LISTINT;
1100 new (data) IntRefList(list);
1103 explicit Value(
const CharStringRefList &list) {
1104 valueType = LISTSTRING;
1105 new (&(as<StringValue>().stringList)) CharStringRefList(list);
1106 new (&(as<StringValue>().scenePath)) CharString();
1109 explicit Value(
const Plugin &plugin) {
1110 valueType = OBJECTID;
1111 new (data) ObjectID(plugin);
1114 explicit Value(
const PluginRef& plugin) {
1115 valueType = OBJECTID;
1116 new (data) ObjectID(plugin);
1119 Value(
const Value &v) {
1120 valueType = UNKNOWN;
1124 Value &operator=(
const Value &v) {
1129 bool operator==(
const Value &v) {
1130 if (valueType != v.valueType)
return false;
1131 switch (valueType) {
1133 return as<double>() == v.as<
double>();
1135 return as<TracePoint>() == v.as<TracePoint>();
1137 return as<Matrix>() == v.as<Matrix>();
1139 return as<Color>() == v.as<Color>();
1141 return as<AColor>() == v.as<AColor>();
1143 return as<TraceTransform>() == v.as<TraceTransform>();
1145 return as<Object*>() == v.as<Object*>();
1147 return as<ObjectID>() == v.as<ObjectID>();
1149 return as<ValueRefList>() == v.as<ValueRefList>();
1151 return as<IntRefList>() == v.as<IntRefList>();
1153 return as<FloatRefList>() == v.as<FloatRefList>();
1155 return as<VectorRefList>() == v.as<VectorRefList>();
1157 return as<ColorRefList>() == v.as<ColorRefList>();
1159 return as<StringValue>().stringList == v.as<StringValue>().stringList;
1161 return as<StringValue>().str == v.as<StringValue>().str;
1163 return as<RuntimeValue>() == v.as<RuntimeValue>();
1169 bool operator!=(
const Value& v) {
1170 return !operator==(v);
1179 VALUE_TYPE getValueType()
const {
1184 void setRuntimeValue(
const RuntimeValue &rtVal) {
1186 valueType = RUNTIMEVALUE;
1187 new (data) RuntimeValue(rtVal);
1190 RuntimeValue getRuntimeValue()
const {
1191 if (valueType == RUNTIMEVALUE) {
1192 return as<RuntimeValue>();
1195 return RuntimeValue();
1198 void setDouble(
double val) {
1201 new (data)
double(val);
1204 double getDouble()
const {
1205 if (valueType == NUMBER) {
1206 return as<double>();
1212 void setList(
const ValueRefList &list) {
1215 new (data) ValueRefList(list);
1218 ValueRefList getList()
const {
1219 if (valueType == LIST) {
1220 return as<ValueRefList>();
1223 return ValueRefList();
1226 void setListVector(
const VectorRefList &list) {
1228 valueType = LISTVECTOR;
1229 new (data) VectorRefList(list);
1232 VectorRefList getListVector()
const {
1233 if (valueType == LISTVECTOR) {
1234 return as<VectorRefList>();
1237 return VectorRefList();
1240 void setListInt(
const IntRefList &list) {
1242 valueType = LISTINT;
1243 new (data) IntRefList(list);
1246 IntRefList getListInt()
const {
1247 if (valueType == LISTINT) {
1248 return as<IntRefList>();
1251 return IntRefList();
1254 void setListColor(
const ColorRefList &list) {
1256 valueType = LISTCOLOR;
1257 new (data) ColorRefList(list);
1260 ColorRefList getListColor()
const {
1261 if (valueType == LISTCOLOR) {
1262 return as<ColorRefList>();
1265 return ColorRefList();
1268 void setListFloat(
const FloatRefList &list) {
1270 valueType = LISTFLOAT;
1271 new (data) FloatRefList(list);
1274 FloatRefList getListFloat()
const {
1275 if (valueType == LISTFLOAT) {
1276 return as<FloatRefList>();
1279 return FloatRefList();
1282 void setListString(
const CharStringRefList &list) {
1284 valueType = LISTSTRING;
1285 new (&(as<StringValue>().stringList)) CharStringRefList(list);
1286 new (&(as<StringValue>().scenePath)) CharString();
1289 CharStringRefList getListString()
const {
1290 if (valueType == LISTSTRING) {
1291 return as<StringValue>().stringList;
1294 return CharStringRefList();
1297 void setObject(Object *obj) {
1300 new (data) Object*(obj);
1303 Object* getObject()
const {
1304 if (valueType == OBJECT) {
1305 return as<Object*>();
1312 void setObjectID(
const ObjectID &
id) {
1314 valueType = OBJECTID;
1315 new (data) ObjectID(
id);
1318 ObjectID getObjectID()
const {
1319 if (valueType == OBJECTID) {
1320 return as<ObjectID>();
1326 Vector getVector()
const {
1327 if (valueType == VECTOR) {
1328 const TracePoint &pt = as<TracePoint>();
1329 return Vector(pt.x, pt.y, pt.z);
1332 return Vector(0.0f);
1335 void setVector(
const TracePoint &v) {
1338 new (data) TracePoint(v);
1341 void setVector(
const Vector &v) {
1344 new (data) TracePoint(v);
1347 TracePoint getTracePoint()
const {
1348 if (valueType == VECTOR) {
1349 return as<TracePoint>();
1352 return TracePoint(0.0f);
1355 void setTracePoint(
const TracePoint &v) {
1358 new (data) TracePoint(v);
1361 Matrix getMatrix()
const {
1362 if (valueType == MATRIX || valueType == TRANSFORM) {
1363 return as<Matrix>();
1369 void setMatrix(
const Matrix &v) {
1372 new (data) Matrix(v);
1375 Color getColor()
const {
1376 if (valueType == COLOR) {
1383 void setColor(
const Color &v) {
1386 new (data) Color(v);
1389 AColor getAColor()
const {
1390 if (valueType == ACOLOR) {
1391 return as<AColor>();
1392 }
else if (valueType == COLOR) {
1393 return AColor(as<Color>());
1396 return AColor(0.0f);
1399 void setAColor(
const AColor &v) {
1402 new (data) AColor(v);
1405 void setString(
const CharString &str) {
1408 new (&(as<StringValue>().str)) CharString(str);
1409 new (&(as<StringValue>().scenePath)) CharString();
1412 CharString getString()
const {
1413 if (valueType == STRING) {
1414 return as<StringValue>().str;
1417 return CharString();
1420 void setTransform(
const TraceTransform &tr) {
1422 valueType = TRANSFORM;
1423 new (data) TraceTransform(tr);
1426 TraceTransform getTransform()
const {
1427 if (valueType == TRANSFORM) {
1428 return as<TraceTransform>();
1429 }
else if (valueType == MATRIX) {
1432 t.offs = TracePoint(0.0);
1436 return TraceTransform(0);
1441 const PluginRef getPlugin(VRayRenderer& renderer)
const {
1442 struct PluginRefWrap :
public PluginRef {
1443 PluginRefWrap(VRayRenderer& renderer, InstanceId
id,
const char* output)
1444 : PluginRef(renderer, id, output) { }
1446 if (valueType == OBJECTID) {
1447 ObjectID objId = as<ObjectID>();
1448 return PluginRefWrap(renderer, objId.id, objId.subobj.ptr());
1450 return PluginRefWrap(renderer, 0,
nullptr);
1453 void setPlugin(
const PluginRef& plugin) {
1455 valueType = OBJECTID;
1456 new (data) ObjectID(plugin);
1460 inline std::ostream& operator <<(std::ostream& stream,
const Value& value) {
1461 switch (value.getValueType()) {
1463 stream << value.getDouble();
1466 stream << value.getVector();
1469 stream << value.getMatrix();
1472 stream << value.getColor();
1475 stream << value.getAColor();
1478 stream << value.getTransform().toTransform();
1481 stream <<
"<Scene Parser Object>";
1484 const ObjectID& objId = value.getObjectID();
1485 stream <<
"ObjectID<" << value.getObjectID().id;
1486 if (!objId.subobj.empty())
1487 stream <<
", " << objId.subobj.ptr();
1491 stream << value.getList();
1494 stream << value.getListInt();
1497 stream << value.getListFloat();
1500 stream << value.getListVector();
1503 stream << value.getListColor();
1506 stream << value.getListString();
1509 stream << value.getString();
1512 stream <<
"<Scene Parser Runtime Value>";
1515 stream <<
"<Unknown Value>";
1529# ifndef VRAY_SDK_INTEROPERABILITY
1530# define VRAY_SDK_INTEROPERABILITY
1532# include "vraysdk.hpp"