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. More...
 
virtual BasegetObjectPointer () const
 Returns a pointer to the contained base object. More...
 
virtual const BasegetConstObjectPointer () const
 Returns a const pointer to the contained base object. More...
 
virtual BaseremoveObjectPointer ()
 Removes the contained object (deletes if owned and not ref-counted). More...
 
BaseContainerItemoperator= (const BaseContainerItem &other)
 Assignment operator, performing a shallow copy as far as the contained base object is concerned. More...
 
virtual BaseContainerItemcopyFrom (const BaseContainerItem &other, bool performDeepCopy=true)
 Copies from other BaseContainerItem. More...
 
Constructors
 BaseContainerItem ()
 
 BaseContainerItem (MLssize_t idParam, const char *nameParam=nullptr, Base *baseP=nullptr)
 When assigning a base object, you should also provide a name. More...
 
 BaseContainerItem (const BaseContainerItem &other, bool useDeepCopy=false)
 
 BaseContainerItem (BaseContainerItem &&other) noexcept
 
 ~BaseContainerItem () override
 
- Public Member Functions inherited from ml::BaseItem
void setId (MLssize_t id)
 Sets the id of the item. More...
 
MLssize_t getId () const
 Sets the id of the item. More...
 
 ~BaseItem () override
 Destructor. More...
 
BaseItemoperator= (const BaseItem &item)
 Assignment operator. More...
 
const char * name () const
 Get name. More...
 
void setName (const char *newName)
 Set name, object stores a copy. More...
 
BaseItemdeepCopy () const override
 Create a deep copy of the BaseItem. More...
 
 BaseItem ()
 Default constructor. More...
 
 BaseItem (MLssize_t id, const char *nameStr=nullptr)
 ID and name. More...
 
 BaseItem (const BaseItem &item)
 Copy constructor. More...
 
 ML_SET_ADDSTATE_VERSION (0)
 Set addState version number. More...
 
void writeTo (AbstractPersistenceOutputStream *stream) const override
 write state to stream More...
 
void readFrom (AbstractPersistenceInputStream *stream, int version) override
 read state from stream More...
 
- Public Member Functions inherited from ml::Base
 Base ()
 Constructor. More...
 
virtual ~Base ()
 Destructor. More...
 
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. More...
 
virtual bool isRefCountedBase () const
 Returns if the instance is derived from RefCountedBase. More...
 
virtual std::string detailString () const
 Return a string describing this object. More...
 
virtual bool implementsPersistence (PersistenceInterface) const
 Override this method to declare which persistence interfaces are implemented by your derived class. More...
 

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

Base_baseObjectP
 Pointer to the actual object: More...
 
bool _ownsBaseObject
 Flag remembering if the contained base object is owned. More...
 
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). More...
 

Persistence

Return a string representation of the item object.

std::string persistentState () const override
 Return a string representation of the item object. More...
 
void setPersistentState (const std::string &state) override
 Initialize the item object from the string state. More...
 
void clearPersistentState (char *state) const override
 Dispose the string state, which has been previously obtained by getPersistentState() More...
 
void addStateToTree (TreeNode *parent) const override
 Attaches the object state as children of the given parent node. More...
 
 ML_SET_ADDSTATE_VERSION (0)
 Set addState version number. More...
 
void readStateFromTree (TreeNode *parent) override
 Reads the object state from the children of the given parent node. More...
 

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::BaseItem.

◆ clearPersistentState()

void ml::BaseContainerItem::clearPersistentState ( char *  state) const
overridevirtual

Dispose the string state, which has been previously obtained by getPersistentState()

Reimplemented from ml::BaseItem.

◆ 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 ( )

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

Return a string representation of the item object.

Reimplemented from ml::BaseItem.

◆ readStateFromTree()

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

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

Reimplemented from ml::BaseItem.

◆ 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::BaseItem.

◆ 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 175 of file mlBaseList.h.

◆ _baseObjectP

Base* ml::BaseContainerItem::_baseObjectP
protected

Pointer to the actual object:

Definition at line 163 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 168 of file mlBaseList.h.


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