MeVisLabToolboxReference
|
Base object class BaseContainerItem encapsulates a pointer to a Base object as a list item. More...
#include <mlBaseList.h>
Public Member Functions | |
virtual void | setObject (Base &object) |
Sets a new object. | |
virtual Base * | getObjectPointer () const |
Returns a pointer to the contained base object. | |
virtual const Base * | getConstObjectPointer () const |
Returns a const pointer to the contained base object. | |
virtual Base * | removeObjectPointer () |
Removes the contained object (deletes if owned and not ref-counted). | |
virtual BaseContainerItem & | operator= (const BaseContainerItem &other) |
Assignment operator, performing a shallow copy as far as the contained base object is concerned. | |
virtual BaseContainerItem & | copyFrom (const BaseContainerItem &other, bool performDeepCopy=true) |
Copies from other BaseContainerItem. | |
Constructors | |
BaseContainerItem () | |
Default constructor. | |
BaseContainerItem (MLssize_t idParam, const char *nameParam=0, Base *baseP=0) | |
When assigning a base object, you should also provide a name. | |
BaseContainerItem (const BaseContainerItem &other) | |
Copy constructor. | |
bool | operator< (const BaseContainerItem &) const |
Dummy "lesser than operator", required for VC7. | |
bool | operator== (const BaseContainerItem &) const |
Dummy "equal operator", required for VC7. | |
Destructor | |
virtual | ~BaseContainerItem () |
Destructor, makes sure the contained object is deleted if necessary. | |
Persistence | |
virtual char * | getPersistentState () const |
Return a string representation of the item object. | |
virtual void | setPersistentState (const char *state) |
Initialize the item object from the string state. | |
virtual void | clearPersistentState (char *state) const |
Dispose the string state, which has been previously obtained by getPersistentState() | |
virtual void | addStateToTree (TreeNode *parent) const |
Attaches the object state as children of the given parent node. | |
ML_SET_ADDSTATE_VERSION (0) | |
Set addState version number. | |
virtual void | readStateFromTree (TreeNode *parent) |
Reads the object state from the children of the given parent node. | |
Static Public Member Functions | |
static BaseContainerItem * | toBaseContainerItem (Base &baseObj, MLssize_t id=0, const char *name=NULL) |
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 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). |
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 55 of file mlBaseList.h.
ml::BaseContainerItem::BaseContainerItem | ( | ) |
Default constructor.
ml::BaseContainerItem::BaseContainerItem | ( | MLssize_t | idParam, |
const char * | nameParam = 0 , |
||
Base * | baseP = 0 |
||
) |
When assigning a base object, you should also provide a name.
ml::BaseContainerItem::BaseContainerItem | ( | const BaseContainerItem & | other | ) |
Copy constructor.
virtual ml::BaseContainerItem::~BaseContainerItem | ( | ) | [virtual] |
Destructor, makes sure the contained object is deleted if necessary.
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)
virtual void ml::BaseContainerItem::addStateToTree | ( | TreeNode * | parent | ) | const [virtual] |
Attaches the object state as children of the given parent node.
Reimplemented from ml::BaseItem.
virtual void ml::BaseContainerItem::clearPersistentState | ( | char * | state | ) | const [virtual] |
Dispose the string state, which has been previously obtained by getPersistentState()
Reimplemented from ml::BaseItem.
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.
virtual const Base* ml::BaseContainerItem::getConstObjectPointer | ( | ) | const [inline, virtual] |
Returns a const pointer to the contained base object.
Definition at line 102 of file mlBaseList.h.
virtual Base* ml::BaseContainerItem::getObjectPointer | ( | ) | const [inline, virtual] |
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 97 of file mlBaseList.h.
virtual char* ml::BaseContainerItem::getPersistentState | ( | ) | const [virtual] |
Return a string representation of the item object.
The string is allocated on the heap and is later disposed by clearPersistentState().
Reimplemented from ml::BaseItem.
ml::BaseContainerItem::ML_SET_ADDSTATE_VERSION | ( | 0 | ) |
Set addState version number.
Reimplemented from ml::BaseItem.
bool ml::BaseContainerItem::operator< | ( | const BaseContainerItem & | ) | const [inline] |
Dummy "lesser than operator", required for VC7.
Definition at line 72 of file mlBaseList.h.
virtual BaseContainerItem& ml::BaseContainerItem::operator= | ( | const BaseContainerItem & | other | ) | [virtual] |
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.
bool ml::BaseContainerItem::operator== | ( | const BaseContainerItem & | ) | const [inline] |
Dummy "equal operator", required for VC7.
Definition at line 75 of file mlBaseList.h.
virtual void ml::BaseContainerItem::readStateFromTree | ( | TreeNode * | parent | ) | [virtual] |
Reads the object state from the children of the given parent node.
Reimplemented from ml::BaseItem.
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.
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.
virtual void ml::BaseContainerItem::setPersistentState | ( | const char * | state | ) | [virtual] |
Initialize the item object from the string state.
Reimplemented from ml::BaseItem.
static BaseContainerItem* ml::BaseContainerItem::toBaseContainerItem | ( | Base & | baseObj, |
MLssize_t | id = 0 , |
||
const char * | name = NULL |
||
) | [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.
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 176 of file mlBaseList.h.
Base* ml::BaseContainerItem::_baseObjectP [protected] |
Pointer to the actual object:
Definition at line 164 of file mlBaseList.h.
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 169 of file mlBaseList.h.