24#ifndef __DOTS_OBJECT_CONTAINER_H__
25#define __DOTS_OBJECT_CONTAINER_H__
216 m_pObject = std::dynamic_pointer_cast<T>(other.m_pObject->Clone());
217 if (m_pObject == NULL)
219 throw IncompatibleTypesException(L
"The types are not compatible!",__WFILE__,__LINE__);
240 m_pObject = std::dynamic_pointer_cast<T>(other.m_pObject->Clone());
241 if (m_pObject == NULL)
267 m_pObject = std::dynamic_pointer_cast<T>(ptr);
268 if (m_pObject == NULL)
314 bool IsNull()
const override {
return m_pObject == NULL;}
316 bool HasVal()
const override {
return m_pObject != NULL;}
328 if (
typeid(*
this) !=
typeid(that))
372 m_pObject = std::dynamic_pointer_cast<T>(ptr);
373 if(m_pObject == NULL)
378 m_pObject = std::static_pointer_cast<T>(ptr);
393 class ObjectContainerImpl<Object> :
public ObjectContainerBase
397 typedef std::shared_ptr<Object> T_Ptr;
398 typedef T_Ptr ContainedType;
405 ObjectContainerImpl():ObjectContainerBase() {}
415 ObjectContainerImpl(
const ObjectContainerImpl & other):
416 ObjectContainerBase(other)
420 m_pObject = other.m_pObject->Clone();
430 ObjectContainerImpl & operator=(
const ObjectContainerImpl & other)
432 ObjectContainerBase::operator =(other);
439 m_pObject = other.m_pObject->Clone();
445 void SetPtr(
const ObjectPtr & ptr)
override
460 const T_Ptr & GetPtr()
const
464 throw NullException(L
"Object is null",
__WFILE__,__LINE__);
477 const T_Ptr GetPtrOrNull()
const {
return IsNull() ? T_Ptr() : m_pObject;}
488 Object * operator->()
const
492 throw NullException(L
"Object is null",
__WFILE__,__LINE__);
494 return m_pObject.operator->();
497 void SetChanged(
const bool changed)
override
499 m_bIsChanged = changed;
502 m_pObject->SetChanged(changed);
506 bool IsChanged()
const override {
return m_bIsChanged || (!IsNull() && m_pObject->IsChanged());}
508 bool IsNull()
const override {
return m_pObject == NULL;}
510 bool HasVal()
const override {
return m_pObject != NULL;}
512 void SetNull()
override
518 void Copy(
const ContainerBase & that)
override
522 if (
typeid(*
this) !=
typeid(that))
524 throw SoftwareViolationException(L
"Invalid call to Copy, containers are not of same type",
__WFILE__,__LINE__);
526 const ObjectContainerImpl<Object> & castedThat =
static_cast<const ObjectContainerImpl<Object> &
>(that);
527 m_bIsChanged = castedThat.m_bIsChanged;
534 SetObjectPointer(castedThat.m_pObject->Clone());
540 ContainerBase & GetMember(
const int member,
const int index)
override
541 {
if (IsNull())
throw NullException(L
"Object is null",
__WFILE__,__LINE__);
return m_pObject->GetMember(member,index);}
542 const ContainerBase & GetMember(
const int member,
const int index)
const override
543 {
if (IsNull())
throw NullException(L
"Object is null",
__WFILE__,__LINE__);
return m_pObject->GetMember(member,index);}
546 const ObjectPtr GetObjectPointer()
const override {
return std::static_pointer_cast<Object>(m_pObject);}
547 void SetObjectPointer(
const ObjectPtr ptr)
override
551 void ResetObjectPointer()
override {m_pObject.reset();}
#define __WFILE__
Definition Exceptions.h:31
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
This namespace contains all functionality of the DOB (Components DOSE and DOTS).
Definition Connection.h:38
This namespace contains the DOB Typesystem functionality and definitions.
Definition ArrayContainer.h:37
DotsC_Int32 Int32
32 bit integer type.
Definition Defs.h:66
Safir::Dob::Typesystem::ObjectContainerImpl< Object > ObjectContainer
Container for DOB Objects.
Definition ObjectContainer.h:565
std::shared_ptr< Object > ObjectPtr
A smart pointer to an Object.
Definition Object.h:44
Base class for all Containers.
Definition ContainerBase.h:44
bool m_bIsChanged
The variable containing the change flag.
Definition ContainerBase.h:134
constexpr ContainerBase()
Default Constructor.
Definition ContainerBase.h:51
virtual bool IsNull() const =0
Is the container set to null?
ContainerBase & operator=(const ContainerBase &other)
Copy assignment operator.
Definition ContainerBase.h:128
This exception is thrown if a class cannot be cast to the expected type.
Definition Exceptions.h:297
Meant to be used when something goes very wrong.
Definition Exceptions.h:364
Thrown when an application attempts to get the value of a member that is null.
Definition Exceptions.h:396
void SetChangedHere(const bool changed)
Set the change flag in the container.
Definition ObjectContainer.h:82
virtual ContainerBase & GetMember(const int member, const int index)=0
Get a reference to a member container from an object.
virtual void ResetObjectPointer()=0
Reset (ie set to null) the contained pointer.
friend class Safir::Dob::Typesystem::Internal::BlobOperations
Definition ObjectContainer.h:164
virtual const ObjectPtr GetObjectPointer() const =0
Get a smart pointer to the contained object.
bool IsChangedHere() const
Is the change flag in the container set?
Definition ObjectContainer.h:73
virtual const ContainerBase & GetMember(const int member, const int index) const =0
Get a const reference to a member container from an object.
ObjectContainerBase()
Default constructor.
Definition ObjectContainer.h:48
virtual void SetPtr(const ObjectPtr &ptr)=0
Set the smart pointer in the container.
ObjectContainerBase(const ObjectContainerBase &)=default
Copy constructor.
ObjectContainerBase & operator=(const ObjectContainerBase &other)
Copy assignment operator.
Definition ObjectContainer.h:172
virtual void SetObjectPointer(const ObjectPtr ptr)=0
Set the smart pointer in the container.
void SetObjectPointer(const ObjectPtr ptr) override
Definition ObjectContainer.h:369
Int32 CalculateBlobSize() const
Calculate the size of the blob-serialized form of the contained object.
Definition ObjectContainer.h:364
void ResetObjectPointer() override
Reset (ie set to null) the contained pointer.
Definition ObjectContainer.h:381
void SetPtr(const ObjectPtr &ptr) override
Set the smart pointer in the container.
Definition ObjectContainer.h:264
void SetChanged(const bool changed) override
Set the containers change flag.
Definition ObjectContainer.h:310
const T_Ptr GetPtrOrNull() const
Get the smart pointer from the container or a nullptr if container is null.
Definition ObjectContainer.h:295
ContainerBase & GetMember(const int member, const int index) override
Get a reference to a member container from an object.
Definition ObjectContainer.h:346
T_Ptr ContainedType
Definition ObjectContainer.h:194
bool IsNull() const override
Is the container set to null?
Definition ObjectContainer.h:314
const ObjectPtr GetObjectPointer() const override
Get a smart pointer to the contained object.
Definition ObjectContainer.h:368
bool HasVal() const override
Does the container have a value?
Definition ObjectContainer.h:316
ObjectContainerImpl & operator=(const ObjectContainerImpl &other)
Copy assignment operator.
Definition ObjectContainer.h:231
const T_Ptr & GetPtr() const
Get the smart pointer from the container.
Definition ObjectContainer.h:283
const ContainerBase & GetMember(const int member, const int index) const override
Get a const reference to a member container from an object.
Definition ObjectContainer.h:348
T * operator->() const
Dereference the smart pointer in the container.
Definition ObjectContainer.h:306
ObjectContainerImpl(const ObjectContainerImpl &other)
Copy constructor.
Definition ObjectContainer.h:211
void Copy(const ContainerBase &that) override
Virtual assignment.
Definition ObjectContainer.h:324
bool IsChanged() const override
Is the change flag set on the container?
Definition ObjectContainer.h:312
void SetNull() override
Set the container to null.
Definition ObjectContainer.h:318
ObjectContainerImpl()
Default constructor.
Definition ObjectContainer.h:201
std::shared_ptr< U > T_Ptr
Definition ObjectContainer.h:193
void SetPtr(const T_Ptr &ptr)
Set the smart pointer in the container.
Definition ObjectContainer.h:258