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

Basic list class template combining properties of ListBase and a vector of the template argument type. More...

#include <mlListBase.h>

Inheritance diagram for ml::ListTemplate< T >:
ml::ListBase ml::Base ml::BaseListTemplate< BaseContainerItem > ml::BaseListTemplate< BaseItem > ml::BaseListTemplate< XMarker > ml::VecListTemplate< Vector3 > ml::VecListTemplate< vec3i > ml::VecListTemplate< Vector4 > ml::VecListTemplate< vec4i > ml::VecListTemplate< Vector6 > ml::VecListTemplate< vec6i > ml::BaseListTemplate< T > ml::VecListTemplate< T >

Public Types

typedef T itemType
 Declare type name for item type (this allows declarations like: ObjectList::itemType obj)
 
- 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...
 

Public Member Functions

Constructors
 ListTemplate ()
 Standard constructor, disables persistence.
 
 ListTemplate (bool persistance)
 Special constructor to explicitly enable/disable persistence.
 
 ListTemplate (const ListTemplate &other)
 
Abstract list access
size_t getSize () const override
 Get number of list elements.
 
void clearList () override
 Clear complete list.
 
ListTemplate< T > & operator= (const ListTemplate< T > &list)
 Assignment operator.
 
ListTemplate< T > * clone () const override
 Create a copy of (*this) using the ML runtime system and the '='-operator.
 
ListTemplate< T > * deepCopy () const override
 Create a deep copy of the list.
 
List persistence

Return a string representation of the list object.

std::string persistentState () const override
 Returns a string describing the object's internal state.
 
void setPersistentState (const std::string &state) override
 Initialize the list object from the string state.
 
void addStateToTree (TreeNode *parent) const override
 Attaches the state as children of the given parent node.
 
 ML_SET_ADDSTATE_VERSION (2)
 Set addState version number, version 2 indicates data saved by a 64 bit version.
 
void readStateFromTree (TreeNode *parent) override
 Reads the object state from the children of the given parent node.
 
- Public Member Functions inherited from ml::ListBase
 ListBase (bool persistance)
 Constructor. Derived class should indicate whether persistence is implemented.
 
 ListBase (const ListBase &other)
 
virtual BaseItemgetItemAt (MLssize_t)
 This virtual function is reimplemented in BaseListTemplate<T>, where it actually returns the item at the given index.
 
virtual const BaseItemgetConstItemAt (MLssize_t) const
 Same as getItemAt(MLssize_t index) for constant access.
 
virtual void insertItemAt (MLssize_t, const BaseItem *)
 This virtual function is reimplemented in BaseListTemplate<T>, where it actually inserts the item at the given index.
 
virtual void modifyItemAt (MLssize_t, const BaseItem *)
 This virtual function is reimplemented in BaseListTemplate<T>, where it actually modifies the item at the given index.
 
virtual void deleteItemAt (MLssize_t)
 This virtual function is reimplemented in BaseListTemplate<T>, where it actually deletes the item at the given index.
 
virtual void selectItemAt (MLssize_t)
 This virtual function is reimplemented in BaseListTemplate<T>, where it actually selects the item at the given index.
 
virtual const RuntimeTypegetItemTypeId () const
 This virtual function is reimplemented in BaseListTemplate<T>, where it actually returns the item class' type id.
 
virtual void setAction (ActionClass actionClass, MLssize_t id, MLssize_t index)
 Set actionClass, affected item id and index.
 
virtual void setAction (ActionClass actionClass)
 Set actionClass for actions affecting the whole list.
 
virtual void getAction (ActionClass &actionClass, MLssize_t &id, MLssize_t &index) const
 Get actionClass, affected item id and index.
 
virtual ActionClass getActionClass () const
 Get actionClass of last action.
 
virtual MLssize_t getActionId () const
 Get id of item affected by last action.
 
virtual MLssize_t getActionIndex () const
 Get index of item affected by last action.
 
virtual MLssize_t getCurrentIndex () const
 Get index of currently selected item, or -1 if no item selected.
 
virtual bool isModified () const
 Tests, if the last action has been an action that has modified the content of the list.
 
virtual bool hasPersistance () const
 Test if persistence is available and enabled.
 
virtual void setPersistance (bool persistance)
 Enable/disable persistence functionality.
 
 ML_SET_ADDSTATE_VERSION (0)
 Set addState version number.
 
- 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.
 
virtual void writeTo (AbstractPersistenceOutputStream *) const
 Write the objects state to the data stream object.
 
virtual void readFrom (AbstractPersistenceInputStream *, int)
 Read the objects state from the data stream object.
 

Protected Member Functions

List item persistence

To implement persistence, overload getItemState() and setItemState().

Make sure that the string returned by getItemState() can be disposed by clearItemState(), or otherwise overload clearItemState() appropriately. The item's string representation may contain any character, including those used in the list string syntax: [],". The list persistence methods take care of quoting the item strings if necessary.

virtual std::string itemState (typename ListTemplate< T >::const_iterator it) const
 Return a string representation of the item object.
 
virtual void setItemState (typename ListTemplate< T >::iterator, const std::string &)
 Initialize the item object from the string state.
 
- Protected Member Functions inherited from ml::ListBase
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()
 
ListBaseoperator= (const ListBase &list)
 Assignment operator, used in derived list classes.
 

Additional Inherited Members

- Static Public Attributes inherited from ml::ListBase
static const char *const ActionClassNames [ActNumActions]
 Action class name constants.
 

Detailed Description

template<class T>
class ml::ListTemplate< T >

Basic list class template combining properties of ListBase and a vector of the template argument type.

Basic list class template (derived from ListBase and std::vector) combining properties of ListBase and a vector of the template argument type. Implements persistence methods that iterate through the vector items and call corresponding persistence methods for each item.

To implement an instance of ListTemplate with a given type T, the following steps are necessary:

  • Derive a subclass from the template instance class ListTemplate<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 ListTemplate<T>(true) in the constructor of the new class.
  • If desired, implement persistence for the item class T by overloading getItemState() and setItemState(). Make sure that the string returned by getItemState() can be disposed by deleteString(), or otherwise overload clearItemState() appropriately.
  • IMPORTANT: Make sure that the item class T has proper copy constructor and assignment operator (these are used by the STL).

Definition at line 311 of file mlListBase.h.

Member Typedef Documentation

◆ itemType

template<class T >
typedef T ml::ListTemplate< T >::itemType

Declare type name for item type (this allows declarations like: ObjectList::itemType obj)

Definition at line 317 of file mlListBase.h.

Constructor & Destructor Documentation

◆ ListTemplate() [1/3]

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

Standard constructor, disables persistence.

Definition at line 324 of file mlListBase.h.

◆ ListTemplate() [2/3]

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

Special constructor to explicitly enable/disable persistence.

Definition at line 327 of file mlListBase.h.

◆ ListTemplate() [3/3]

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

Definition at line 329 of file mlListBase.h.

Member Function Documentation

◆ addStateToTree()

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

Attaches the 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::ListBase.

Definition at line 510 of file mlListBase.h.

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

◆ clearList()

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

Clear complete list.

Reimplemented from ml::ListBase.

Definition at line 342 of file mlListBase.h.

◆ clone()

template<class T >
ListTemplate< T > * ml::ListTemplate< T >::clone ( ) const
overridevirtual

Create a copy of (*this) using the ML runtime system and the '='-operator.

Create a copy of (*this) using the ML runtime system.

Overwrite in derived classes if copying the list is not equivalent to copying the object (for instance, if the derived class has a global list description member). Returns NULL if a copy could not be created, or the cloned list otherwise.

Reimplemented from ml::ListBase.

Definition at line 602 of file mlListBase.h.

References ml::RuntimeType::canCreateInstance(), and mlrange_cast().

◆ deepCopy()

template<class T >
ListTemplate< T > * ml::ListTemplate< T >::deepCopy ( ) const
inlineoverridevirtual

Create a deep copy of the list.

Reimplemented from ml::ListBase.

Definition at line 364 of file mlListBase.h.

◆ getSize()

template<class T >
size_t ml::ListTemplate< T >::getSize ( ) const
inlineoverridevirtual

Get number of list elements.

Implements ml::ListBase.

Definition at line 338 of file mlListBase.h.

Referenced by ml::VecListTemplate< T >::itemState().

◆ itemState()

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

Return a string representation of the item object.

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

Reimplemented in ml::BaseListTemplate< T >.

Definition at line 406 of file mlListBase.h.

◆ ML_SET_ADDSTATE_VERSION()

template<class T >
ml::ListTemplate< T >::ML_SET_ADDSTATE_VERSION ( 2 )

Set addState version number, version 2 indicates data saved by a 64 bit version.

◆ operator=()

template<class T >
ListTemplate< T > & ml::ListTemplate< T >::operator= ( const ListTemplate< T > & list)
inline

Assignment operator.

Definition at line 347 of file mlListBase.h.

◆ persistentState()

template<class T >
std::string ml::ListTemplate< T >::persistentState ( ) const
overridevirtual

Returns a string describing the object's internal state.

Reimplemented from ml::Base.

Definition at line 422 of file mlListBase.h.

References mlrange_cast().

◆ readStateFromTree()

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

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

Reimplemented from ml::ListBase.

Definition at line 538 of file mlListBase.h.

References ML_READCHILD_OPTIONAL, ML_READSTATE_SUPER, mlrange_cast(), T, and ml::TNE_UnsupportedClassVersion.

◆ setItemState()

template<class T >
virtual void ml::ListTemplate< T >::setItemState ( typename ListTemplate< T >::iterator ,
const std::string &  )
inlineprotectedvirtual

Initialize the item object from the string state.

Reimplemented in ml::BaseListTemplate< T >.

Definition at line 412 of file mlListBase.h.

◆ setPersistentState()

template<class T >
void ml::ListTemplate< T >::setPersistentState ( const std::string & state)
overridevirtual

Initialize the list object from the string state.

Reimplemented from ml::Base.

Definition at line 465 of file mlListBase.h.

References ML_EMPTY_MESSAGE, ML_PRINT_ERROR, mlrange_cast(), and T.


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