24#ifndef _ODRXVALUE_INCLUDED_
25#define _ODRXVALUE_INCLUDED_
98 memset(&m_value, 0,
sizeof(m_value));
135 if (
type() != rhs.type())
137 if (!
type().isBlittable())
138 type().nonBlittable()->destruct(valuePtr());
139 if (!isInlined() && rhs.isInlined())
140 deallocate(m_value.m_ptr);
142#pragma push_macro("new")
145 ::new ((OdRxValueStorage*)
this)
OdRxValue(rhs, !isInlined() && !rhs.isInlined());
147#pragma pop_macro("new")
151 bool blittable = rhs.type().isBlittable();
152 bool inlined = rhs.isInlined();
153 if (blittable && inlined)
164 type().nonBlittable()->assign(inlineValuePtr(), rhs.inlineValuePtr());
166 setNonInlineValue(rhs.nonInlineValuePtr(), blittable,
true,
true);
176 if (!
type().isBlittable())
177 type().nonBlittable()->destruct(valuePtr());
180 deallocate(m_value.m_ptr);
240 return m_type.toString(valuePtr(),
format);
255 return type().equalTo(valuePtr(),
value.valuePtr());
281 return m_type.typePath(*
this);
290 template <
typename ValueType>
296 initBlittable<sizeof(ValueType) <= 24>(&
value,
sizeof(ValueType));
308 template<
typename ValueType>
323 template<
typename ValueType>
328 value->type().isEnum() &&
340 template<
typename ValueType>
356 template<
typename ValueType>
371 template<
typename ValueType>
434 template<typename ValueType>
435 void operator << (const ValueType &val)
450 template<
typename ValueType>
451 bool operator >> (ValueType &val)
const
481#pragma region private
484 bool isInlined()
const
486 return type().size() <=
sizeof(m_value);
488 const void* nonInlineValuePtr()
const {
return m_value.m_ptr; }
489 void* nonInlineValuePtr() {
return m_value.m_ptr; }
490 const void* inlineValuePtr()
const {
return &m_value; }
491 void* inlineValuePtr() {
return &m_value; }
492 const void* valuePtr()
const
495 return inlineValuePtr();
497 return nonInlineValuePtr();
499 template <
bool Inlined>
501 template <
bool Inlined>
502 void initBlittable(
const void*
value,
size_t size);
504 template<
typename T,
bool inlined>
505 class InitNonBlittable
508 static void init(OdRxValue& rxValue,
const T&
value);
511 class InitNonBlittable<T,
true>
514 static void init(OdRxValue& rxValue,
const T&
value);
517 class InitNonBlittable<T,
false>
520 static void init(OdRxValue& rxValue,
const T&
value);
523 template <
typename T>
524 void initNonBlittable(
const T&
value)
526 InitNonBlittable<T,
sizeof(
value) <=
sizeof(m_value) >::init(*
this,
value);
529 void init(
const OdRxValue& rhs,
bool realloc)
531 bool blittable =
type().isBlittable();
532 bool inlined = isInlined();
533 if (blittable && inlined)
535 memcpy(&m_value, &rhs.m_value,
sizeof(m_value));
544 type().nonBlittable()->construct(inlineValuePtr(), rhs.inlineValuePtr());
546 setNonInlineValue(rhs.nonInlineValuePtr(), blittable,
false, realloc);
548 void setNonInlineValue(
const void*
value,
bool blittable,
bool assignment,
bool realloc)
552 unsigned int newSize =
type().size();
553 realloc = realloc || assignment;
556 size_t oldsize = *(((
size_t*)m_value.m_ptr) - 1);
557 if (oldsize != newSize)
559 m_value.m_ptr = reallocate(newSize, m_value.m_ptr);
564 m_value.m_ptr = allocate(newSize);
567 memcpy(nonInlineValuePtr(),
value, newSize);
569 type().nonBlittable()->assign(nonInlineValuePtr(),
value);
571 type().nonBlittable()->construct(nonInlineValuePtr(),
value);
573 OdRxValue(
const OdRxValue& rhs,
bool realloc)
578 const OdRxValueType& m_type;
579#if (OD_SIZEOF_PTR == 4)
593 void* allocate(
size_t size)
const;
594 void* reallocate(
size_t size,
void* p)
const;
595 void deallocate(
void* p)
const;
598#pragma endregion private
625inline void* OdRxValue::valuePtr__<true>()
628 return inlineValuePtr();
635inline void* OdRxValue::valuePtr__<false>()
638 return nonInlineValuePtr();
645inline void OdRxValue::initBlittable<true>(
const void*
value,
size_t size)
652inline void OdRxValue::initBlittable<false>(
const void*
value,
size_t size)
656 m_value.m_ptr = allocate(
size);
657 memcpy(nonInlineValuePtr(),
value,
size);
664inline void OdRxValue::InitNonBlittable< T, true>::init(
OdRxValue& rxValue,
const T&
value)
667 ::new ((OdRxValueStorage*)(rxValue.inlineValuePtr())) T(
value);
676 rxValue.setNonInlineValue(&
value,
false,
false,
false);
801#define ODRX_DECLARE_VALUE_TYPE(type, attribute)\
802template<> struct OdRxValueType::Desc<type>\
804 attribute static const OdRxValueType& value() throw();\
805 attribute static void del();\
807template<> OdRxValue::OdRxValue(const type&) throw();
1064#include "TD_PackPop.h"
OdArray< double, OdMemoryAllocator< double > > OdGeDoubleArray
bool operator==(T left, const OdGiVariant::EnumType right)
OdArray< OdInt64, OdMemoryAllocator< OdInt64 > > OdInt64Array
OdArray< int, OdMemoryAllocator< int > > OdIntArray
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)
OdArray< OdUInt64, OdMemoryAllocator< OdUInt64 > > OdUInt64Array
ODRX_DECLARE_MEMBERS(OdRxBoxedValue)
virtual OdRx::Ordering comparedTo(const OdRxObject *other) const ODRX_OVERRIDE
virtual OdRxValue * value()=0
virtual const OdRxValue * value() const =0
virtual bool isEqualTo(const OdRxObject *other) const ODRX_OVERRIDE
static OdRxBoxedValuePtr newBoxedValueOnHeap(const OdRxValue &value)
virtual OdRxObjectPtr clone() const ODRX_OVERRIDE
virtual void copyFrom(const OdRxObject *other) ODRX_OVERRIDE
OdRxBoxedValueOnStack(OdRxValue &value)
ODRX_DECLARE_MEMBERS(OdRxBoxedValueOnStack)
virtual const OdRxValue * value() const ODRX_OVERRIDE
virtual OdRxValue * value() ODRX_OVERRIDE
OdRxClass(OdRxClassImpl *)
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)
size_t serializeIn(const void *pBytes, size_t maxBytesToRead)
OdRxValue & operator=(const ValueType &rhs)
friend const ValueType * rxenum_cast(const OdRxValue *value)
static const OdRxValue * unbox(const OdRxObject *pO)
OdString toString(OdRxValueType::StringFormat format=OdRxValueType::kStringFormatGlobal) const
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)
size_t serializeOut(void *pBytes, size_t &maxBytesToWrite) const
const OdRxValue & operator=(const OdRxValue &rhs)
OdRxValueType(const OdRxValueType &)=delete
GLuint GLsizei GLsizei GLint GLenum * type
GLint GLint GLint GLsizei GLsizei GLenum format
GLsizei const GLfloat * value
static FIRSTDLL_EXPORT const OdRxValueType & value()
static FIRSTDLL_EXPORT void del()
static FIRSTDLL_EXPORT const OdRxValueType & value()
static FIRSTDLL_EXPORT void del()
static FIRSTDLL_EXPORT void del()
static FIRSTDLL_EXPORT const OdRxValueType & value()
static const OdRxValueType & value()