24#ifndef _ODRXVALUE_INCLUDED_
25#define _ODRXVALUE_INCLUDED_
96 memset(&m_value, 0,
sizeof(m_value));
133 if (
type() != rhs.type())
135 if (!
type().isBlittable())
136 type().nonBlittable()->destruct(valuePtr());
137 if (!isInlined() && rhs.isInlined())
138 deallocate(m_value.m_ptr);
140#pragma push_macro("new")
143 ::new ((OdRxValueStorage*)
this)
OdRxValue(rhs, !isInlined() && !rhs.isInlined());
145#pragma pop_macro("new")
149 bool blittable = rhs.type().isBlittable();
150 bool inlined = rhs.isInlined();
151 if (blittable && inlined)
162 type().nonBlittable()->assign(inlineValuePtr(), rhs.inlineValuePtr());
164 setNonInlineValue(rhs.nonInlineValuePtr(), blittable,
true,
true);
174 if (!
type().isBlittable())
175 type().nonBlittable()->destruct(valuePtr());
178 deallocate(m_value.m_ptr);
198 bool isEmpty()
const throw() {
return *
this == empty(); }
215 bool isVaries() const throw() {
return *
this == varies(); }
238 return m_type.toString(valuePtr(),
format);
253 return type().equalTo(valuePtr(),
value.valuePtr());
279 return m_type.typePath(*
this);
288 template <
typename ValueType>
294 initBlittable<sizeof(ValueType) <= 24>(&
value,
sizeof(ValueType));
306 template<
typename ValueType>
321 template<
typename ValueType>
326 value->type().isEnum() &&
338 template<
typename ValueType>
354 template<
typename ValueType>
369 template<
typename ValueType>
413 size_t serializeOut(
void* pBytes,
size_t& maxBytesToWrite) const;
424 size_t serializeIn(const
void* pBytes,
size_t maxBytesToRead);
432 template<typename ValueType>
433 void operator << (const ValueType &val)
448 template<
typename ValueType>
449 bool operator >> (ValueType &val)
const
453 const ValueType *pVal = rxvalue_cast<ValueType>(
this);
466 const ValueType *pVal = rxvalue_cast<ValueType>(&subVal);
479#pragma region private
482 bool isInlined()
const
484 return type().size() <=
sizeof(m_value);
486 const void* nonInlineValuePtr()
const {
return m_value.m_ptr; }
487 void* nonInlineValuePtr() {
return m_value.m_ptr; }
488 const void* inlineValuePtr()
const {
return &m_value; }
489 void* inlineValuePtr() {
return &m_value; }
490 const void* valuePtr()
const
493 return inlineValuePtr();
495 return nonInlineValuePtr();
497 template <
bool Inlined>
499 template <
bool Inlined>
500 void initBlittable(
const void*
value,
size_t size);
502 template<
typename T,
bool inlined>
503 class InitNonBlittable
509 class InitNonBlittable<T,
true>
515 class InitNonBlittable<T,
false>
521 template <
typename T>
522 void initNonBlittable(
const T&
value)
524 InitNonBlittable<T,
sizeof(
value) <=
sizeof(m_value) >::init(*
this,
value);
527 void init(
const OdRxValue& rhs,
bool realloc)
529 bool blittable =
type().isBlittable();
530 bool inlined = isInlined();
531 if (blittable && inlined)
533 memcpy(&m_value, &rhs.m_value,
sizeof(m_value));
542 type().nonBlittable()->construct(inlineValuePtr(), rhs.inlineValuePtr());
544 setNonInlineValue(rhs.nonInlineValuePtr(), blittable,
false, realloc);
546 void setNonInlineValue(
const void*
value,
bool blittable,
bool assignment,
bool realloc)
550 unsigned int newSize =
type().size();
551 realloc = realloc || assignment;
554 size_t oldsize = *(((
size_t*)m_value.m_ptr) - 1);
555 if (oldsize != newSize)
557 m_value.m_ptr = reallocate(newSize, m_value.m_ptr);
562 m_value.m_ptr = allocate(newSize);
565 memcpy(nonInlineValuePtr(),
value, newSize);
567 type().nonBlittable()->assign(nonInlineValuePtr(),
value);
569 type().nonBlittable()->construct(nonInlineValuePtr(),
value);
577#if (OD_SIZEOF_PTR == 4)
591 void* allocate(
size_t size)
const;
592 void* reallocate(
size_t size,
void* p)
const;
593 void deallocate(
void* p)
const;
596#pragma endregion private
623inline void* OdRxValue::valuePtr__<true>()
626 return inlineValuePtr();
633inline void* OdRxValue::valuePtr__<false>()
636 return nonInlineValuePtr();
643inline void OdRxValue::initBlittable<true>(
const void*
value,
size_t size)
650inline void OdRxValue::initBlittable<false>(
const void*
value,
size_t size)
654 m_value.m_ptr = allocate(
size);
655 memcpy(nonInlineValuePtr(),
value,
size);
662inline void OdRxValue::InitNonBlittable< T, true>::init(
OdRxValue& rxValue,
const T&
value)
665 ::new ((OdRxValueStorage*)(rxValue.inlineValuePtr())) T(
value);
674 rxValue.setNonInlineValue(&
value,
false,
false,
false);
799#define ODRX_DECLARE_VALUE_TYPE(type, attribute)\
800template<> struct OdRxValueType::Desc<type>\
802 attribute static const OdRxValueType& value() throw();\
803 attribute static void del();\
805template<> OdRxValue::OdRxValue(const type&) throw();
1032#include "TD_PackPop.h"
bool operator==(T left, const OdGiVariant::EnumType right)
ValueType * rxvalue_cast(OdRxValue *value)
OdRxValue createOdRxValue()
OdSmartPtr< OdRxBoxedValue > OdRxBoxedValuePtr
const void * rxvalue_cast< void >(const OdRxValue *value)
#define ODRX_DECLARE_VALUE_TYPE(type, attribute)
ValueType * rxenum_cast(OdRxValue *value)
ODRX_DECLARE_MEMBERS(OdRxBoxedValue)
virtual OdRxValue * value()=0
virtual const OdRxValue * value() const =0
static OdRxBoxedValuePtr newBoxedValueOnHeap(const OdRxValue &value)
virtual OdRxObjectPtr clone() const ODRX_OVERRIDE
OdRxBoxedValueOnStack(OdRxValue &value)
ODRX_DECLARE_MEMBERS(OdRxBoxedValueOnStack)
virtual const OdRxValue * value() const ODRX_OVERRIDE
virtual OdRxValue * value() ODRX_OVERRIDE
const OdRxValueType & type() const
bool operator!=(const OdRxValue &value) const
friend ValueType * rxvalue_cast(OdRxValue *value)
OdRxValue(const OdRxValue &rhs)
static const OdRxValue & empty()
bool operator==(const OdRxValue &value) const
OdRxValue(const OdRxValueType &type, const OdRxValue &value)
OdRxValue & operator=(const ValueType &rhs)
friend const ValueType * rxenum_cast(const OdRxValue *value)
static const OdRxValue * unbox(const OdRxObject *pO)
const OdRxEnumTag * getEnumTag() const
const OdRxValueType & type() const
friend ValueType * rxenum_cast(OdRxValue *value)
static const OdRxValue & varies()
const OdAnsiString typePath() const
OdRxValue(const ValueType &value)
friend const ValueType * rxvalue_cast(const OdRxValue *value)
static OdRxValue * unbox(OdRxObject *pO)
const OdRxValue & operator=(const OdRxValue &rhs)
virtual const IOdRxEnumeration * enumeration() const
GLuint GLsizei GLsizei GLint GLenum * type
GLint GLint GLint GLsizei GLsizei GLenum format
GLsizei const GLfloat * value
virtual const OdRxEnumTag & getAt(int index) const =0
static FIRSTDLL_EXPORT const OdRxValueType & value()
static FIRSTDLL_EXPORT const OdRxValueType & value()
static FIRSTDLL_EXPORT const OdRxValueType & value()
static const OdRxValueType & value()