MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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#include "mlListParser.h"
36
37// Also include BaseItem although it is not needed here; however many derived classes still expect it.
38#include "mlBaseItem.h"
39
40// Safe casts.
41#include "mlRangeCasts.h"
42
43#include <algorithm>
44
46
47class BaseItem;
48class ListContainerBase;
49
50// ------------------------------------------------------------------
52// ------------------------------------------------------------------
53
63{
64public:
67 : _hasPersistence(persistence)
68 , _actionClass(ActNew)
69 , _actionId(-1)
70 , _actionIndex(-1)
71 , _currentIndex(-1)
72 , _container(nullptr)
73 {}
74
76 : _hasPersistence(other.hasPersistence())
77 , _actionClass(other.getActionClass())
78 , _actionId(other.getActionId())
79 , _actionIndex(other.getActionIndex())
80 , _currentIndex(other.getCurrentIndex())
81 , _container(nullptr)
82 {}
83
86
88 virtual size_t getSize() const = 0;
89
95 virtual BaseItem* getItemAt(MLssize_t /*index*/)
96 {
97 return nullptr;
98 };
99
101 virtual const BaseItem* getConstItemAt(MLssize_t /*index*/) const
102 {
103 return nullptr;
104 };
105
109 virtual void insertItemAt(MLssize_t /*index*/, const BaseItem* /*item*/) {};
110
114 virtual void modifyItemAt(MLssize_t /*index*/, const BaseItem* /*item*/) {};
115
119 virtual void deleteItemAt(MLssize_t /*index*/){};
120
124 virtual void selectItemAt(MLssize_t /*index*/){};
125
129 virtual const RuntimeType* getItemTypeId() const
130 {
131 return nullptr;
132 };
133
135 virtual void clearList()
136 {
137 setAction(ActNew);
138 }
139
146 virtual ListBase* clone() const
147 {
148 return nullptr;
149 };
150
152 ListBase* deepCopy() const override
153 {
154 return clone();
155 };
156
158
160 {
161 _container = container;
162 }
164 {
165 return _container;
166 }
167
176
178 virtual bool hasPersistence() const
179 {
180 return _hasPersistence;
181 }
182
184 virtual void setPersistence(bool persistence)
185 {
186 _hasPersistence = persistence;
187 }
188
191 [[deprecated("Use hasPersistence() instead.")]]
192 bool hasPersistance() const
193 {
194 return hasPersistence();
195 }
198 [[deprecated("Use setPersistence(bool persistence) instead.")]]
200 {
201 setPersistence(persistence);
202 }
203
205 MLBASEEXPORT friend std::ostream& operator<<(std::ostream& s, const ListBase& list);
206
208 void addStateToTree(TreeNode* parent) const override;
209
212
214 void readStateFromTree(TreeNode* parent) override;
215
217
218
232
235 ActNone = 0,
238 ActSelect,
241 ActDelete,
244 ActInsertOvw,
248 ActNumActions
249 };
250
252 static const char* const ActionClassNames[ActNumActions];
253
256
259 {
260 setAction(actionClass, -1, -1);
261 }
262
264 virtual void getAction(ActionClass& actionClass, MLssize_t& id, MLssize_t& index) const;
265
268 {
269 return _actionClass;
270 }
271
273 virtual MLssize_t getActionId() const
274 {
275 return _actionId;
276 }
277
281 virtual MLssize_t getActionIndex() const
282 {
283 return _actionIndex;
284 }
285
288 {
289 return _currentIndex;
290 }
291
293 virtual bool isModified() const
294 {
295 return (ActSelect != _actionClass && ActNone != _actionClass);
296 }
297
298
300
301
302protected:
306 char* newString(const std::string& str) const
307 {
309 }
310
312 void deleteString(char* str) const
313 {
315 }
316
319
320private:
322 bool _hasPersistence;
323
325 ActionClass _actionClass;
326
328 MLssize_t _actionId;
329
331 MLssize_t _actionIndex;
332
334 MLssize_t _currentIndex;
335
336 ListContainerBase* _container;
337
339};
340
341
342// ------------------------------------------------------------------
344// ------------------------------------------------------------------
345
369template <class T> class ListTemplate : public ListBase, public std::vector<T>
370{
371public:
374 typedef T itemType;
375
376
379
382 : ListBase(false)
383 {}
384
389
391 : ListBase(other)
392 , std::vector<T>(other)
393 {}
394
396
397
400
402 size_t getSize() const override
403 {
404 using namespace std;
405 return vector<T>::size();
406 }
407
409 void clearList() override
410 {
411 ListBase::clearList();
412 using namespace std;
413 vector<T>::clear();
414 }
415
416
419 {
420 using namespace std;
421
422 ListBase::operator=(list);
423 vector<T>::operator=(list);
424
425 return *this;
426 }
427
432 ListTemplate<T>* clone() const override;
433
435 ListTemplate<T>* deepCopy() const override
436 {
437 return clone();
438 };
439
441
442
446 std::string persistentState() const override;
447
449 void setPersistentState(const std::string& state) override;
450
451
452public:
454 void addStateToTree(TreeNode* parent) const override;
455
458
460 void readStateFromTree(TreeNode* parent) override;
461
463
464protected:
475
478 virtual std::string itemState([[maybe_unused]] typename ListTemplate<T>::const_iterator it) const
479 {
480 return {};
481 }
482
484 virtual void setItemState(typename ListTemplate<T>::iterator /*it*/, const std::string& /*state*/)
485 {}
486};
487
488
489// ------------------------------------------------------------------
490// Implementation of ListTemplate
491// ------------------------------------------------------------------
492
493template <class T> std::string ListTemplate<T>::persistentState() const
494{
495 std::string listStr;
496
497 using namespace std;
498
499 if (hasPersistence()) {
500 // Start list with an opening bracket
501 listStr = "[";
502
503 // Iterate through list
504 for (auto it = vector<T>::begin(); it != vector<T>::end(); ++it) {
505 // Separate items by a comma
506 if (it != vector<T>::begin()) {
507 listStr += ", ";
508 }
509
510 // Get string representation for item object
511 auto itemStr = itemState(it);
512 if (!itemStr.empty()) {
513 if (ListParser::needsQuote(itemStr)) {
514 listStr += ListParser::quoteString(itemStr);
515 }
516 else {
517 listStr += itemStr;
518 }
519 }
520 else
521 // Empty item string, add "" to list string
522 listStr += "\"\"";
523 }
524
525 // End list with a closing bracket
526 listStr += ']';
527 }
528
529 return listStr;
530}
531
532template <class T> void ListTemplate<T>::setPersistentState(const std::string& state)
533{
534 using namespace std;
535
536 if (hasPersistence()) {
538
539 // Start with empty list
540 clearList();
541
542 // Initialize parser
543 auto parserResult = parser.init(state.c_str());
544
545 while (!parserResult) {
546 // Parse next item string
547 std::string itemString;
548 std::tie(parserResult, itemString) = parser.nextItem();
549 if (!itemString.empty() && parserResult != ListParser::kEndOfSource) {
550 // Append new item object at end of list
551 vector<T>::insert(vector<T>::end(), T());
552
553 // Restore item object from item string
554 setItemState(vector<T>::end() - 1, itemString);
555 }
556 }
557
558 // Set list action
559 setAction(ListBase::ActNew);
560
561 // Print error message to console
562 if (parserResult > 0 && parserResult != ParserBase::kEmptyString) {
563 ML_PRINT_ERROR("ListTemplate::setPersistentState()", ML_EMPTY_MESSAGE, parser.getErrorMessage(parserResult));
564 }
565 }
566}
567
568
572template <class T> void ListTemplate<T>::addStateToTree(TreeNode* parent) const
573{
574 using namespace std;
575
576 // if (!hasPersistence()) return;
577
579
580 // add listbase members
582
583 // write list size always as unsigned 64 bit integer.
584 parent->addChild(static_cast<MLuint64>(vector<T>::size()), "ListSize");
585
586 // write list items:
587 TreeNode* items = parent->addChild("ListItems");
588
589 // Iterate through list
590 for (auto it = vector<T>::cbegin(); it != vector<T>::cend(); ++it) {
591 auto state = itemState(it);
592 items->addChild(state, "Item");
593 }
594}
595
597template <class T> void ListTemplate<T>::readStateFromTree(TreeNode* parent)
598{
599 using namespace std;
600
601 if (!hasPersistence()) {
602 return;
603 }
604
605 int version = parent->getVersion("ListTemplate");
606
607 // Currently supporting version <= 2 only, version 2 is saved by 64 bit systems.
608 if (version > 2) {
609 // Error, too high version number.
611 }
612
613 if (version >= 1) {
614 // ListBase saves its members since version 1:
616 }
617
618 bool endLoop = false;
619
620 clearList();
621
622 // read size if possible
624 ML_READCHILD_OPTIONAL(loadedSize, "ListSize", 0);
625
626 // reserve some memory for the list. However, we do really want to rely on the ListSize
627 // setting and still read until a child is not found.
628 vector<T>::reserve(loadedSize);
629
630 TreeNode* items = parent->readContainerChild("ListItems");
631
632 std::string currStr;
633 do {
634 // try to read next child:
635 if (items->hasChild()) {
636 items->readChild(currStr);
637 }
638 else {
639 // break free from loop
640 endLoop = true;
641 }
642 if (!endLoop) {
643
644 vector<T>::insert(vector<T>::end(), T());
645
646 // Restore item object from item string
647 setItemState(vector<T>::end() - 1, currStr);
648
649 currStr = {};
650 }
651 } while (!endLoop);
652
653 // Set list action
654 setAction(ListBase::ActNew);
655}
656
657
662template <class T> ListTemplate<T>* ListTemplate<T>::clone() const
663{
664 // get runtime type of this instance
665 const RuntimeType* thisType = this->getTypeId();
666
667 // valid type?
668 if (!thisType || !thisType->canCreateInstance()) {
669 // invalid type
670 return nullptr;
671 }
672
673 ListTemplate<T>* newList = static_cast<ListTemplate<T>*>(thisType->createInstance());
674 if (!newList) {
675 // object creation failed
676 return nullptr;
677 }
678
679 (*newList) = (*this);
680
681 return newList;
682}
683
684
685// ------------------------------------------------------------------
687// ------------------------------------------------------------------
688
709template <class T> class BaseListTemplate : public ListTemplate<T>
710{
711public:
714
717 : ListTemplate<T>()
718 , _nextId(1)
719 {}
720
724 , _nextId(1)
725 {}
726
729 , _nextId(other._nextId)
730 {}
731
733
736
742 BaseItem* getItemAt(MLssize_t index) override
743 {
744 return &(*this)[mlrange_cast<size_t>(index)];
745 };
746
748 const BaseItem* getConstItemAt(MLssize_t index) const override
749 {
750 return &(*this)[mlrange_cast<size_t>(index)];
751 };
752
757 void insertItemAt(MLssize_t index, const BaseItem* item) override
758 {
759 if (item && (getItemTypeId() == item->getTypeId())) {
760 doInsertItem(index, *static_cast<const T*>(item));
761 }
762 };
763
764
769 void modifyItemAt(MLssize_t index, const BaseItem* item) override
770 {
771 if (item && (getItemTypeId() == item->getTypeId())) {
772 doModifyItem(index, *static_cast<const T*>(item));
773 }
774 };
775
780 void deleteItemAt(MLssize_t index) override
781 {
782 doDeleteItem(index);
783 };
784
789 void selectItemAt(MLssize_t index) override
790 {
791 doSelectItem(index);
792 };
793
797 const RuntimeType* getItemTypeId() const override
798 {
799 return T::getClassTypeId();
800 }
801
802
805
807 virtual MLssize_t newId()
808 {
809 return _nextId++;
810 }
811
813 virtual void usedId(MLssize_t id)
814 {
815 if (id >= _nextId) {
816 _nextId = id + 1;
817 }
818 }
819
821 virtual void resetId()
822 {
823 _nextId = 1;
824 for (typename ListTemplate<T>::iterator it = ListTemplate<T>::begin(); it != ListTemplate<T>::end(); it++) {
825 usedId(it->getId());
826 }
827 }
828
830
832 void clearList() override
833 {
835 resetId();
836 }
837
838
848
850 virtual void doDeleteItem(MLssize_t index);
851
854 virtual void doInsertItem(MLssize_t index, const T& item);
855
858 virtual void doModifyItem(MLssize_t index, const T& item);
859
862 virtual void doSelectItem(MLssize_t index);
863
866 virtual void appendItem(const T& item);
867
869 void addStateToTree(TreeNode* parent) const override;
870
872
877
879 void readStateFromTree(TreeNode* parent) override;
880
881
883
884
885protected:
893 std::string itemState(typename ListTemplate<T>::const_iterator it) const override
894 {
895 return it->persistentState();
896 }
897
899 void setItemState(typename ListTemplate<T>::iterator it, const std::string& state) override
900 {
901 it->setPersistentState(state);
902 usedId(it->getId());
903 }
904
905private:
907 MLssize_t _nextId;
908};
909
910
911// ------------------------------------------------------------------
912// --- Implementation of BaseListTemplate
913// ------------------------------------------------------------------
914
916template <class T> void BaseListTemplate<T>::doDeleteItem(MLssize_t index)
917{
918 if ((index >= 0) && (index < static_cast<MLssize_t>(ListTemplate<T>::size()))) {
919 this->setAction(ListTemplate<T>::ActDelete, (*this)[mlrange_cast<size_t>(index)].getId(), index);
921 }
922}
923
924
927template <class T> void BaseListTemplate<T>::doInsertItem(MLssize_t index, const T& item)
928{
929 MLssize_t id = 0;
930
931 if ((index >= 0) && (index <= mlrange_cast<MLssize_t>(ListTemplate<T>::size()))) {
933 id = newId();
934 (*this)[static_cast<size_t>(index)].setId(id);
935 this->setAction(ListTemplate<T>::ActInsert, id, index);
936 }
937}
938
941template <class T> void BaseListTemplate<T>::appendItem(const T& item)
942{
943 doInsertItem(static_cast<MLssize_t>(ListTemplate<T>::size()), item);
944}
945
946
949template <class T> void BaseListTemplate<T>::doModifyItem(MLssize_t index, const T& item)
950{
951 if ((index >= 0) && (index < mlrange_cast<MLssize_t>(ListTemplate<T>::size()))) {
952 const size_t idx_size_t = static_cast<size_t>(index);
953 const MLssize_t id = (*this)[idx_size_t].getId();
954 (*this)[idx_size_t] = item;
955 (*this)[idx_size_t].setId(id);
956 this->setAction(ListTemplate<T>::ActModify, id, index);
957 }
958}
959
960
963template <class T> void BaseListTemplate<T>::doSelectItem(MLssize_t index)
964{
965 if ((index >= 0) && (index < mlrange_cast<MLssize_t>(ListTemplate<T>::size()))) {
966 this->setAction(ListTemplate<T>::ActSelect, (*this)[static_cast<size_t>(index)].getId(), index);
967 }
968 else if (index == -1) {
969 // deselect all
970 this->setAction(ListTemplate<T>::ActSelect);
971 }
972}
973
974
978template <class T> void BaseListTemplate<T>::addStateToTree(TreeNode* parent) const
979{
981
982 // add ListBase members
984
985 typename BaseListTemplate<T>::const_iterator it;
986 // write list size
987 parent->addChild(static_cast<MLuint64>(ListTemplate<T>::size()), "ListSize");
988
989 TreeNode* items = parent->addChild("ListItems");
990
991 // Iterate through list
993 items->addChild(&(*it), "Item", false);
994 }
995}
996
998template <class T> void BaseListTemplate<T>::readStateFromTree(TreeNode* parent)
999{
1000 int version = parent->getVersion("BaseListTemplate");
1001
1002 // Currently supporting version <= 2 only, version 2 is 64 bit version.
1003 if (version > 2) {
1005 }
1006
1007 if (version >= 1) {
1008 // ListBase saves its members since version 1:
1010 }
1011
1012 bool endLoop = false;
1013
1014 clearList(); // includes _nextId = 1;
1015
1016 // read size if possible
1017 MLuint64 loadedSize = 0;
1018 ML_READCHILD_OPTIONAL(loadedSize, "ListSize", 0);
1019
1020 // reserve some memory for the list. However, we do not really want to rely on the ListSize
1021 // setting and still read until a child is not found.
1023
1024 TreeNode* items = parent->readContainerChild("ListItems");
1025
1026 if (items)
1027 do {
1028 // try to read next child:
1029 if (items->hasChild()) {
1031 items->readChild(*(ListTemplate<T>::end() - 1));
1032 }
1033 else {
1034 // break free from loop
1035 endLoop = true;
1036 }
1037 if (ListTemplate<T>::size() > 0) {
1038 // update _nextId:
1039 _nextId = std::max(_nextId, (ListTemplate<T>::end() - 1)->getId() + 1);
1040 }
1041 else {
1042 endLoop = true;
1043 }
1044 } while (!endLoop);
1045
1046 // Set list action
1047 this->setAction(ListTemplate<T>::ActNew);
1048}
1049
1050
1052
1053
1054#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:710
void deleteItemAt(MLssize_t index) override
This virtual function is reimplemented from ListBase, where it does nothing at all.
Definition mlListBase.h:780
virtual MLssize_t newId()
Get new unused id.
Definition mlListBase.h:807
void setItemState(typename ListTemplate< T >::iterator it, const std::string &state) override
Initialize the item object from the string state.
Definition mlListBase.h:899
BaseListTemplate()
Standard constructor, disables persistence.
Definition mlListBase.h:716
void addStateToTree(TreeNode *parent) const override
Attaches the object state as children of the given parent node.
Definition mlListBase.h:978
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:769
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:916
std::string itemState(typename ListTemplate< T >::const_iterator it) const override
Return a string representation of the item object.
Definition mlListBase.h:893
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:927
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
Definition mlListBase.h:998
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:941
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:742
BaseListTemplate(bool persistence)
Special constructor to explicitly enable/disable persistence.
Definition mlListBase.h:722
const BaseItem * getConstItemAt(MLssize_t index) const override
Same as getItemAt(MLssize_t index) for constant access.
Definition mlListBase.h:748
BaseListTemplate(const BaseListTemplate &other)
Definition mlListBase.h:727
void selectItemAt(MLssize_t index) override
This virtual function is reimplemented from ListBase, where it does nothing at all.
Definition mlListBase.h:789
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:757
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:963
virtual void usedId(MLssize_t id)
Notify list that id is used.
Definition mlListBase.h:813
void clearList() override
Clear complete list.
Definition mlListBase.h:832
virtual void resetId()
Reset next id.
Definition mlListBase.h:821
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:797
virtual void doModifyItem(MLssize_t index, const T &item)
Store item at position index and set the corresponding ActModify action.
Definition mlListBase.h:949
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:63
Base object class ListBase managing a number of BaseItem objects.
Definition mlListBase.h:63
virtual void clearList()
Clear complete list.
Definition mlListBase.h:135
virtual MLssize_t getActionId() const
Get id of item affected by last action.
Definition mlListBase.h:273
virtual void setPersistence(bool persistence)
Enable/disable persistence functionality.
Definition mlListBase.h:184
char * newString(const std::string &str) const
Convenience method to create a copy of the string str allocated on the heap.
Definition mlListBase.h:306
virtual MLssize_t getActionIndex() const
Get index of item affected by last action.
Definition mlListBase.h:281
ListBase(bool persistence)
Constructor. Derived class should indicate whether persistence is implemented.
Definition mlListBase.h:66
ListBase * deepCopy() const override
Create a deep copy of the list.
Definition mlListBase.h:152
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:129
ActionClass
Constants to describe the type of action most recently performed.
Definition mlListBase.h:234
@ ActInsert
List item inserted.
Definition mlListBase.h:243
@ ActModify
Current list item modified.
Definition mlListBase.h:240
@ ActNew
New list generated.
Definition mlListBase.h:237
@ ActUnknown
Unknown action.
Definition mlListBase.h:236
virtual void selectItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually selects the item at ...
Definition mlListBase.h:124
ListBase & operator=(const ListBase &list)
Assignment operator, used in derived list classes.
virtual MLssize_t getCurrentIndex() const
Get index of currently selected item, or -1 if no item selected.
Definition mlListBase.h:287
ListContainerBase * getContainer() const
Definition mlListBase.h:163
virtual void deleteItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually deletes the item at ...
Definition mlListBase.h:119
virtual bool isModified() const
Tests, if the last action has been an action that has modified the content of the list.
Definition mlListBase.h:293
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:101
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:267
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.
MLBASEEXPORT friend std::ostream & operator<<(std::ostream &s, const ListBase &list)
Output persistent state to stream.
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:199
virtual void setAction(ActionClass actionClass)
Set actionClass for actions affecting the whole list.
Definition mlListBase.h:258
virtual BaseItem * getItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually returns the item at ...
Definition mlListBase.h:95
virtual ListBase * clone() const
Create a copy of (*this) using the ML runtime system and the '='-operator.
Definition mlListBase.h:146
void deleteString(char *str) const
Dispose a string allocated with newString()
Definition mlListBase.h:312
ListBase(const ListBase &other)
Definition mlListBase.h:75
void setContainer(ListContainerBase *container)
Definition mlListBase.h:159
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:114
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:109
virtual bool hasPersistence() const
Test if persistence is available and enabled.
Definition mlListBase.h:178
bool hasPersistance() const
Definition mlListBase.h:192
Abstract module class ListContainerBase implementing basic functionality for a list container module.
Parser class for parsing persistent state strings of list objects.
Basic list class template combining properties of ListBase and a vector of the template argument type...
Definition mlListBase.h:370
virtual void setItemState(typename ListTemplate< T >::iterator, const std::string &)
Initialize the item object from the string state.
Definition mlListBase.h:484
ML_SET_ADDSTATE_VERSION(2)
Set addState version number, version 2 indicates data saved by a 64 bit version.
ListTemplate< T > & operator=(const ListTemplate< T > &list)
Assignment operator.
Definition mlListBase.h:418
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
Definition mlListBase.h:597
ListTemplate()
Standard constructor, disables persistence.
Definition mlListBase.h:381
size_t getSize() const override
Get number of list elements.
Definition mlListBase.h:402
ListTemplate< T > * clone() const override
Create a copy of (*this) using the ML runtime system and the '='-operator.
Definition mlListBase.h:662
T itemType
Declare type name for item type (this allows declarations like: ObjectList::itemType obj)
Definition mlListBase.h:374
void clearList() override
Clear complete list.
Definition mlListBase.h:409
virtual std::string itemState(typename ListTemplate< T >::const_iterator it) const
Return a string representation of the item object.
Definition mlListBase.h:478
void addStateToTree(TreeNode *parent) const override
Attaches the state as children of the given parent node.
Definition mlListBase.h:572
ListTemplate(bool persistence)
Special constructor to explicitly enable/disable persistence.
Definition mlListBase.h:386
ListTemplate(const ListTemplate &other)
Definition mlListBase.h:390
void setPersistentState(const std::string &state) override
Initialize the list object from the string state.
Definition mlListBase.h:532
ListTemplate< T > * deepCopy() const override
Create a deep copy of the list.
Definition mlListBase.h:435
std::string persistentState() const override
Returns a string describing the object's internal state.
Definition mlListBase.h:493
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.
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:160
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:851
#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
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#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:717
#define ML_ADDSTATE_VERSION(ThisClass)
Use this macro in addStateToTree() for classes that might need versioning in the future.
Definition mlTreeNode.h:727
#define ML_ADDSTATE_SUPER(SuperClass)
Use this macro if you would like to store your superclass members as well.
Definition mlTreeNode.h:731
#define ML_READSTATE_SUPER(SuperClass)
Use this macro if you would like to store your superclass members as well.
Definition mlTreeNode.h:739
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:563
@ TNE_UnsupportedClassVersion
Definition mlTreeNode.h:73
STL namespace.