MeVisLab Toolbox Reference
ml::BaseListTemplate< T > Class Template Reference

Base object template list class for list item classes derived from BaseItem. More...

#include <mlListBase.h>

Inheritance diagram for ml::BaseListTemplate< T >:
ml::ListTemplate< T > ml::ListBase ml::Base

Public Member Functions

BaseListTemplate< T > & operator= (const BaseListTemplate &other)=default
 explicitly create default assignment operator More...
 
BaseItemgetItemAt (MLssize_t index) override
 This virtual function is reimplemented from ListBase, where it returns 0 in any case (also in ListTemplate<T>, because the items are not necessarily BaseItems there). More...
 
const BaseItemgetConstItemAt (MLssize_t index) const override
 Same as getItemAt(MLssize_t index) for constant access. More...
 
void insertItemAt (MLssize_t index, const BaseItem *item) override
 This virtual function is reimplemented from ListBase, where it does nothing at all. More...
 
void modifyItemAt (MLssize_t index, const BaseItem *item) override
 This virtual function is reimplemented from ListBase, where it does nothing at all. More...
 
void deleteItemAt (MLssize_t index) override
 This virtual function is reimplemented from ListBase, where it does nothing at all. More...
 
void selectItemAt (MLssize_t index) override
 This virtual function is reimplemented from ListBase, where it does nothing at all. More...
 
const RuntimeTypegetItemTypeId () const override
 This virtual function is reimplemented from ListBase, where it returns 0 in any case (also in ListTemplate<T>, because the items are not necessarily BaseItems there). More...
 
void clearList () override
 Clear complete list. More...
 
Constructors
 BaseListTemplate ()
 Standard constructor, disables persistence. More...
 
 BaseListTemplate (bool persistance)
 Special constructor to explicitly enable/disable persistence. More...
 
 BaseListTemplate (const BaseListTemplate &other)
 
Next-id support
virtual MLssize_t newId ()
 Get new unused id. More...
 
virtual void usedId (MLssize_t id)
 Notify list that id is used. More...
 
virtual void resetId ()
 Reset next id. More...
 
List modification methods

These methods combine list modifications (via the STL vector interface) with the corresponding updates of the last action properties.

They are provided for convenience when only a single modification is performed and the field to which the list might be connected is touched directly after this modification. Do not use these methods if several modifications are performed before the list field is touched.

virtual void doDeleteItem (MLssize_t index)
 Delete single item at position index and set the corresponding ActDelete action. More...
 
virtual void doInsertItem (MLssize_t index, const T &item)
 Insert item at position index, assign a new id value to the inserted item and set the corresponding ActInsert action. More...
 
virtual void doModifyItem (MLssize_t index, const T &item)
 Store item at position index and set the corresponding ActModify action. More...
 
virtual void doSelectItem (MLssize_t index)
 Select item at position index, or deselect if item == -1, and set the corresponding ActSelect action. More...
 
virtual void appendItem (const T &item)
 Appends an item to the list. More...
 
void addStateToTree (TreeNode *parent) const override
 Attaches the object state as children of the given parent node. More...
 
 ML_SET_ADDSTATE_VERSION (1)
 Set addState version number. More...
 
void readStateFromTree (TreeNode *parent) override
 Reads the object state from the children of the given parent node. More...
 
- Public Member Functions inherited from ml::ListTemplate< T >
 ListTemplate ()
 Standard constructor, disables persistence. More...
 
 ListTemplate (bool persistance)
 Special constructor to explicitly enable/disable persistence. More...
 
 ListTemplate (const ListTemplate &other)
 
size_t getSize () const override
 Get number of list elements. More...
 
ListTemplate< T > & operator= (const ListTemplate< T > &list)
 Assignment operator. More...
 
ListTemplate< T > * clone () const override
 Create a copy of (*this) using the ML runtime system and the '='-operator. More...
 
ListTemplate< T > * deepCopy () const override
 Create a deep copy of the list. More...
 
std::string persistentState () const override
 Returns a string describing the object's internal state. More...
 
void setPersistentState (const std::string &state) override
 Initialize the list object from the string state. More...
 
 ML_SET_ADDSTATE_VERSION (2)
 Set addState version number, version 2 indicates data saved by a 64 bit version. More...
 
- Public Member Functions inherited from ml::ListBase
 ListBase (bool persistance)
 Constructor. Derived class should indicate whether persistence is implemented. More...
 
 ListBase (const ListBase &other)
 
virtual void setAction (ActionClass actionClass, MLssize_t id, MLssize_t index)
 Set actionClass, affected item id and index. More...
 
virtual void setAction (ActionClass actionClass)
 Set actionClass for actions affecting the whole list. More...
 
virtual void getAction (ActionClass &actionClass, MLssize_t &id, MLssize_t &index) const
 Get actionClass, affected item id and index. More...
 
virtual ActionClass getActionClass () const
 Get actionClass of last action. More...
 
virtual MLssize_t getActionId () const
 Get id of item affected by last action. More...
 
virtual MLssize_t getActionIndex () const
 Get index of item affected by last action. More...
 
virtual MLssize_t getCurrentIndex () const
 Get index of currently selected item, or -1 if no item selected. More...
 
virtual bool isModified () const
 Tests, if the last action has been an action that has modified the content of the list. More...
 
virtual bool hasPersistance () const
 Test if persistence is available and enabled. More...
 
virtual void setPersistance (bool persistance)
 Enable/disable persistence functionality. More...
 
 ML_SET_ADDSTATE_VERSION (0)
 Set addState version number. 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...
 
virtual void writeTo (AbstractPersistenceOutputStream *) const
 Write the objects state to the data stream object. More...
 
virtual void readFrom (AbstractPersistenceInputStream *, int)
 Read the objects state from the data stream object. More...
 

Protected Member Functions

List item persistence

List persistence is directly based on the persistence methods of the list item class.

Hence, the following methods are mapped to the item class persistence methods.

Return a string representation of the item object.

std::string itemState (typename ListTemplate< T >::const_iterator it) const override
 Return a string representation of the item object. More...
 
void setItemState (typename ListTemplate< T >::iterator it, const std::string &state) override
 Initialize the item object from the string state. More...
 
char * getItemState (typename ListTemplate< T >::const_iterator it) const override
 Return a string representation of the item object. More...
 
void setItemState (typename ListTemplate< T >::iterator it, const char *state) override
 Initialize the item object from the string state. More...
 
void clearItemState (typename ListTemplate< T >::const_iterator it, char *state) const override
 Dispose the string state, which has been previously obtained by getItemState() More...
 
- Protected Member Functions inherited from ml::ListTemplate< T >
- Protected Member Functions inherited from ml::ListBase
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...
 
ListBaseoperator= (const ListBase &list)
 Assignment operator, used in derived list classes. More...
 
- Protected Member Functions inherited from ml::Base

Additional Inherited Members

- Public Types inherited from ml::ListTemplate< T >
typedef T itemType
 Declare type name for item type (this allows declarations like: ObjectList::itemType obj) More...
 
- Public Types inherited from ml::ListBase
enum  ActionClass {
  ActNone = 0 , ActUnknown , ActNew , ActSelect ,
  ActModify , ActDelete , ActInsert , ActInsertOvw ,
  ActNumActions
}
 Constants to describe the type of action most recently performed. More...
 
- Public Types inherited from ml::Base
enum  PersistenceInterface { PersistenceByString , PersistenceByTreeNode , PersistenceByStream }
 This enum describes the different persistence interfaces available. More...
 
- Static Public Attributes inherited from ml::ListBase
static const char *const ActionClassNames [ActNumActions]
 Action class name constants. More...
 

Detailed Description

template<class T>
class ml::BaseListTemplate< T >

Base object template list class for list item classes derived from BaseItem.

List class template (derived from ListTemplate) for list item classes derived from BaseItem. Persistence of the list is based on the corresponding methods of the list class. The list maintains a 'next id' feature to support unique item id's.

To implement an instance of BaseListTemplate with a given type T (where T must be a subclass of BaseItem), the following steps are necessary:

  • Derive a subclass from the template instance class BaseListTemplate<T>
  • Use the ML_CLASS_HEADER and ML_CLASS_SOURCE macros to implement the runtime type system for this class. In the ML_CLASS_SOURCE macro, use ListBase in the base class argument.
  • If persistence is desired for the new class, make sure to initialize the base class with BaseListTemplate<T>(true) in the constructor of the new class. This requires that the persistence methods are properly defined for the item class T.
  • IMPORTANT: Make sure that the item class T has proper copy constructor and assignment operator (these are used by the STL).

Definition at line 721 of file mlListBase.h.

Constructor & Destructor Documentation

◆ BaseListTemplate() [1/3]

template<class T >
ml::BaseListTemplate< T >::BaseListTemplate ( )
inline

Standard constructor, disables persistence.

Definition at line 729 of file mlListBase.h.

◆ BaseListTemplate() [2/3]

template<class T >
ml::BaseListTemplate< T >::BaseListTemplate ( bool  persistance)
inline

Special constructor to explicitly enable/disable persistence.

Definition at line 732 of file mlListBase.h.

◆ BaseListTemplate() [3/3]

template<class T >
ml::BaseListTemplate< T >::BaseListTemplate ( const BaseListTemplate< T > &  other)
inline

Definition at line 734 of file mlListBase.h.

Member Function Documentation

◆ addStateToTree()

template<class T >
void ml::BaseListTemplate< T >::addStateToTree ( TreeNode parent) const
overridevirtual

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

BE SURE TO INCREASE THE VERSION NUMBER IN THE DECLARATION AND ADAPT readStateFromTree() TO THE NEW VERSION WHILE KEEPING IT DOWNWARD- COMPATIBLE!

Reimplemented from ml::ListTemplate< T >.

Definition at line 1015 of file mlListBase.h.

References ml::TreeNode::addChild(), ML_ADDSTATE_SUPER, and ML_ADDSTATE_VERSION.

◆ appendItem()

template<class T >
void ml::BaseListTemplate< T >::appendItem ( const T item)
virtual

Appends an item to the list.

Equivalent to list.doInsertItem(list->getSize(), item);

Definition at line 972 of file mlListBase.h.

◆ clearItemState()

template<class T >
void ml::BaseListTemplate< T >::clearItemState ( typename ListTemplate< T >::const_iterator  it,
char *  state 
) const
inlineoverrideprotectedvirtual

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

Deprecated:

Reimplemented from ml::ListTemplate< T >.

Definition at line 922 of file mlListBase.h.

◆ clearList()

template<class T >
void ml::BaseListTemplate< T >::clearList ( )
inlineoverridevirtual

Clear complete list.

Reimplemented from ml::ListTemplate< T >.

Definition at line 826 of file mlListBase.h.

◆ deleteItemAt()

template<class T >
void ml::BaseListTemplate< T >::deleteItemAt ( MLssize_t  index)
inlineoverridevirtual

This virtual function is reimplemented from ListBase, where it does nothing at all.

(also in ListTemplate<T>, because the items are not necessarily BaseItems there).

Here, the index is simply relayed to doDeleteItem.

Reimplemented from ml::ListBase.

Definition at line 780 of file mlListBase.h.

◆ doDeleteItem()

template<class T >
void ml::BaseListTemplate< T >::doDeleteItem ( MLssize_t  index)
virtual

Delete single item at position index and set the corresponding ActDelete action.

Definition at line 943 of file mlListBase.h.

◆ doInsertItem()

template<class T >
void ml::BaseListTemplate< T >::doInsertItem ( MLssize_t  index,
const T item 
)
virtual

Insert item at position index, assign a new id value to the inserted item and set the corresponding ActInsert action.

Definition at line 956 of file mlListBase.h.

◆ doModifyItem()

template<class T >
void ml::BaseListTemplate< T >::doModifyItem ( MLssize_t  index,
const T item 
)
virtual

Store item at position index and set the corresponding ActModify action.

The id value of the modified item is left unchanged.

Definition at line 981 of file mlListBase.h.

◆ doSelectItem()

template<class T >
void ml::BaseListTemplate< T >::doSelectItem ( MLssize_t  index)
virtual

Select item at position index, or deselect if item == -1, and set the corresponding ActSelect action.

Select item at position index, or deselect if index == -1, and set the corresponding ActSelect action.

Definition at line 997 of file mlListBase.h.

◆ getConstItemAt()

template<class T >
const BaseItem* ml::BaseListTemplate< T >::getConstItemAt ( MLssize_t  index) const
inlineoverridevirtual

Same as getItemAt(MLssize_t index) for constant access.

Reimplemented from ml::ListBase.

Definition at line 751 of file mlListBase.h.

Referenced by ml::PCLMLTools::createPointCloudFromBaseList().

◆ getItemAt()

template<class T >
BaseItem* ml::BaseListTemplate< T >::getItemAt ( MLssize_t  index)
inlineoverridevirtual

This virtual function is reimplemented from ListBase, where it returns 0 in any case (also in ListTemplate<T>, because the items are not necessarily BaseItems there).

Here, the item at the given index is returned. Note that no range checking is done for performance reasons.

Reimplemented from ml::ListBase.

Definition at line 746 of file mlListBase.h.

Referenced by ml::PCLMLTools::convertPointCloudToXMarkerList(), ml::ITKNodeContainerFromBasePointer(), ml::ITKPointSetFromBasePointer(), and ml::ITKPolylineFromBasePointer().

◆ getItemState()

template<class T >
char* ml::BaseListTemplate< T >::getItemState ( typename ListTemplate< T >::const_iterator  it) const
inlineoverrideprotectedvirtual

Return a string representation of the item object.

The string is allocated on the heap and is later disposed by clearItemState().

Deprecated:

Reimplemented from ml::ListTemplate< T >.

Definition at line 908 of file mlListBase.h.

References ml::ListTemplate< T >::persistentState().

◆ getItemTypeId()

template<class T >
const RuntimeType* ml::BaseListTemplate< T >::getItemTypeId ( ) const
inlineoverridevirtual

This virtual function is reimplemented from ListBase, where it returns 0 in any case (also in ListTemplate<T>, because the items are not necessarily BaseItems there).

Reimplemented from ml::ListBase.

Definition at line 795 of file mlListBase.h.

◆ insertItemAt()

template<class T >
void ml::BaseListTemplate< T >::insertItemAt ( MLssize_t  index,
const BaseItem item 
)
inlineoverridevirtual

This virtual function is reimplemented from ListBase, where it does nothing at all.

(also in ListTemplate<T>, because the items are not necessarily BaseItems there).

Here, the item is inserted at the given index, as long as it is of type T.

Reimplemented from ml::ListBase.

Definition at line 759 of file mlListBase.h.

References T.

◆ itemState()

template<class T >
std::string ml::BaseListTemplate< T >::itemState ( typename ListTemplate< T >::const_iterator  it) const
inlineoverrideprotectedvirtual

Return a string representation of the item object.

The string is allocated on the heap and is later disposed by clearItemState().

Reimplemented from ml::ListTemplate< T >.

Definition at line 889 of file mlListBase.h.

References ml::ListTemplate< T >::persistentState().

◆ ML_SET_ADDSTATE_VERSION()

template<class T >
ml::BaseListTemplate< T >::ML_SET_ADDSTATE_VERSION ( )

Set addState version number.

Version History: 0 : adding size and items only 1 : also adding ListBase members (hasPersistence, currentItem);

◆ modifyItemAt()

template<class T >
void ml::BaseListTemplate< T >::modifyItemAt ( MLssize_t  index,
const BaseItem item 
)
inlineoverridevirtual

This virtual function is reimplemented from ListBase, where it does nothing at all.

(also in ListTemplate<T>, because the items are not necessarily BaseItems there).

Here, the item is inserted at the given index, as long as it is of type T.

Reimplemented from ml::ListBase.

Definition at line 770 of file mlListBase.h.

References T.

◆ newId()

template<class T >
virtual MLssize_t ml::BaseListTemplate< T >::newId ( )
inlinevirtual

Get new unused id.

Definition at line 804 of file mlListBase.h.

◆ operator=()

template<class T >
BaseListTemplate<T>& ml::BaseListTemplate< T >::operator= ( const BaseListTemplate< T > &  other)
default

explicitly create default assignment operator

◆ readStateFromTree()

template<class T >
void ml::BaseListTemplate< T >::readStateFromTree ( TreeNode parent)
overridevirtual

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

Reimplemented from ml::ListTemplate< T >.

Definition at line 1040 of file mlListBase.h.

References ML_READCHILD_OPTIONAL, ML_READSTATE_SUPER, T, and ml::TNE_UnsupportedClassVersion.

◆ resetId()

template<class T >
virtual void ml::BaseListTemplate< T >::resetId ( )
inlinevirtual

Reset next id.

Definition at line 815 of file mlListBase.h.

◆ selectItemAt()

template<class T >
void ml::BaseListTemplate< T >::selectItemAt ( MLssize_t  index)
inlineoverridevirtual

This virtual function is reimplemented from ListBase, where it does nothing at all.

(also in ListTemplate<T>, because the items are not necessarily BaseItems there).

Here, the index is simply relayed to doSelectItem.

Reimplemented from ml::ListBase.

Definition at line 788 of file mlListBase.h.

◆ setItemState() [1/2]

template<class T >
void ml::BaseListTemplate< T >::setItemState ( typename ListTemplate< T >::iterator  it,
const char *  state 
)
inlineoverrideprotectedvirtual

Initialize the item object from the string state.

Deprecated:

Reimplemented from ml::ListTemplate< T >.

Definition at line 913 of file mlListBase.h.

References ml::ListTemplate< T >::setPersistentState().

◆ setItemState() [2/2]

template<class T >
void ml::BaseListTemplate< T >::setItemState ( typename ListTemplate< T >::iterator  it,
const std::string &  state 
)
inlineoverrideprotectedvirtual

Initialize the item object from the string state.

Reimplemented from ml::ListTemplate< T >.

Definition at line 895 of file mlListBase.h.

References ml::ListTemplate< T >::setPersistentState().

◆ usedId()

template<class T >
virtual void ml::BaseListTemplate< T >::usedId ( MLssize_t  id)
inlinevirtual

Notify list that id is used.

Definition at line 807 of file mlListBase.h.


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