24 #ifndef _ODRXVALUE_INCLUDED_
25 #define _ODRXVALUE_INCLUDED_
71 memset(&m_value, 0,
sizeof(m_value));
98 if (
type() != rhs.type())
100 if (!
type().isBlittable())
101 type().nonBlittable()->destruct(valuePtr());
102 if (!isInlined() && rhs.isInlined())
103 deallocate(m_value.m_ptr);
105 #pragma push_macro("new")
108 ::new ((OdRxValueStorage*)
this)
OdRxValue(rhs, !isInlined() && !rhs.isInlined());
110 #pragma pop_macro("new")
114 bool blittable = rhs.type().isBlittable();
115 bool inlined = rhs.isInlined();
116 if (blittable && inlined)
127 type().nonBlittable()->assign(inlineValuePtr(), rhs.inlineValuePtr());
129 setNonInlineValue(rhs.nonInlineValuePtr(), blittable,
true,
true);
136 if (!
type().isBlittable())
137 type().nonBlittable()->destruct(valuePtr());
140 deallocate(m_value.m_ptr);
154 bool isEmpty()
const throw() {
return *
this == empty(); }
164 bool isVaries() const throw() {
return *
this == varies(); }
176 return m_type.toString(valuePtr(),
format);
186 return type().equalTo(valuePtr(),
value.valuePtr());
204 return m_type.typePath(*
this);
210 template <
typename ValueType>
216 initBlittable<sizeof(ValueType) <= 24>(&
value,
sizeof(ValueType));
222 template<
typename ValueType>
231 template<
typename ValueType>
236 value->type().isEnum() &&
243 template<
typename ValueType>
253 template<
typename ValueType>
262 template<
typename ValueType>
286 size_t serializeOut(
void* pBytes,
size_t& maxBytesToWrite) const;
291 size_t serializeIn(const
void* pBytes,
size_t maxBytesToRead);
295 template<typename ValueType>
296 void operator << (const ValueType &val)
305 template<
typename ValueType>
310 const ValueType *pVal = rxvalue_cast<ValueType>(
this);
323 const ValueType *pVal = rxvalue_cast<ValueType>(&subVal);
336 #pragma region private
339 bool isInlined()
const
341 return type().size() <=
sizeof(m_value);
343 const void* nonInlineValuePtr()
const {
return m_value.m_ptr; }
344 void* nonInlineValuePtr() {
return m_value.m_ptr; }
345 const void* inlineValuePtr()
const {
return &m_value; }
346 void* inlineValuePtr() {
return &m_value; }
347 const void* valuePtr()
const
350 return inlineValuePtr();
352 return nonInlineValuePtr();
354 template <
bool Inlined>
356 template <
bool Inlined>
357 void initBlittable(
const void*
value,
size_t size);
359 template<
typename T,
bool inlined>
360 class InitNonBlittable
366 class InitNonBlittable<T,
true>
372 class InitNonBlittable<T,
false>
378 template <
typename T>
379 void initNonBlittable(
const T&
value)
381 InitNonBlittable<T,
sizeof(
value) <=
sizeof(m_value) >::init(*
this,
value);
384 void init(
const OdRxValue& rhs,
bool realloc)
386 bool blittable =
type().isBlittable();
387 bool inlined = isInlined();
388 if (blittable && inlined)
390 memcpy(&m_value, &rhs.m_value,
sizeof(m_value));
399 type().nonBlittable()->construct(inlineValuePtr(), rhs.inlineValuePtr());
401 setNonInlineValue(rhs.nonInlineValuePtr(), blittable,
false, realloc);
403 void setNonInlineValue(
const void*
value,
bool blittable,
bool assignment,
bool realloc)
407 unsigned int newSize =
type().size();
408 realloc = realloc || assignment;
411 size_t oldsize = *(((
size_t*)m_value.m_ptr) - 1);
412 if (oldsize != newSize)
414 m_value.m_ptr = reallocate(newSize, m_value.m_ptr);
419 m_value.m_ptr = allocate(newSize);
422 memcpy(nonInlineValuePtr(),
value, newSize);
424 type().nonBlittable()->assign(nonInlineValuePtr(),
value);
426 type().nonBlittable()->construct(nonInlineValuePtr(),
value);
434 #if (OD_SIZEOF_PTR == 4)
448 void* allocate(
size_t size)
const;
449 void* reallocate(
size_t size,
void* p)
const;
450 void deallocate(
void* p)
const;
453 #pragma endregion private
476 inline void* OdRxValue::valuePtr__<true>()
479 return inlineValuePtr();
486 inline void* OdRxValue::valuePtr__<false>()
489 return nonInlineValuePtr();
496 inline void OdRxValue::initBlittable<true>(
const void*
value,
size_t size)
503 inline void OdRxValue::initBlittable<false>(
const void*
value,
size_t size)
507 m_value.m_ptr = allocate(
size);
508 memcpy(nonInlineValuePtr(),
value,
size);
515 inline void OdRxValue::InitNonBlittable< T, true>::init(
OdRxValue& rxValue,
const T&
value)
518 ::new ((OdRxValueStorage*)(rxValue.inlineValuePtr())) T(
value);
527 rxValue.setNonInlineValue(&
value,
false,
false,
false);
610 #define ODRX_DECLARE_VALUE_TYPE(type, attribute)\
611 template<> struct OdRxValueType::Desc<type>\
613 attribute static const OdRxValueType& value() throw();\
614 attribute static void del();\
616 template<> OdRxValue::OdRxValue(const type&) throw();
841 #include "TD_PackPop.h"
842 #endif // _ODRXVALUE_INCLUDED_