MeVisLab Toolbox Reference
ml::BaseContainerItem Class Reference

Base object class BaseContainerItem encapsulates a pointer to a Base object as a list item. More...

#include <mlBaseList.h>

Inheritance diagram for ml::BaseContainerItem:
ml::BaseItem ml::Base

Public Member Functions

virtual void setObject (Base &object)
 Sets a new object.
 
virtual BasegetObjectPointer () const
 Returns a pointer to the contained base object.
 
virtual const BasegetConstObjectPointer () const
 Returns a const pointer to the contained base object.
 
virtual BaseremoveObjectPointer ()
 Removes the contained object (deletes if owned and not ref-counted).
 
BaseContainerItemoperator= (const BaseContainerItem &other)
 Assignment operator, performing a shallow copy as far as the contained base object is concerned.
 
virtual BaseContainerItemcopyFrom (const BaseContainerItem &other, bool performDeepCopy=true)
 Copies from other BaseContainerItem.
 
Constructors
 BaseContainerItem ()
 
 BaseContainerItem (MLssize_t idParam, const char *nameParam=nullptr, Base *baseP=nullptr)
 When assigning a base object, you should also provide a name.
 
 BaseContainerItem (const BaseContainerItem &other, bool useDeepCopy=false)
 
 BaseContainerItem (BaseContainerItem &&other) noexcept
 
 ~BaseContainerItem () override
 
Persistence

Return a string representation of the item object.

std::string persistentState () const override
 Returns a string describing the object's internal state.
 
void setPersistentState (const std::string &state) override
 Initialize the item object from the string state.
 
void addStateToTree (TreeNode *parent) const override
 Attaches the object state as children of the given parent node.
 
 ML_SET_ADDSTATE_VERSION (0)
 Set addState version number.
 
void readStateFromTree (TreeNode *parent) override
 Reads the object state from the children of the given parent node.
 
- Public Member Functions inherited from ml::BaseItem
void setId (MLssize_t id)
 Sets the id of the item.
 
MLssize_t getId () const
 Sets the id of the item.
 
 ~BaseItem () override
 Destructor.
 
BaseItemoperator= (const BaseItem &item)
 Assignment operator.
 
const charname () const
 Get name.
 
void setName (const char *newName)
 Set name, object stores a copy.
 
BaseItemdeepCopy () const override
 Create a deep copy of the BaseItem.
 
 BaseItem ()
 Default constructor.
 
 BaseItem (MLssize_t id, const char *nameStr=nullptr)
 ID and name.
 
 BaseItem (const BaseItem &item)
 Copy constructor.
 
std::string persistentState () const override
 Return a string representation of the item object.
 
void setPersistentState (const std::string &state) override
 Initialize the item object from the string state.
 
void addStateToTree (TreeNode *parent) const override
 Attaches the object state as children of the given parent node.
 
 ML_SET_ADDSTATE_VERSION (0)
 Set addState version number.
 
void readStateFromTree (TreeNode *parent) override
 Reads the object state from the children of the given parent node.
 
void writeTo (AbstractPersistenceOutputStream *stream) const override
 write state to stream
 
void readFrom (AbstractPersistenceInputStream *stream, int version) override
 read state from stream
 
- Public Member Functions inherited from ml::Base
 Base ()
 Constructor.
 
virtual ~Base ()
 Destructor.
 
bool isOfAllowedType (const std::vector< const RuntimeType * > &types) const
 Check if this object's type is equal to or derived from one of the types given in the argument.
 
virtual bool isRefCountedBase () const
 Returns if the instance is derived from RefCountedBase.
 
virtual std::string detailString () const
 Return a string describing this object.
 
virtual bool implementsPersistence (PersistenceInterface) const
 Override this method to declare which persistence interfaces are implemented by your derived class.
 

Static Public Member Functions

static BaseContainerItemtoBaseContainerItem (Base &baseObj, MLssize_t id=0, const char *name=nullptr)
 Returns baseObj, if baseObj already is a BaseContainerItem.
 

Protected Member Functions

void _setObjectPointer (Base *objectP, bool isOwner=true)
 Sets a new object by pointer.
 
- Protected Member Functions inherited from ml::BaseItem
charnewString (const std::string &str) const
 Convenience method to create a copy of the string str allocated on the heap.
 
void deleteString (char *str) const
 Dispose a string allocated with newString()
 

Protected Attributes

Base_baseObjectP
 Pointer to the actual object:
 
bool _ownsBaseObject
 Flag remembering if the contained base object is owned.
 
bool _baseObjectIsRefCounted
 Flag remembering if the contained base object is ref-counted This flag is not strictly necessary, but it prevents us from having to ask the object in the destructor whether it is ref-counted, which can sometimes cause crashes if a non-ref-counted object was already deleted by someone else (this should not happen but can).
 

Additional Inherited Members

- Public Types inherited from ml::Base
enum  PersistenceInterface { PersistenceByString , PersistenceByTreeNode , PersistenceByStream }
 This enum describes the different persistence interfaces available. More...
 

Detailed Description

Base object class BaseContainerItem encapsulates a pointer to a Base object as a list item.

The class is reference-counting aware so that objects derived from RefCountedBase are correctly handled. The class supports TreeNode persistence. Objects are never owned (and thus never deleted) except when created by the BaseContainerItem itself (in case of restoration from a TreeNode) or in a deep copy operation (which is performed using set/getPersistentState and thus only available for base objects implementing this concept.

Definition at line 52 of file mlBaseList.h.

Constructor & Destructor Documentation

◆ BaseContainerItem() [1/4]

ml::BaseContainerItem::BaseContainerItem ( )

◆ BaseContainerItem() [2/4]

ml::BaseContainerItem::BaseContainerItem ( MLssize_t idParam,
const char * nameParam = nullptr,
Base * baseP = nullptr )

When assigning a base object, you should also provide a name.

◆ BaseContainerItem() [3/4]

ml::BaseContainerItem::BaseContainerItem ( const BaseContainerItem & other,
bool useDeepCopy = false )

◆ BaseContainerItem() [4/4]

ml::BaseContainerItem::BaseContainerItem ( BaseContainerItem && other)
noexcept

◆ ~BaseContainerItem()

ml::BaseContainerItem::~BaseContainerItem ( )
override

Member Function Documentation

◆ _setObjectPointer()

void ml::BaseContainerItem::_setObjectPointer ( Base * objectP,
bool isOwner = true )
protected

Sets a new object by pointer.

The previous one (if any) is automatically removed using removeObject(). The \ isOwner parameter is only relevant for non-ref-counted objects and indicates whether the item is responsible for the given object's deletion. The method is protected because it does not make sense to delete externally created base objects (delete might not necessarily be correct)

◆ addStateToTree()

void ml::BaseContainerItem::addStateToTree ( TreeNode * parent) const
overridevirtual

Attaches the object state as children of the given parent node.

Reimplemented from ml::Base.

◆ copyFrom()

virtual BaseContainerItem & ml::BaseContainerItem::copyFrom ( const BaseContainerItem & other,
bool performDeepCopy = true )
virtual

Copies from other BaseContainerItem.

If performDeepCopy is false, only the pointer will be copied. Otherwise, the method tries to perform a deepCopy a copy of the object contained (only works if get/setPersistentState are correctly implemented). In any case, the currently contained object (if any) is removed.

◆ getConstObjectPointer()

virtual const Base * ml::BaseContainerItem::getConstObjectPointer ( ) const
inlinevirtual

Returns a const pointer to the contained base object.

Definition at line 87 of file mlBaseList.h.

◆ getObjectPointer()

virtual Base * ml::BaseContainerItem::getObjectPointer ( ) const
inlinevirtual

Returns a pointer to the contained base object.

NOTE: Do not use this method to get the object for deletion, use removeObjectPointer() for that purpose.

Definition at line 82 of file mlBaseList.h.

◆ ML_SET_ADDSTATE_VERSION()

ml::BaseContainerItem::ML_SET_ADDSTATE_VERSION ( 0 )

Set addState version number.

◆ operator=()

BaseContainerItem & ml::BaseContainerItem::operator= ( const BaseContainerItem & other)

Assignment operator, performing a shallow copy as far as the contained base object is concerned.

If this is not what you want, use copyFrom(X, true) or deepCopy() instead.

◆ persistentState()

std::string ml::BaseContainerItem::persistentState ( ) const
overridevirtual

Returns a string describing the object's internal state.

Reimplemented from ml::Base.

◆ readStateFromTree()

void ml::BaseContainerItem::readStateFromTree ( TreeNode * parent)
overridevirtual

Reads the object state from the children of the given parent node.

Reimplemented from ml::Base.

◆ removeObjectPointer()

virtual Base * ml::BaseContainerItem::removeObjectPointer ( )
virtual

Removes the contained object (deletes if owned and not ref-counted).

If the removed object was neither ref-counted nor owned, its address is returned for external removal. Otherwise, NULL is returned.

◆ setObject()

virtual void ml::BaseContainerItem::setObject ( Base & object)
virtual

Sets a new object.

The previous object (if any) is automatically removed using removeObject(). If the object derived from RefCountedBase, the Item's reference is counted accoringly. For all (and especially the non-ref-counted objects, the ownership remains with the caller.

◆ setPersistentState()

void ml::BaseContainerItem::setPersistentState ( const std::string & state)
overridevirtual

Initialize the item object from the string state.

Reimplemented from ml::Base.

◆ toBaseContainerItem()

static BaseContainerItem * ml::BaseContainerItem::toBaseContainerItem ( Base & baseObj,
MLssize_t id = 0,
const char * name = nullptr )
static

Returns baseObj, if baseObj already is a BaseContainerItem.

If not, an item containing baseObj is created using new(). Returns NULL if object creation failed.

Member Data Documentation

◆ _baseObjectIsRefCounted

bool ml::BaseContainerItem::_baseObjectIsRefCounted
protected

Flag remembering if the contained base object is ref-counted This flag is not strictly necessary, but it prevents us from having to ask the object in the destructor whether it is ref-counted, which can sometimes cause crashes if a non-ref-counted object was already deleted by someone else (this should not happen but can).

Definition at line 155 of file mlBaseList.h.

◆ _baseObjectP

Base* ml::BaseContainerItem::_baseObjectP
protected

Pointer to the actual object:

Definition at line 143 of file mlBaseList.h.

◆ _ownsBaseObject

bool ml::BaseContainerItem::_ownsBaseObject
protected

Flag remembering if the contained base object is owned.

The flag is only relevant if _baseObjectP refers to a non-ref-counted base objects (i.e. _baseObjectIsRefCounted is true).

Definition at line 148 of file mlBaseList.h.


The documentation for this class was generated from the following file: