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 
46 ML_START_NAMESPACE
47 
48 class BaseItem;
49 
50 // ------------------------------------------------------------------
52 // ------------------------------------------------------------------
53 
62 class MLBASEEXPORT ListBase : public Base
63 {
64 public:
65 
67  ListBase (bool persistance)
68  : _hasPersistance(persistance),
69  _actionClass(ActNew),
70  _actionId(-1),
71  _actionIndex(-1),
72  _currentIndex(-1)
73  {}
74 
75  ListBase(const ListBase& other)
76  : _hasPersistance(other.hasPersistance()),
77  _actionClass(other.getActionClass()),
78  _actionId(other.getActionId()),
79  _actionIndex(other.getActionIndex()),
80  _currentIndex(other.getCurrentIndex())
81  {}
82 
85 
87  virtual size_t getSize () const = 0;
88 
94  virtual BaseItem* getItemAt(MLssize_t /*index*/) { return nullptr; };
95 
97  virtual const BaseItem* getConstItemAt(MLssize_t /*index*/) const { return nullptr; };
98 
102  virtual void insertItemAt(MLssize_t /*index*/, const BaseItem* /*item*/) {};
103 
107  virtual void modifyItemAt(MLssize_t /*index*/, const BaseItem* /*item*/) {};
108 
112  virtual void deleteItemAt(MLssize_t /*index*/) {};
113 
117  virtual void selectItemAt(MLssize_t /*index*/) {};
118 
122  virtual const RuntimeType* getItemTypeId() const { return nullptr; };
123 
125  virtual void clearList ()
126  { setAction(ActNew); }
127 
134  virtual ListBase* clone() const { return nullptr; };
135 
137  ListBase* deepCopy() const override { return clone(); };
138 
140 
141 
150 
152  virtual bool hasPersistance () const { return _hasPersistance; }
153 
155  virtual void setPersistance (bool persistance) { _hasPersistance = persistance; }
156 
158  MLBASEEXPORT friend std::ostream& operator << (std::ostream &s, const ListBase &list);
159 
161  void addStateToTree(TreeNode* parent) const override;
162 
165 
167  void readStateFromTree(TreeNode* parent) override;
168 
170 
171 
185 
188  {
189  ActNone = 0,
192  ActSelect,
195  ActDelete,
198  ActInsertOvw,
202  ActNumActions
203  };
204 
206  static const char *const ActionClassNames[ActNumActions];
207 
209  virtual void setAction (ActionClass actionClass, MLssize_t id, MLssize_t index);
210 
212  virtual void setAction (ActionClass actionClass)
213  { setAction(actionClass, -1, -1); }
214 
216  virtual void getAction (ActionClass &actionClass, MLssize_t &id, MLssize_t &index) const;
217 
219  virtual ActionClass getActionClass () const
220  { return _actionClass; }
221 
223  virtual MLssize_t getActionId () const
224  { return _actionId; }
225 
229  virtual MLssize_t getActionIndex () const
230  { return _actionIndex; }
231 
233  virtual MLssize_t getCurrentIndex () const
234  { return _currentIndex; }
235 
237  virtual bool isModified () const
238  { return (ActSelect != _actionClass && ActNone != _actionClass); }
239 
240 
242 
243 
244 protected:
245 
249  char *newString (const std::string &str) const
250  { return ParserBase::newString(str); }
251 
253  void deleteString (char *str) const
254  { ParserBase::deleteString(str); }
255 
257  ListBase &operator = (const ListBase &list);
258 
259 private:
260 
262  bool _hasPersistance;
263 
265  ActionClass _actionClass;
266 
268  MLssize_t _actionId;
269 
271  MLssize_t _actionIndex;
272 
274  MLssize_t _currentIndex;
275 
276 
278 
279 };
280 
281 
282 
283 // ------------------------------------------------------------------
285 // ------------------------------------------------------------------
286 
310 template <class T>
311 class ListTemplate : public ListBase, public std::vector<T>
312 {
313 public:
314 
317  typedef T itemType;
318 
319 
322 
324  ListTemplate () : ListBase(false) {}
325 
327  ListTemplate (bool persistance) : ListBase(persistance) {}
328 
329  ListTemplate(const ListTemplate& other) : ListBase(other), std::vector<T>(other) {}
330 
332 
333 
336 
338  size_t getSize () const override
339  { using namespace std; return vector<T>::size(); }
340 
342  void clearList () override
343  { ListBase::clearList(); using namespace std; vector<T>::clear(); }
344 
345 
347  ListTemplate<T> &operator = (const ListTemplate<T> &list)
348  {
349  using namespace std;
350 
351  ListBase::operator =(list);
352  vector<T>::operator =(list);
353 
354  return *this;
355  }
356 
361  ListTemplate<T>* clone() const override;
362 
364  ListTemplate<T>* deepCopy() const override { return clone(); };
365 
367 
368 
372  std::string persistentState() const override;
373 
375  void setPersistentState(const std::string& state) override;
376 
377 #if !ML_DEPRECATED_SINCE(3,5,0)
378 private:
379 #endif
383  [[nodiscard]]
384  [[deprecated]] char *getPersistentState() const override;
385 
388  [[deprecated]] void setPersistentState (const char *state) override;
389 
393  [[deprecated]] void clearPersistentState (char *state) const override
394  { deleteString(state); }
395 
396 #if !ML_DEPRECATED_SINCE(3,5,0)
397 public:
398 #endif
399 
401  void addStateToTree(TreeNode* parent) const override;
402 
405 
407  void readStateFromTree(TreeNode* parent) override;
408 
410 private:
411  struct ItemStateDeleter
412  {
413  const ListTemplate<T>* _this{};
415 
416  void operator()(char* p) const
417  {
418  _this->clearItemState(it, p);
419  }
420  };
421 
422 protected:
423 
434 
437  virtual std::string itemState(typename ListTemplate<T>::const_iterator it) const
438  {
439 #if ML_DEPRECATED_SINCE(3,5,0)
440  const auto tmp = std::unique_ptr<char[], ItemStateDeleter>{ getItemState(it), ItemStateDeleter{this, it} };
441  return std::string{ tmp.get()? tmp.get() : "" };
442 #else
443  return {};
444 #endif
445  }
446 
448  virtual void setItemState(typename ListTemplate<T>::iterator /*it*/, const std::string& /*state*/) {}
449 
450 #if !ML_DEPRECATED_SINCE(3,5,0)
451 private:
452 #endif
453  [[deprecated]] virtual char* getItemState(typename ListTemplate<T>::const_iterator /*it*/) const { return nullptr; }
454 
455  [[deprecated]] virtual void setItemState(typename ListTemplate<T>::iterator /*it*/, const char* /*state*/) {}
456 
459  [[deprecated]] virtual void clearItemState(typename ListTemplate<T>::const_iterator /*it*/, char *state) const
460  { deleteString(state); }
462 
463 };
464 
465 
466 
467 // ------------------------------------------------------------------
468 // Implementation of ListTemplate
469 // ------------------------------------------------------------------
470 
473 template <class T>
474 char *ListTemplate<T>::getPersistentState () const
475 {
476  return newString(persistentState());
477 }
478 
479 
480 template <class T>
482 {
483  std::string listStr;
484 
485  using namespace std;
486 
487  if (hasPersistance())
488  {
489  // Start list with an opening bracket
490  listStr = "[";
491 
492  // Iterate through list
493  for (auto it = vector<T>::begin(); it != vector<T>::end(); ++it)
494  {
495  // Separate items by a comma
496  if (it != vector<T>::begin()) {
497  listStr += ", ";
498  }
499 
500  // Get string representation for item object
501  auto itemStr = itemState(it);
502  if (!itemStr.empty())
503  {
504  if (ListParser::needsQuote(itemStr))
505  {
506  listStr += ListParser::quoteString(itemStr);
507  }
508  else {
509  listStr += itemStr;
510  }
511  }
512  else
513  // Empty item string, add "" to list string
514  listStr += "\"\"";
515  }
516 
517  // End list with a closing bracket
518  listStr += ']';
519  }
520 
521  return listStr;
522 }
523 
524 
526 template <class T>
527 void ListTemplate<T>::setPersistentState (const char *state)
528 {
529  setPersistentState(std::string(state));
530 }
531 
532 
533 template <class T> void ListTemplate<T>::setPersistentState(const std::string &state)
534 {
535  using namespace std;
536 
537  if (hasPersistance())
538  {
539  ListParser parser;
540 
541  // Start with empty list
542  clearList();
543 
544  // Initialize parser
545  auto parserResult = parser.init(state.c_str());
546 
547  while (!parserResult)
548  {
549  // Parse next item string
550  std::string itemString;
551  std::tie(parserResult, itemString) = parser.nextItem();
552  if (!itemString.empty() && parserResult != ListParser::kEndOfSource)
553  {
554  // Append new item object at end of list
555  vector<T>::insert(vector<T>::end(), T());
556 
557  // Restore item object from item string
558  setItemState(vector<T>::end() - 1, itemString);
559  }
560  }
561 
562  // Set list action
563  setAction(ListBase::ActNew);
564 
565  // Print error message to console
566  if (parserResult > 0 && parserResult != ParserBase::kEmptyString) {
567  ML_PRINT_ERROR("ListTemplate::setPersistentState()", ML_EMPTY_MESSAGE,
568  parser.getErrorMessage(parserResult));
569  }
570  }
571 }
572 
573 
577 template <class T>
579 {
580  using namespace std;
581 
582  //if (!hasPersistance()) return;
583 
585 
586  // add listbase members
588 
589  // write list size always as unsigned 64 bit integer.
590  parent->addChild(static_cast<MLuint64>(vector<T>::size()), "ListSize");
591 
592  // write list items:
593  TreeNode* items = parent->addChild("ListItems");
594 
595  // Iterate through list
596  for (auto it = vector<T>::cbegin(); it != vector<T>::cend(); ++it)
597  {
598  auto state = itemState(it);
599  items->addChild(state, "Item");
600  }
601 
602 }
603 
605 template <class T>
607 {
608  using namespace std;
609 
610  if (!hasPersistance()) { return; }
611 
612  int version = parent->getVersion("ListTemplate");
613 
614  // Currently supporting version <= 2 only, version 2 is saved by 64 bit systems.
615  if (version > 2){
616  // Error, too high version number.
618  }
619 
620  if (version >= 1) {
621  // ListBase saves its members since version 1:
623  }
624 
625  bool endLoop = false;
626 
627  clearList();
628 
629  // read size if possible
630  MLuint64 loadedSize = 0;
631  ML_READCHILD_OPTIONAL(loadedSize, "ListSize", 0);
632 
633  // reserve some memory for the list. However, we do really want to rely on the ListSize
634  // setting and still read until a child is not found.
635  vector<T>::reserve( loadedSize );
636 
637  TreeNode* items = parent->readContainerChild("ListItems");
638 
639  std::string currStr;
640  do {
641  // try to read next child:
642  if (items->hasChild()) {
643  items->readChild(currStr);
644  } else {
645  // break free from loop
646  endLoop = true;
647  }
648  if (!endLoop) {
649 
650  vector<T>::insert(vector<T>::end(), T());
651 
652  // Restore item object from item string
653  setItemState(vector<T>::end()-1, currStr.c_str());
654 
655  currStr = {};
656  }
657  } while (!endLoop);
658 
659  // Set list action
660  setAction(ListBase::ActNew);
661 }
662 
663 
664 
669 template <class T>
671 {
672  // get runtime type of this instance
673  const RuntimeType* thisType = this->getTypeId();
674 
675  // valid type?
676  if (!thisType || !thisType->canCreateInstance()) {
677  // invalid type
678  return nullptr;
679  }
680 
681  ListTemplate<T>* newList = static_cast<ListTemplate<T>*>(thisType->createInstance());
682  if (!newList) {
683  // object creation failed
684  return nullptr;
685  }
686 
687  (*newList) = (*this);
688 
689  return newList;
690 }
691 
692 
693 
694 
695 
696 // ------------------------------------------------------------------
698 // ------------------------------------------------------------------
699 
720 template <class T>
722 {
723 public:
724 
727 
729  BaseListTemplate () : ListTemplate<T>(), _nextId(1) {}
730 
732  BaseListTemplate (bool persistance) : ListTemplate<T>(persistance), _nextId(1) {}
733 
734  BaseListTemplate(const BaseListTemplate& other) : ListTemplate<T>(other) {}
735 
737 
740 
746  BaseItem* getItemAt(MLssize_t index) override{
747  return &(*this)[mlrange_cast<size_t>(index)];
748  };
749 
751  const BaseItem* getConstItemAt(MLssize_t index) const override {
752  return &(*this)[mlrange_cast<size_t>(index)];
753  };
754 
759  void insertItemAt(MLssize_t index, const BaseItem* item) override {
760  if (item && (getItemTypeId() == item->getTypeId())) {
761  doInsertItem(index, *static_cast<const T*>(item) );
762  }
763  };
764 
765 
770  void modifyItemAt(MLssize_t index, const BaseItem* item) override {
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  doDeleteItem(index);
782  };
783 
788  void selectItemAt(MLssize_t index) override {
789  doSelectItem(index);
790  };
791 
795  const RuntimeType* getItemTypeId() const override {
796  return T::getClassTypeId();
797  }
798 
799 
802 
804  virtual MLssize_t newId () { return _nextId++; }
805 
807  virtual void usedId (MLssize_t id)
808  {
809  if (id >= _nextId) {
810  _nextId = id+1;
811  }
812  }
813 
815  virtual void resetId ()
816  {
817  _nextId = 1;
818  for (typename ListTemplate<T>::iterator it = ListTemplate<T>::begin(); it != ListTemplate<T>::end(); it++){
819  usedId(it->getId());
820  }
821  }
822 
824 
826  void clearList () override
827  {
829  resetId();
830  }
831 
832 
842 
844  virtual void doDeleteItem (MLssize_t index);
845 
848  virtual void doInsertItem (MLssize_t index, const T &item);
849 
852  virtual void doModifyItem (MLssize_t index, const T &item);
853 
856  virtual void doSelectItem (MLssize_t index);
857 
860  virtual void appendItem(const T &item);
861 
863  void addStateToTree(TreeNode* parent) const override;
864 
866 
871 
873  void readStateFromTree(TreeNode* parent) override;
874 
875 
876 
878 
879 
880 protected:
881 
889  std::string itemState(typename ListTemplate<T>::const_iterator it) const override
890  {
891  return it->persistentState();
892  }
893 
895  void setItemState(typename ListTemplate<T>::iterator it, const std::string& state) override
896  {
897  it->setPersistentState(state);
898  usedId(it->getId());
899  }
900 
901 #if !ML_DEPRECATED_SINCE(3,5,0)
902 protected:
903 #endif
907  [[nodiscard]]
908  [[deprecated]] char *getItemState(typename ListTemplate<T>::const_iterator it) const override
909  { return StringConversion::newString(it->persistentState()); }
910 
913  [[deprecated]] void setItemState(typename ListTemplate<T>::iterator it, const char *state) override
914  {
915  it->setPersistentState(std::string(state));
916  usedId(it->getId());
917  }
918 
922  [[deprecated]] void clearItemState (typename ListTemplate<T>::const_iterator it, char *state) const override
923  { it->clearPersistentState(state); }
925 
926 
927 private:
928 
930  MLssize_t _nextId;
931 
932 };
933 
934 
935 
936 
937 // ------------------------------------------------------------------
938 // --- Implementation of BaseListTemplate
939 // ------------------------------------------------------------------
940 
942 template <class T>
944 {
945  if ((index >= 0) && (index < static_cast<MLssize_t>(ListTemplate<T>::size())) )
946  {
947  this->setAction(ListTemplate<T>::ActDelete, (*this)[mlrange_cast<size_t>(index)].getId(), index);
949  }
950 }
951 
952 
955 template <class T>
957 {
958  MLssize_t id=0;
959 
960  if ((index >= 0) && (index <= mlrange_cast<MLssize_t>(ListTemplate<T>::size())) )
961  {
963  id = newId();
964  (*this)[static_cast<size_t>(index)].setId(id);
965  this->setAction(ListTemplate<T>::ActInsert, id, index);
966  }
967 }
968 
971 template <class T>
973 {
974  doInsertItem(static_cast<MLssize_t>(ListTemplate<T>::size()), item);
975 }
976 
977 
980 template <class T>
982 {
983  if ((index >= 0) && (index < mlrange_cast<MLssize_t>(ListTemplate<T>::size())) )
984  {
985  const size_t idx_size_t = static_cast<size_t>(index);
986  const MLssize_t id = (*this)[idx_size_t].getId();
987  (*this)[idx_size_t] = item;
988  (*this)[idx_size_t].setId(id);
989  this->setAction(ListTemplate<T>::ActModify, id, index);
990  }
991 }
992 
993 
996 template <class T>
998 {
999  if ((index >= 0) && (index < mlrange_cast<MLssize_t>(ListTemplate<T>::size())) )
1000  {
1001  this->setAction(ListTemplate<T>::ActSelect, (*this)[static_cast<size_t>(index)].getId(), index);
1002  }
1003  else if (index == -1)
1004  {
1005  // deselect all
1006  this->setAction(ListTemplate<T>::ActSelect);
1007  }
1008 }
1009 
1010 
1014 template <class T>
1016 {
1018 
1019  // add ListBase members
1021 
1023  MLuint64 i = 0;
1024 
1025  // write list size
1026  parent->addChild(static_cast<MLuint64>(ListTemplate<T>::size()), "ListSize");
1027 
1028  TreeNode* items = parent->addChild("ListItems");
1029 
1030  // Iterate through list
1031  for (it = ListTemplate<T>::begin(); it != ListTemplate<T>::end(); it++, i++)
1032  {
1033  items->addChild(&(*it), "Item", false);
1034  }
1035 
1036 }
1037 
1039 template <class T>
1041 {
1042  int version = parent->getVersion("BaseListTemplate");
1043 
1044  // Currently supporting version <= 2 only, version 2 is 64 bit version.
1045  if (version > 2) {
1047  }
1048 
1049  if (version >= 1) {
1050  // ListBase saves its members since version 1:
1052  }
1053 
1054  bool endLoop = false;
1055 
1056  clearList(); // includes _nextId = 1;
1057 
1058  // read size if possible
1059  MLuint64 loadedSize = 0;
1060  ML_READCHILD_OPTIONAL(loadedSize, "ListSize", 0);
1061 
1062  // reserve some memory for the list. However, we do not really want to rely on the ListSize
1063  // setting and still read until a child is not found.
1064  ListTemplate<T>::reserve( loadedSize );
1065 
1066  TreeNode* items = parent->readContainerChild("ListItems");
1067 
1068  if (items) do {
1069  // try to read next child:
1070  if (items->hasChild()) {
1072  items->readChild(*(ListTemplate<T>::end()-1));
1073  } else {
1074  // break free from loop
1075  endLoop = true;
1076  }
1077  if (ListTemplate<T>::size() > 0){
1078  // update _nextId:
1079  _nextId = std::max(_nextId, (ListTemplate<T>::end()-1)->getId() + 1);
1080  } else {
1081  endLoop = true;
1082  }
1083  } while (!endLoop);
1084 
1085  // Set list action
1086  this->setAction(ListTemplate<T>::ActNew);
1087 }
1088 
1089 
1090 ML_END_NAMESPACE
1091 
1092 
1093 #endif
@ T
Definition: SoKeyGrabber.h:71
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:722
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:804
void setItemState(typename ListTemplate< T >::iterator it, const std::string &state) override
Initialize the item object from the string state.
Definition: mlListBase.h:895
BaseListTemplate()
Standard constructor, disables persistence.
Definition: mlListBase.h:729
void addStateToTree(TreeNode *parent) const override
Attaches the object state as children of the given parent node.
Definition: mlListBase.h:1015
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:770
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:943
std::string itemState(typename ListTemplate< T >::const_iterator it) const override
Return a string representation of the item object.
Definition: mlListBase.h:889
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:746
void clearItemState(typename ListTemplate< T >::const_iterator it, char *state) const override
Dispose the string state, which has been previously obtained by getItemState()
Definition: mlListBase.h:922
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:956
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
Definition: mlListBase.h:1040
virtual void appendItem(const T &item)
Appends an item to the list.
Definition: mlListBase.h:972
char * getItemState(typename ListTemplate< T >::const_iterator it) const override
Return a string representation of the item object.
Definition: mlListBase.h:908
const BaseItem * getConstItemAt(MLssize_t index) const override
Same as getItemAt(MLssize_t index) for constant access.
Definition: mlListBase.h:751
BaseListTemplate(const BaseListTemplate &other)
Definition: mlListBase.h:734
BaseListTemplate< T > & operator=(const BaseListTemplate &other)=default
explicitly create default assignment operator
void selectItemAt(MLssize_t index) override
This virtual function is reimplemented from ListBase, where it does nothing at all.
Definition: mlListBase.h:788
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:759
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:795
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:997
BaseListTemplate(bool persistance)
Special constructor to explicitly enable/disable persistence.
Definition: mlListBase.h:732
virtual void usedId(MLssize_t id)
Notify list that id is used.
Definition: mlListBase.h:807
void clearList() override
Clear complete list.
Definition: mlListBase.h:826
virtual void resetId()
Reset next id.
Definition: mlListBase.h:815
virtual void doModifyItem(MLssize_t index, const T &item)
Store item at position index and set the corresponding ActModify action.
Definition: mlListBase.h:981
void setItemState(typename ListTemplate< T >::iterator it, const char *state) override
Initialize the item object from the string state.
Definition: mlListBase.h:913
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition: mlBase.h:62
Base object class ListBase managing a number of BaseItem objects.
Definition: mlListBase.h:63
virtual void clearList()
Clear complete list.
Definition: mlListBase.h:125
virtual MLssize_t getActionId() const
Get id of item affected by last action.
Definition: mlListBase.h:223
virtual MLssize_t getActionIndex() const
Get index of item affected by last action.
Definition: mlListBase.h:229
ML_SET_ADDSTATE_VERSION(0)
Set addState version number.
ActionClass
Constants to describe the type of action most recently performed.
Definition: mlListBase.h:188
@ ActInsert
List item inserted.
Definition: mlListBase.h:197
@ ActModify
Current list item modified.
Definition: mlListBase.h:194
@ ActNew
New list generated.
Definition: mlListBase.h:191
@ ActUnknown
Unknown action.
Definition: mlListBase.h:190
virtual ListBase * clone() const
Create a copy of (*this) using the ML runtime system and the '='-operator.
Definition: mlListBase.h:134
char * newString(const std::string &str) const
Convenience method to create a copy of the string str allocated on the heap.
Definition: mlListBase.h:249
virtual void selectItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually selects the item at ...
Definition: mlListBase.h:117
virtual const RuntimeType * getItemTypeId() const
This virtual function is reimplemented in BaseListTemplate<T>, where it actually returns the item cla...
Definition: mlListBase.h:122
virtual MLssize_t getCurrentIndex() const
Get index of currently selected item, or -1 if no item selected.
Definition: mlListBase.h:233
virtual bool hasPersistance() const
Test if persistence is available and enabled.
Definition: mlListBase.h:152
virtual void deleteItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually deletes the item at ...
Definition: mlListBase.h:112
virtual bool isModified() const
Tests, if the last action has been an action that has modified the content of the list.
Definition: mlListBase.h:237
virtual size_t getSize() const =0
Get number of list elements.
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:219
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.
ListBase * deepCopy() const override
Create a deep copy of the list.
Definition: mlListBase.h:137
virtual void getAction(ActionClass &actionClass, MLssize_t &id, MLssize_t &index) const
Get actionClass, affected item id and index.
virtual void setPersistance(bool persistance)
Enable/disable persistence functionality.
Definition: mlListBase.h:155
virtual void setAction(ActionClass actionClass)
Set actionClass for actions affecting the whole list.
Definition: mlListBase.h:212
virtual const BaseItem * getConstItemAt(MLssize_t) const
Same as getItemAt(MLssize_t index) for constant access.
Definition: mlListBase.h:97
void deleteString(char *str) const
Dispose a string allocated with newString()
Definition: mlListBase.h:253
ListBase(const ListBase &other)
Definition: mlListBase.h:75
virtual BaseItem * getItemAt(MLssize_t)
This virtual function is reimplemented in BaseListTemplate<T>, where it actually returns the item at ...
Definition: mlListBase.h:94
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:107
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:102
ListBase(bool persistance)
Constructor. Derived class should indicate whether persistence is implemented.
Definition: mlListBase.h:67
Parser class for parsing persistent state strings of list objects.
Definition: mlListParser.h:40
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.
const char * getErrorMessage(int errorCode) override
Get error string for errorCode.
Basic list class template combining properties of ListBase and a vector of the template argument type...
Definition: mlListBase.h:312
virtual void setItemState(typename ListTemplate< T >::iterator, const std::string &)
Initialize the item object from the string state.
Definition: mlListBase.h:448
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:606
ListTemplate()
Standard constructor, disables persistence.
Definition: mlListBase.h:324
size_t getSize() const override
Get number of list elements.
Definition: mlListBase.h:338
ListTemplate< T > * clone() const override
Create a copy of (*this) using the ML runtime system and the '='-operator.
Definition: mlListBase.h:670
ListTemplate(bool persistance)
Special constructor to explicitly enable/disable persistence.
Definition: mlListBase.h:327
ListTemplate< T > * deepCopy() const override
Create a deep copy of the list.
Definition: mlListBase.h:364
T itemType
Declare type name for item type (this allows declarations like: ObjectList::itemType obj)
Definition: mlListBase.h:317
void clearList() override
Clear complete list.
Definition: mlListBase.h:342
virtual std::string itemState(typename ListTemplate< T >::const_iterator it) const
Return a string representation of the item object.
Definition: mlListBase.h:437
void addStateToTree(TreeNode *parent) const override
Attaches the state as children of the given parent node.
Definition: mlListBase.h:578
ListTemplate(const ListTemplate &other)
Definition: mlListBase.h:329
void setPersistentState(const std::string &state) override
Initialize the list object from the string state.
Definition: mlListBase.h:533
std::string persistentState() const override
Returns a string describing the object's internal state.
Definition: mlListBase.h:481
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...
Definition: mlRuntimeType.h:53
void * createInstance() const
Creates and returns an instance of the of the class (NULL if such an instance is unavailable).
Definition: mlRuntimeType.h:98
bool canCreateInstance() const
Returns true if this (runtime)type knows how to create an instance of the class.
Definition: mlRuntimeType.h:94
The class TreeNodeException is the base class for all exceptions thrown by the class TreeNode and all...
Definition: mlTreeNode.h:111
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition: mlTreeNode.h:170
virtual void addChild(bool val, const char *name) ADD_ULONG_CHILD
Factory method adding a child encapsulating a variable of type bool.
#define ML_ABSTRACT_CLASS_HEADER(className)
Same like 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 er...
Definition: mlTypeDefs.h:897
#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:680
#define ML_ADDSTATE_VERSION(ThisClass)
Use this macro in addStateToTree() for classes that might need versioning in the future.
Definition: mlTreeNode.h:689
#define ML_ADDSTATE_SUPER(SuperClass)
Use this macro if you would like to store your super class members as well.
Definition: mlTreeNode.h:693
#define ML_READSTATE_SUPER(SuperClass)
Use this macro if you would like to store your super class members as well.
Definition: mlTreeNode.h:700
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
SSIZE_T MLssize_t
The signed ML size type which is a signed 32 bit size_t on 32 bit platforms and 64 bit one on 64 bit ...
Definition: mlTypeDefs.h:654
std::ostream & operator<<(std::ostream &out, const KeyFrame &frame)
KeyFrame stream output.
@ TNE_UnsupportedClassVersion
Definition: mlTreeNode.h:76