MeVisLab Toolbox Reference
|
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). | |
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 () | |
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. | |
BaseItem & | operator= (const BaseItem &item) |
Assignment operator. | |
const char * | name () const |
Get name. | |
void | setName (const char *newName) |
Set name, object stores a copy. | |
BaseItem * | deepCopy () 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 BaseContainerItem * | toBaseContainerItem (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 | |
char * | newString (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... | |
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.
ml::BaseContainerItem::BaseContainerItem | ( | ) |
ml::BaseContainerItem::BaseContainerItem | ( | MLssize_t | idParam, |
const char * | nameParam = nullptr, | ||
Base * | baseP = nullptr ) |
When assigning a base object, you should also provide a name.
ml::BaseContainerItem::BaseContainerItem | ( | const BaseContainerItem & | other, |
bool | useDeepCopy = false ) |
|
noexcept |
|
override |
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)
Attaches the object state as children of the given parent node.
Reimplemented from ml::Base.
|
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.
Returns a const pointer to the contained base object.
Definition at line 87 of file mlBaseList.h.
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::BaseContainerItem::ML_SET_ADDSTATE_VERSION | ( | 0 | ) |
Set addState version number.
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.
|
overridevirtual |
Returns a string describing the object's internal state.
Reimplemented from ml::Base.
Reads the object state from the children of the given parent node.
Reimplemented from ml::Base.
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.
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.
Initialize the item object from the string state.
Reimplemented from ml::Base.
|
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.
|
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.
|
protected |
Pointer to the actual object:
Definition at line 143 of file mlBaseList.h.
|
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.