MeVisLab Toolbox Reference
mlListBase.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_LIST_BASE_H
14#define ML_LIST_BASE_H
15
16
18
19// Defines the following classes:
20// - ListBase: An abstract class derived from Base providing methods available
21// for all list classes.
22// - ListTemplate: A class template derived from ListBase and std::vector.
23// It implements the persistence functionality of a list.
24// - BaseListTemplate: A class template derived from ListTemplate. It should be
25// used for item classes that are subclasses of BaseItem.
26// - For class BaseItem see mlBaseItem.h.
27
28// ML-includes
29#include "mlBaseInit.h"
30#include "mlModuleIncludes.h"
31#include "mlTreeNode.h"
32#include "mlStringConversion.h"
33
34
35
36#include "mlListParser.h"
37
38// Also include BaseItem although it is not needed here; however many derived classes still expect it.
39#include "mlBaseItem.h"
40
41// Safe casts.
42#include "mlRangeCasts.h"
43
44#include <algorithm>
45
46ML_START_NAMESPACE
47
48class BaseItem;
49class ListContainerBase;
50
51// ------------------------------------------------------------------
53// ------------------------------------------------------------------
54
64{
65public:
66
68 ListBase (bool persistence)
69 : _hasPersistence(persistence),
70 _actionClass(ActNew),
71 _actionId(-1),
72 _actionIndex(-1),
73 _currentIndex(-1),
74 _container(nullptr)
75 {}
76
77 ListBase(const ListBase& other)
78 : _hasPersistence(other.hasPersistence()),
79 _actionClass(other.getActionClass()),
80 _actionId(other.getActionId()),
81 _actionIndex(other.getActionIndex()),
82 _currentIndex(other.getCurrentIndex()),
83 _container(nullptr)
84 {}
85
88
90 virtual size_t getSize () const = 0;
91
97 virtual BaseItem* getItemAt(MLssize_t /*index*/) { return nullptr; };
98
100 virtual const BaseItem* getConstItemAt(MLssize_t /*index*/) const { return nullptr; };
101
105 virtual void insertItemAt(MLssize_t /*index*/, const BaseItem* /*item*/) {};
106
110 virtual void modifyItemAt(MLssize_t /*index*/, const BaseItem* /*item*/) {};
111
115 virtual void deleteItemAt(MLssize_t /*index*/) {};
116
120 virtual void selectItemAt(MLssize_t /*index*/) {};
121
125 virtual const RuntimeType* getItemTypeId() const { return nullptr; };
126
128 virtual void clearList ()
129 { setAction(ActNew); }
130
137 virtual ListBase* clone() const { return nullptr; };
138
140 ListBase* deepCopy() const override { return clone(); };
141
143
144 void setContainer(ListContainerBase* container) { _container = container; }
145 ListContainerBase* getContainer() const { return _container; }
146
155
157 virtual bool hasPersistence() const { return _hasPersistence; }
158
160 virtual void setPersistence(bool persistence) { _hasPersistence = persistence; }
161
164 [[deprecated("Use hasPersistence() instead.")]]
165 bool hasPersistance () const { return hasPersistence(); }
168 [[deprecated("Use setPersistence(bool persistence) instead.")]]
169 void setPersistance (bool persistence) { setPersistence(persistence); }
170
172 MLBASEEXPORT friend std::ostream& operator << (std::ostream &s, const ListBase &list);
173
175 void addStateToTree(TreeNode* parent) const override;
176
179
181 void readStateFromTree(TreeNode* parent) override;
182
184
185
199
202 {
203 ActNone = 0,
206 ActSelect,
209 ActDelete,
212 ActInsertOvw,
216 ActNumActions
217 };
218
220 static const char *const ActionClassNames[ActNumActions];
221
223 virtual void setAction (ActionClass actionClass, MLssize_t id, MLssize_t index);
224
226 virtual void setAction (ActionClass actionClass)
227 { setAction(actionClass, -1, -1); }
228
230 virtual void getAction (ActionClass &actionClass, MLssize_t &id, MLssize_t &index) const;
231
234 { return _actionClass; }
235
237 virtual MLssize_t getActionId () const
238 { return _actionId; }
239
243 virtual MLssize_t getActionIndex () const
244 { return _actionIndex; }
245
247 virtual MLssize_t getCurrentIndex () const
248 { return _currentIndex; }
249
251 virtual bool isModified () const
252 { return (ActSelect != _actionClass && ActNone != _actionClass); }
253
254
256
257
258protected:
259
263 char *newString (const std::string &str) const
264 { return ParserBase::newString(str); }
265
267 void deleteString (char *str) const
269
271 ListBase &operator = (const ListBase &list);
272
273private:
274
276 bool _hasPersistence;
277
279 ActionClass _actionClass;
280
282 MLssize_t _actionId;
283
285 MLssize_t _actionIndex;
286
288 MLssize_t _currentIndex;
289
290 ListContainerBase* _container;
291
293
294};
295
296
297
298// ------------------------------------------------------------------
300// ------------------------------------------------------------------
301
325template <class T>
326class ListTemplate : public ListBase, public std::vector<T>
327{
328public:
329
332 typedef T itemType;
333
334
337
339 ListTemplate () : ListBase(false) {}
340
342 ListTemplate (bool persistence) : ListBase(persistence) {}
343
344 ListTemplate(const ListTemplate& other) : ListBase(other), std::vector<T>(other) {}
345
347
348
351
353 size_t getSize () const override
354 { using namespace std; return vector<T>::size(); }
355
357 void clearList () override
358 { ListBase::clearList(); using namespace std; vector<T>::clear(); }
359
360
362 ListTemplate<T> &operator = (const ListTemplate<T> &list)
363 {
364 using namespace std;
365
366 ListBase::operator =(list);
367 vector<T>::operator =(list);
368
369 return *this;
370 }
371
376 ListTemplate<T>* clone() const override;
377
379 ListTemplate<T>* deepCopy() const override { return clone(); };
380
382
383
387 std::string persistentState() const override;
388
390 void setPersistentState(const std::string& state) override;
391
392
393public:
394
396 void addStateToTree(TreeNode* parent) const override;
397
400
402 void readStateFromTree(TreeNode* parent) override;
403
405
406protected:
407
418
421 virtual std::string itemState([[maybe_unused]] typename ListTemplate<T>::const_iterator it) const
422 {
423 return {};
424 }
425
427 virtual void setItemState(typename ListTemplate<T>::iterator /*it*/, const std::string& /*state*/) {}
428};
429
430
431
432// ------------------------------------------------------------------
433// Implementation of ListTemplate
434// ------------------------------------------------------------------
435
436template <class T>
438{
439 std::string listStr;
440
441 using namespace std;
442
443 if (hasPersistence())
444 {
445 // Start list with an opening bracket
446 listStr = "[";
447
448 // Iterate through list
449 for (auto it = vector<T>::begin(); it != vector<T>::end(); ++it)
450 {
451 // Separate items by a comma
452 if (it != vector<T>::begin()) {
453 listStr += ", ";
454 }
455
456 // Get string representation for item object
457 auto itemStr = itemState(it);
458 if (!itemStr.empty())
459 {
460 if (ListParser::needsQuote(itemStr))
461 {
462 listStr += ListParser::quoteString(itemStr);
463 }
464 else {
465 listStr += itemStr;
466 }
467 }
468 else
469 // Empty item string, add "" to list string
470 listStr += "\"\"";
471 }
472
473 // End list with a closing bracket
474 listStr += ']';
475 }
476
477 return listStr;
478}
479
480template <class T> void ListTemplate<T>::setPersistentState(const std::string &state)
481{
482 using namespace std;
483
484 if (hasPersistence())
485 {
486 ListParser parser;
487
488 // Start with empty list
489 clearList();
490
491 // Initialize parser
492 auto parserResult = parser.init(state.c_str());
493
494 while (!parserResult)
495 {
496 // Parse next item string
497 std::string itemString;
498 std::tie(parserResult, itemString) = parser.nextItem();
499 if (!itemString.empty() && parserResult != ListParser::kEndOfSource)
500 {
501 // Append new item object at end of list
502 vector<T>::insert(vector<T>::end(), T());
503
504 // Restore item object from item string
505 setItemState(vector<T>::end() - 1, itemString);
506 }
507 }
508
509 // Set list action
510 setAction(ListBase::ActNew);
511
512 // Print error message to console
513 if (parserResult > 0 && parserResult != ParserBase::kEmptyString) {
514 ML_PRINT_ERROR("ListTemplate::setPersistentState()", ML_EMPTY_MESSAGE,
515 parser.getErrorMessage(parserResult));
516 }
517 }
518}
519
520
524template <class T>
526{
527 using namespace std;
528
529 //if (!hasPersistence()) return;
530
532
533 // add listbase members
535
536 // write list size always as unsigned 64 bit integer.
537 parent->addChild(static_cast<MLuint64>(vector<T>::size()), "ListSize");
538
539 // write list items:
540 TreeNode* items = parent->addChild("ListItems");
541
542 // Iterate through list
543 for (auto it = vector<T>::cbegin(); it != vector<T>::cend(); ++it)
544 {
545 auto state = itemState(it);
546 items->addChild(state, "Item");
547 }
548
549}
550
552template <class T>
554{
555 using namespace std;
556
557 if (!hasPersistence()) { return; }
558
559 int version = parent->getVersion("ListTemplate");
560
561 // Currently supporting version <= 2 only, version 2 is saved by 64 bit systems.
562 if (version > 2){
563 // Error, too high version number.
565 }
566
567 if (version >= 1) {
568 // ListBase saves its members since version 1:
570 }
571
572 bool endLoop = false;
573
574 clearList();
575
576 // read size if possible
577 MLuint64 loadedSize = 0;
578 ML_READCHILD_OPTIONAL(loadedSize, "ListSize", 0);
579
580 // reserve some memory for the list. However, we do really want to rely on the ListSize
581 // setting and still read until a child is not found.
582 vector<T>::reserve( loadedSize );
583
584 TreeNode* items = parent->readContainerChild("ListItems");
585
586 std::string currStr;
587 do {
588 // try to read next child:
589 if (items->hasChild()) {
590 items->readChild(currStr);
591 } else {
592 // break free from loop
593 endLoop = true;
594 }
595 if (!endLoop) {
596
597 vector<T>::insert(vector<T>::end(), T());
598
599 // Restore item object from item string
600 setItemState(vector<T>::end()-1, currStr);
601
602 currStr = {};
603 }
604 } while (!endLoop);
605
606 // Set list action
607 setAction(ListBase::ActNew);
608}
609
610
611
616template <class T>
618{
619 // get runtime type of this instance
620 const RuntimeType* thisType = this->getTypeId();
621
622 // valid type?
623 if (!thisType || !thisType->canCreateInstance()) {
624 // invalid type
625 return nullptr;
626 }
627
628 ListTemplate<T>* newList = static_cast<ListTemplate<T>*>(thisType->createInstance());
629 if (!newList) {
630 // object creation failed
631 return nullptr;
632 }
633
634 (*newList) = (*this);
635
636 return newList;
637}
638
639
640
641
642
643// ------------------------------------------------------------------
645// ------------------------------------------------------------------
646
667template <class T>
669{
670public:
671
674
676 BaseListTemplate () : ListTemplate<T>(), _nextId(1) {}
677
679 BaseListTemplate (bool persistence) : ListTemplate<T>(persistence), _nextId(1) {}
680
681 BaseListTemplate(const BaseListTemplate& other) : ListTemplate<T>(other), _nextId(other._nextId) {}
682
684
687
693 BaseItem* getItemAt(MLssize_t index) override{
694 return &(*this)[mlrange_cast<size_t>(index)];
695 };
696
698 const BaseItem* getConstItemAt(MLssize_t index) const override {
699 return &(*this)[mlrange_cast<size_t>(index)];
700 };
701
706 void insertItemAt(MLssize_t index, const BaseItem* item) override {
707 if (item && (getItemTypeId() == item->getTypeId())) {
708 doInsertItem(index, *static_cast<const T*>(item) );
709 }
710 };
711
712
717 void modifyItemAt(MLssize_t index, const BaseItem* item) override {
718 if (item && (getItemTypeId() == item->getTypeId())) {
719 doModifyItem(index, *static_cast<const T*>(item) );
720 }
721 };
722
727 void deleteItemAt(MLssize_t index) override {
728 doDeleteItem(index);
729 };
730
735 void selectItemAt(MLssize_t index) override {
736 doSelectItem(index);
737 };
738
742 const RuntimeType* getItemTypeId() const override {
743 return T::getClassTypeId();
744 }
745
746
749
751 virtual MLssize_t newId () { return _nextId++; }
752
754 virtual void usedId (MLssize_t id)
755 {
756 if (id >= _nextId) {
757 _nextId = id+1;
758 }
759 }
760
762 virtual void resetId ()
763 {
764 _nextId = 1;
765 for (typename ListTemplate<T>::iterator it = ListTemplate<T>::begin(); it != ListTemplate<T>::end(); it++){
766 usedId(it->getId());
767 }
768 }
769
771
773 void clearList () override
774 {
776 resetId();
777 }
778
779
789
791 virtual void doDeleteItem (MLssize_t index);
792
795 virtual void doInsertItem (MLssize_t index, const T &item);
796
799 virtual void doModifyItem (MLssize_t index, const T &item);
800
803 virtual void doSelectItem (MLssize_t index);
804
807 virtual void appendItem(const T &item);
808
810 void addStateToTree(TreeNode* parent) const override;
811
813
818
820 void readStateFromTree(TreeNode* parent) override;
821
822
823
825
826
827protected:
828
836 std::string itemState(typename ListTemplate<T>::const_iterator it) const override
837 {
838 return it->persistentState();
839 }
840
842 void setItemState(typename ListTemplate<T>::iterator it, const std::string& state) override
843 {
844 it->setPersistentState(state);
845 usedId(it->getId());
846 }
847
848private:
849
851 MLssize_t _nextId;
852
853};
854
855
856
857
858// ------------------------------------------------------------------
859// --- Implementation of BaseListTemplate
860// ------------------------------------------------------------------
861
863template <class T>
865{
866 if ((index >= 0) && (index < static_cast<MLssize_t>(ListTemplate<T>::size())) )
867 {
868 this->setAction(ListTemplate<T>::ActDelete, (*this)[mlrange_cast<size_t>(index)].getId(), index);
870 }
871}
872
873
876template <class T>
878{
879 MLssize_t id=0;
880
881 if ((index >= 0) && (index <= mlrange_cast<MLssize_t>(ListTemplate<T>::size())) )
882 {
884 id = newId();
885 (*this)[static_cast<size_t>(index)].setId(id);
886 this->setAction(ListTemplate<T>::ActInsert, id, index);
887 }
888}
889
892template <class T>
894{
895 doInsertItem(static_cast<MLssize_t>(ListTemplate<T>::size()), item);
896}
897
898
901template <class T>
903{
904 if ((index >= 0) && (index < mlrange_cast<MLssize_t>(ListTemplate<T>::size())) )
905 {
906 const size_t idx_size_t = static_cast<size_t>(index);
907 const MLssize_t id = (*this)[idx_size_t].getId();
908 (*this)[idx_size_t] = item;
909 (*this)[idx_size_t].setId(id);
910 this->setAction(ListTemplate<T>::ActModify, id, index);
911 }
912}
913
914
917template <class T>
919{
920 if ((index >= 0) && (index < mlrange_cast<MLssize_t>(ListTemplate<T>::size())) )
921 {
922 this->setAction(ListTemplate<T>::ActSelect, (*this)[static_cast<size_t>(index)].getId(), index);
923 }
924 else if (index == -1)
925 {
926 // deselect all
927 this->setAction(ListTemplate<T>::ActSelect);
928 }
929}
930
931
935template <class T>
937{
939
940 // add ListBase members
942
944 MLuint64 i = 0;
945
946 // write list size
947 parent->addChild(static_cast<MLuint64>(ListTemplate<T>::size()), "ListSize");
948
949 TreeNode* items = parent->addChild("ListItems");
950
951 // Iterate through list
952 for (it = ListTemplate<T>::begin(); it != ListTemplate<T>::end(); it++, i++)
953 {
954 items->addChild(&(*it), "Item", false);
955 }
956
957}
958
960template <class T>
962{
963 int version = parent->getVersion("BaseListTemplate");
964
965 // Currently supporting version <= 2 only, version 2 is 64 bit version.
966 if (version > 2) {
968 }
969
970 if (version >= 1) {
971 // ListBase saves its members since version 1:
973 }
974
975 bool endLoop = false;
976
977 clearList(); // includes _nextId = 1;
978
979 // read size if possible
980 MLuint64 loadedSize = 0;
981 ML_READCHILD_OPTIONAL(loadedSize, "ListSize", 0);
982
983 // reserve some memory for the list. However, we do not really want to rely on the ListSize
984 // setting and still read until a child is not found.
985 ListTemplate<T>::reserve( loadedSize );
986
987 TreeNode* items = parent->readContainerChild("ListItems");
988
989 if (items) do {
990 // try to read next child:
991 if (items->hasChild()) {
993 items->readChild(*(ListTemplate<T>::end()-1));
994 } else {
995 // break free from loop
996 endLoop = true;
997 }
998 if (ListTemplate<T>::size() > 0){
999 // update _nextId:
1000 _nextId = std::max(_nextId, (ListTemplate<T>::end()-1)->getId() + 1);
1001 } else {
1002 endLoop = true;
1003 }
1004 } while (!endLoop);
1005
1006 // Set list action
1007 this->setAction(ListTemplate<T>::ActNew);
1008}
1009
1010
1011ML_END_NAMESPACE
1012
1013
1014#endif
@ T
General Base object class for list items that have an id and a name.
Definition mlBaseItem.h:38
Base object template list class for list item classes derived from BaseItem.
Definition mlListBase.h:669
void deleteItemAt(MLssize_t index) override
This virtual function is reimplemented from ListBase, where it does nothing at all.
Definition mlListBase.h:727
virtual MLssize_t newId()
Get new unused id.
Definition mlListBase.h:751
void setItemState(typename ListTemplate< T >::iterator it, const std::string &state) override
Initialize the item object from the string state.
Definition mlListBase.h:842
BaseListTemplate()
Standard constructor, disables persistence.
Definition mlListBase.h:676
void addStateToTree(TreeNode *parent) const override
Attaches the object state as children of the given parent node.
Definition mlListBase.h:936
void modifyItemAt(MLssize_t index, const BaseItem *item) override
This virtual function is reimplemented from ListBase, where it does nothing at all.
Definition mlListBase.h:717
ML_SET_ADDSTATE_VERSION(1)
Set addState version number.
virtual void doDeleteItem(MLssize_t index)
Delete single item at position index and set the corresponding ActDelete action.
Definition mlListBase.h:864
std::string itemState(typename ListTemplate< T >::const_iterator it) const override
Return a string representation of the item object.
Definition mlListBase.h:836
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 A...
Definition mlListBase.h:877
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
Definition mlListBase.h:961
BaseListTemplate< T > & operator=(const BaseListTemplate &other)=default
explicitly create default assignment operator
virtual void appendItem(const T &item)
Appends an item to the list.
Definition mlListBase.h:893
BaseItem * getItemAt(MLssize_t index) override
This virtual function is reimplemented from ListBase, where it returns 0 in any case (also in ListTem...
Definition mlListBase.h:693
BaseListTemplate(bool persistence)
Special constructor to explicitly enable/disable persistence.
Definition mlListBase.h:679
const BaseItem * getConstItemAt(MLssize_t index) const override
Same as getItemAt(MLssize_t index) for constant access.
Definition mlListBase.h:698
BaseListTemplate(const BaseListTemplate &other)
Definition mlListBase.h:681
void selectItemAt(MLssize_t index) override
This virtual function is reimplemented from ListBase, where it does nothing at all.
Definition mlListBase.h:735
void insertItemAt(MLssize_t index, const BaseItem *item) override
This virtual function is reimplemented from ListBase, where it does nothing at all.
Definition mlListBase.h:706
virtual void doSelectItem(MLssize_t index)
Select item at position index, or deselect if item == -1, and set the corresponding ActSelect action.
Definition mlListBase.h:918
virtual void usedId(MLssize_t id)
Notify list that id is used.
Definition mlListBase.h:754
void clearList() override
Clear complete list.
Definition mlListBase.h:773
virtual void resetId()
Reset next id.
Definition mlListBase.h:762
const RuntimeType * getItemTypeId() const override
This virtual function is reimplemented from ListBase, where it returns 0 in any case (also in ListTem...
Definition mlListBase.h:742
virtual void doModifyItem(MLssize_t index, const T &item)
Store item at position index and set the corresponding ActModify action.
Definition mlListBase.h:902
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:59
Base object class ListBase managing a number of BaseItem objects.
Definition mlListBase.h:64
virtual void clearList()
Clear complete list.
Definition mlListBase.h:128
virtual MLssize_t getActionId() const
Get id of item affected by last action.
Definition mlListBase.h:237
virtual void setPersistence(bool persistence)
Enable/disable persistence functionality.
Definition mlListBase.h:160
char * newString(const std::string &str) const
Convenience method to create a copy of the string str allocated on the heap.
Definition mlListBase.h:263
virtual MLssize_t getActionIndex() const
Get index of item affected by last action.
Definition mlListBase.h:243
ListBase(bool persistence)
Constructor. Derived class should indicate whether persistence is implemented.
Definition mlListBase.h:68
ListBase * deepCopy() const override
Create a deep copy of the list.
Definition mlListBase.h:140
ML_SET_ADDSTATE_VERSION(0)
Set addState version number.
virtual const RuntimeType * getItemTypeId() const
This virtual function is reimplemented in BaseListTemplate<T>, where it actually returns the item cla...
Definition mlListBase.h:125
ActionClass
Constants to describe the type of action most recently performed.
Definition mlListBase.h:202
@ ActInsert
List item inserted.
Definition mlListBase.h:211
@ ActModify
Current list item modified.
Definition mlListBase.h:208
@ ActNew
New list generated.
Definition mlListBase.h:205
@ ActUnknown
Unknown action.
Definition mlListBase.h:204
virtual void selectItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually selects the item at ...
Definition mlListBase.h:120
virtual MLssize_t getCurrentIndex() const
Get index of currently selected item, or -1 if no item selected.
Definition mlListBase.h:247
ListContainerBase * getContainer() const
Definition mlListBase.h:145
virtual void deleteItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually deletes the item at ...
Definition mlListBase.h:115
virtual bool isModified() const
Tests, if the last action has been an action that has modified the content of the list.
Definition mlListBase.h:251
virtual size_t getSize() const =0
Get number of list elements.
virtual const BaseItem * getConstItemAt(MLssize_t) const
Same as getItemAt(MLssize_t index) for constant access.
Definition mlListBase.h:100
void addStateToTree(TreeNode *parent) const override
Attaches the state as children of the given parent node.
virtual ActionClass getActionClass() const
Get actionClass of last action.
Definition mlListBase.h:233
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
virtual void setAction(ActionClass actionClass, MLssize_t id, MLssize_t index)
Set actionClass, affected item id and index.
virtual void getAction(ActionClass &actionClass, MLssize_t &id, MLssize_t &index) const
Get actionClass, affected item id and index.
void setPersistance(bool persistence)
Definition mlListBase.h:169
virtual void setAction(ActionClass actionClass)
Set actionClass for actions affecting the whole list.
Definition mlListBase.h:226
virtual BaseItem * getItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually returns the item at ...
Definition mlListBase.h:97
virtual ListBase * clone() const
Create a copy of (*this) using the ML runtime system and the '='-operator.
Definition mlListBase.h:137
void deleteString(char *str) const
Dispose a string allocated with newString()
Definition mlListBase.h:267
ListBase(const ListBase &other)
Definition mlListBase.h:77
void setContainer(ListContainerBase *container)
Definition mlListBase.h:144
virtual void modifyItemAt(MLssize_t, const BaseItem *)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually modifies the item at...
Definition mlListBase.h:110
virtual void insertItemAt(MLssize_t, const BaseItem *)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually inserts the item at ...
Definition mlListBase.h:105
virtual bool hasPersistence() const
Test if persistence is available and enabled.
Definition mlListBase.h:157
bool hasPersistance() const
Definition mlListBase.h:165
Abstract module class ListContainerBase implementing basic functionality for a list container module.
Parser class for parsing persistent state strings of list objects.
const char * getErrorMessage(int errorCode) override
Get error string for errorCode.
std::pair< int, std::string > nextItem()
Return a string to next item's substring Return codes:
int init(const char *source) override
Initialize parser and proceed to first character of first item.
Basic list class template combining properties of ListBase and a vector of the template argument type...
Definition mlListBase.h:327
virtual void setItemState(typename ListTemplate< T >::iterator, const std::string &)
Initialize the item object from the string state.
Definition mlListBase.h:427
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.
Definition mlListBase.h:553
ListTemplate()
Standard constructor, disables persistence.
Definition mlListBase.h:339
size_t getSize() const override
Get number of list elements.
Definition mlListBase.h:353
ListTemplate< T > * clone() const override
Create a copy of (*this) using the ML runtime system and the '='-operator.
Definition mlListBase.h:617
T itemType
Declare type name for item type (this allows declarations like: ObjectList::itemType obj)
Definition mlListBase.h:332
void clearList() override
Clear complete list.
Definition mlListBase.h:357
virtual std::string itemState(typename ListTemplate< T >::const_iterator it) const
Return a string representation of the item object.
Definition mlListBase.h:421
void addStateToTree(TreeNode *parent) const override
Attaches the state as children of the given parent node.
Definition mlListBase.h:525
ListTemplate(bool persistence)
Special constructor to explicitly enable/disable persistence.
Definition mlListBase.h:342
ListTemplate(const ListTemplate &other)
Definition mlListBase.h:344
void setPersistentState(const std::string &state) override
Initialize the list object from the string state.
Definition mlListBase.h:480
ListTemplate< T > * deepCopy() const override
Create a deep copy of the list.
Definition mlListBase.h:379
std::string persistentState() const override
Returns a string describing the object's internal state.
Definition mlListBase.h:437
static char * newString(const std::string &str)
Convenience method to create a copy of the string str allocated on the heap.
static void deleteString(char *str)
Dispose a string allocated with newString()
RuntimeType contains type and inheritance information of a class and a static dictionary with informa...
bool canCreateInstance() const
Returns true if this (runtime) type knows how to create an instance of the class.
void * createInstance() const
Creates and returns an instance of the of the class or NULL if such an instance is unavailable.
The class TreeNodeException is the base class for all exceptions thrown by the class TreeNode and all...
Definition mlTreeNode.h:95
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition mlTreeNode.h:154
virtual void addChild(bool val, const char *name) ADD_ULONG_CHILD
Factory method for adding a child encapsulating a variable of type bool.
#define ML_ABSTRACT_CLASS_HEADER(className)
Similar to ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non-existing export symbol.
#define ML_EMPTY_MESSAGE
The following error message describes more precise what has happened; if not, then a non-registered e...
Definition mlTypeDefs.h:794
#define ML_PRINT_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped.
#define MLBASEEXPORT
defined Header file mlBaseInit.h
Definition mlBaseInit.h:22
#define ML_READCHILD_OPTIONAL(obj, tagName, defaultVal)
Convenience macro that can be used to read an optional child with name tagName into obj and assign a ...
Definition mlTreeNode.h:651
#define ML_ADDSTATE_VERSION(ThisClass)
Use this macro in addStateToTree() for classes that might need versioning in the future.
Definition mlTreeNode.h:660
#define ML_ADDSTATE_SUPER(SuperClass)
Use this macro if you would like to store your superclass members as well.
Definition mlTreeNode.h:664
#define ML_READSTATE_SUPER(SuperClass)
Use this macro if you would like to store your superclass members as well.
Definition mlTreeNode.h:671
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
Definition mlTypeDefs.h:424
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
Definition mlTypeDefs.h:565
std::ostream & operator<<(std::ostream &out, const KeyFrame &frame)
KeyFrame stream output.
@ TNE_UnsupportedClassVersion
Definition mlTreeNode.h:73
STL namespace.