Verovio
Source code documentation
object.h
1 // Name: object.h
3 // Author: Laurent Pugin
4 // Created: 2005
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_OBJECT_H__
9 #define __VRV_OBJECT_H__
10 
11 #include <cstdlib>
12 #include <functional>
13 #include <iterator>
14 #include <map>
15 #include <memory>
16 #include <mutex>
17 #include <shared_mutex>
18 #include <string>
19 #include <unordered_set>
20 
21 //----------------------------------------------------------------------------
22 
23 #include "attclasses.h"
24 #include "attmodule.h"
25 #include "boundingbox.h"
26 #include "vrvdef.h"
27 
28 namespace vrv {
29 
30 class AltSymInterface;
31 class AreaPosInterface;
32 class Doc;
33 class DurationInterface;
34 class EditorialElement;
35 class Output;
36 class Filters;
37 class Functor;
38 class Functor;
39 class ConstFunctor;
40 class LinkingInterface;
41 class FacsimileInterface;
42 class OffsetInterface;
43 class OffsetSpanningInterface;
44 class PitchInterface;
45 class PositionInterface;
46 class Resources;
47 class ScoreDefInterface;
48 class StemmedDrawingInterface;
49 class TextDirInterface;
50 class TimePointInterface;
51 class TimeSpanningInterface;
52 class VisibilityDrawingInterface;
53 class Zone;
54 
55 #define UNLIMITED_DEPTH -10000
56 #define FORWARD true
57 #define BACKWARD false
58 
59 //----------------------------------------------------------------------------
60 // Object
61 //----------------------------------------------------------------------------
62 
66 class Object : public BoundingBox {
67 public:
73  Object();
74  Object(ClassId classId);
75  virtual ~Object();
76  ClassId GetClassId() const final { return m_classId; }
77  virtual std::string GetClassName() const { return "[MISSING]"; }
79 
86  bool IsReferenceObject() const { return m_isReferenceObject; }
88 
92  bool IsFloatingObject() const { return (this->IsSystemElement() || this->IsControlElement()); }
93 
98  bool IsMilestoneElement() const;
99  Object *GetMilestoneEnd();
101 
107  bool IsControlElement() const { return Object::IsControlElement(m_classId); }
108  bool IsEditorialElement() const { return Object::IsEditorialElement(m_classId); }
109  bool IsLayerElement() const { return Object::IsLayerElement(m_classId); }
110  bool IsLyricElement() const { return Object::IsLyricElement(m_classId); }
111  bool IsPageElement() const { return Object::IsPageElement(m_classId); }
112  bool IsRunningElement() const { return Object::IsRunningElement(m_classId); }
113  bool IsScoreDefElement() const { return Object::IsScoreDefElement(m_classId); }
114  bool IsScoreOrPartElement() const { return Object::IsScoreOrPartElement(m_classId); }
115  bool IsSystemElement() const { return Object::IsSystemElement(m_classId); }
116  bool IsTextElement() const { return Object::IsTextElement(m_classId); }
118 
125  static bool IsControlElement(ClassId classId)
126  {
127  return ((classId > CONTROL_ELEMENT) && (classId < CONTROL_ELEMENT_max));
128  }
129  static bool IsEditorialElement(ClassId classId)
130  {
131  return ((classId > EDITORIAL_ELEMENT) && (classId < EDITORIAL_ELEMENT_max));
132  }
133  static bool IsLayerElement(ClassId classId) { return ((classId > LAYER_ELEMENT) && (classId < LAYER_ELEMENT_max)); }
134  static bool IsLyricElement(ClassId classId) { return ((classId > LYRIC_ELEMENT) && (classId < LYRIC_ELEMENT_max)); }
135  static bool IsPageElement(ClassId classId) { return ((classId > PAGE_ELEMENT) && (classId < PAGE_ELEMENT_max)); }
136  static bool IsRunningElement(ClassId classId)
137  {
138  return ((classId > RUNNING_ELEMENT) && (classId < RUNNING_ELEMENT_max));
139  }
140  static bool IsScoreDefElement(ClassId classId)
141  {
142  return ((classId > SCOREDEF_ELEMENT) && (classId < SCOREDEF_ELEMENT_max));
143  }
144  static bool IsScoreOrPartElement(ClassId classId)
145  {
146  return ((classId > SCORE_OR_PART_ELEMENT) && (classId < SCORE_OR_PART_ELEMENT_max));
147  }
148  static bool IsSystemElement(ClassId classId)
149  {
150  return ((classId > SYSTEM_ELEMENT) && (classId < SYSTEM_ELEMENT_max));
151  }
152  static bool IsTextElement(ClassId classId) { return ((classId > TEXT_ELEMENT) && (classId < TEXT_ELEMENT_max)); }
154 
159  void RegisterAttClass(AttClassId attClassId) { m_attClasses.push_back(attClassId); }
160  bool HasAttClass(AttClassId attClassId) const
161  {
162  return std::find(m_attClasses.begin(), m_attClasses.end(), attClassId) != m_attClasses.end();
163  }
164  void RegisterInterface(std::vector<AttClassId> *attClasses, InterfaceId interfaceId);
165  bool HasInterface(InterfaceId interfaceId) const
166  {
167  return std::find(m_interfaces.begin(), m_interfaces.end(), interfaceId) != m_interfaces.end();
168  }
170 
175  virtual AltSymInterface *GetAltSymInterface() { return NULL; }
176  virtual const AltSymInterface *GetAltSymInterface() const { return NULL; }
177  virtual AreaPosInterface *GetAreaPosInterface() { return NULL; }
178  virtual const AreaPosInterface *GetAreaPosInterface() const { return NULL; }
179  virtual BeamDrawingInterface *GetBeamDrawingInterface() { return NULL; }
180  virtual const BeamDrawingInterface *GetBeamDrawingInterface() const { return NULL; }
181  virtual DurationInterface *GetDurationInterface() { return NULL; }
182  virtual const DurationInterface *GetDurationInterface() const { return NULL; }
183  virtual LinkingInterface *GetLinkingInterface() { return NULL; }
184  virtual const LinkingInterface *GetLinkingInterface() const { return NULL; }
185  virtual FacsimileInterface *GetFacsimileInterface() { return NULL; }
186  virtual const FacsimileInterface *GetFacsimileInterface() const { return NULL; }
187  virtual OffsetInterface *GetOffsetInterface() { return NULL; }
188  virtual const OffsetInterface *GetOffsetInterface() const { return NULL; }
189  virtual OffsetSpanningInterface *GetOffsetSpanningInterface() { return NULL; }
190  virtual const OffsetSpanningInterface *GetOffsetSpanningInterface() const { return NULL; }
191  virtual PitchInterface *GetPitchInterface() { return NULL; }
192  virtual const PitchInterface *GetPitchInterface() const { return NULL; }
193  virtual PlistInterface *GetPlistInterface() { return NULL; }
194  virtual const PlistInterface *GetPlistInterface() const { return NULL; }
195  virtual PositionInterface *GetPositionInterface() { return NULL; }
196  virtual const PositionInterface *GetPositionInterface() const { return NULL; }
197  virtual ScoreDefInterface *GetScoreDefInterface() { return NULL; }
198  virtual const ScoreDefInterface *GetScoreDefInterface() const { return NULL; }
199  virtual StemmedDrawingInterface *GetStemmedDrawingInterface() { return NULL; }
200  virtual const StemmedDrawingInterface *GetStemmedDrawingInterface() const { return NULL; }
201  virtual TextDirInterface *GetTextDirInterface() { return NULL; }
202  virtual const TextDirInterface *GetTextDirInterface() const { return NULL; }
203  virtual TimePointInterface *GetTimePointInterface() { return NULL; }
204  virtual const TimePointInterface *GetTimePointInterface() const { return NULL; }
205  virtual TimeSpanningInterface *GetTimeSpanningInterface() { return NULL; }
206  virtual const TimeSpanningInterface *GetTimeSpanningInterface() const { return NULL; }
207  virtual VisibilityDrawingInterface *GetVisibilityDrawingInterface() { return NULL; }
208  virtual const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const { return NULL; }
210 
214  const Resources *GetDocResources() const;
215 
220  virtual void Reset();
221 
230  Object(const Object &object);
231 
235  Object &operator=(const Object &object);
236 
244  void MoveChildrenFrom(Object *sourceParent, int idx = -1, bool allowTypeChange = false);
245 
250  void ReplaceChild(Object *currentChild, Object *replacingChild);
251 
256  void InsertBefore(Object *child, Object *newChild);
257  void InsertAfter(Object *child, Object *newChild);
259 
265  typedef bool (*binaryComp)(Object *, Object *);
266  void SortChildren(binaryComp comp);
267 
272  void MoveItselfTo(Object *targetParent);
273 
278  virtual Object *Clone() const;
279 
284  virtual bool CopyChildren() const { return true; }
285 
291  virtual void CloneReset();
292 
293  const std::string &GetID() const { return m_id; }
294  void SetID(const std::string &id) { m_id = id; }
295  void SwapID(Object *other);
296  void ResetID();
297 
302  virtual void AttributesToExternal() {};
303  virtual void AttributesToInternal() {};
305 
309  std::string GetComment() const { return m_comment; }
310  void SetComment(std::string comment) { m_comment = comment; }
311  bool HasComment() const { return !m_comment.empty(); }
312  std::string GetClosingComment() const { return m_closingComment; }
313  void SetClosingComment(std::string endComment) { m_closingComment = endComment; }
314  bool HasClosingComment() const { return !m_closingComment.empty(); }
315 
322  int GetChildCount() const { return (int)m_children.size(); }
323  int GetChildCount(const ClassId classId) const;
324  int GetChildCount(const ClassId classId, int depth) const;
325  int GetDescendantCount(const ClassId classId) const;
327 
332  Object *GetChild(int idx);
333  const Object *GetChild(int idx) const;
334  Object *GetChild(int idx, const ClassId classId);
335  const Object *GetChild(int idx, const ClassId classId) const;
337 
344  Object *GetDirectChild(Object *parent, Object *descendant);
345 
350  ArrayOfConstObjects GetChildren() const;
351  const ArrayOfObjects &GetChildren() { return m_children; }
353 
358  ArrayOfObjects &GetChildrenForModification() { return m_children; }
359 
365  void CopyAttributesTo(Object *target) const;
366 
371  int GetAttributes(ArrayOfStrAttr *attributes, bool convertToExternal = true) const;
372 
376  bool HasAttribute(std::string attribute, std::string value) const;
377 
386  Object *GetFirst(const ClassId classId = UNSPECIFIED);
387  const Object *GetFirst(const ClassId classId = UNSPECIFIED) const;
388  Object *GetNext();
389  const Object *GetNext() const;
391 
397  Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED);
398  const Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED) const;
399  Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED);
400  const Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED) const;
402 
407  Object *GetLast(const ClassId classId = UNSPECIFIED);
408  const Object *GetLast(const ClassId classId = UNSPECIFIED) const;
410 
415  Object *GetParent() { return m_parent; }
416  const Object *GetParent() const { return m_parent; }
418 
423  void SetParent(Object *parent);
424 
429  void ResetParent() { m_parent = NULL; }
430 
435  virtual bool IsSupportedChild(ClassId classId);
436 
441  virtual bool AddChild(Object *object);
442 
446  virtual bool AddChildAdditionalCheck(Object *) { return true; };
447 
453  virtual int GetInsertOrderFor(ClassId) const { return VRV_UNSET; }
454 
458  int GetInsertOrderForIn(ClassId classId, const std::vector<ClassId> &order) const;
459 
463  int GetIdx() const;
464 
469  int GetDrawingX() const override;
470  int GetDrawingY() const override;
472 
478  void ResetCachedDrawingX() const override;
479  void ResetCachedDrawingY() const override;
481 
485  int GetChildIndex(const Object *child) const;
486 
490  int GetDescendantIndex(const Object *child, const ClassId classId, int depth);
491 
495  void InsertChild(Object *element, int idx);
496 
502  void RotateChildren(int first, int middle, int last);
503 
508  Object *DetachChild(int idx);
509 
514  void ReplaceWithCopyOf(Object *object);
515 
521  void SwapWith(Object *object);
522 
527  bool HasDescendant(const Object *child, int deepness = UNLIMITED_DEPTH) const;
528 
534  Object *FindDescendantByID(const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
535  const Object *FindDescendantByID(
536  const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
538 
544  Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
545  const Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
547 
554  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
556  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
558 
565  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
567  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
569 
575  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH);
576  ListOfConstObjects FindAllDescendantsByType(
577  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH) const;
579 
585  void FindAllDescendantsByComparison(ListOfObjects *objects, Comparison *comparison, int deepness = UNLIMITED_DEPTH,
586  bool direction = FORWARD, bool clear = true);
587  void FindAllDescendantsByComparison(ListOfConstObjects *objects, Comparison *comparison,
588  int deepness = UNLIMITED_DEPTH, bool direction = FORWARD, bool clear = true) const;
590 
596  void FindAllDescendantsBetween(ListOfObjects *objects, Comparison *comparison, const Object *start,
597  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH);
598  void FindAllDescendantsBetween(ListOfConstObjects *objects, Comparison *comparison, const Object *start,
599  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH) const;
601 
611  Object *Relinquish(int idx);
612 
618 
623 
628  bool DeleteChild(Object *child);
629 
635 
640  ListOfObjects GetAncestors();
641  ListOfConstObjects GetAncestors() const;
643 
647  bool IsAncestorOf(const Object *object) const;
648 
654  Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1);
655  const Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1) const;
657 
659  Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1);
660  const Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1) const;
662 
668  Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1);
669  const Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1) const;
671 
676  Object *GetFirstChildNot(const ClassId classId);
677  const Object *GetFirstChildNot(const ClassId classId) const;
679 
684  void FillFlatList(ListOfConstObjects &list) const;
685 
689  bool IsModified() const { return m_isModified; }
690 
694  void Modify(bool modified = true) const;
695 
700  bool IsAttribute() const { return m_isAttribute; }
701  void IsAttribute(bool isAttribute) { m_isAttribute = isAttribute; }
703 
708  bool IsExpansion() const { return m_isExpansion; }
709  void IsExpansion(bool isExpansion) { m_isExpansion = isExpansion; }
711 
716 
721 
725  void SaveObject(Output *output);
726 
730  template <class Compare> void StableSort(Compare comp)
731  {
732  std::stable_sort(m_children.begin(), m_children.end(), comp);
733  }
734 
735  void ReorderByXPos();
736 
737  Object *FindNextChild(Comparison *comp, Object *start);
738 
739  Object *FindPreviousChild(Comparison *comp, Object *start);
740 
745  bool HasPlistReferences() const { return static_cast<bool>(m_plistReferences); }
746  void ResetPlistReferences() { m_plistReferences.reset(); }
747  const ListOfConstObjects *GetPlistReferences() const { return m_plistReferences.get(); }
748  void AddPlistReference(const Object *object);
750 
760  void Process(Functor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false);
761  void Process(ConstFunctor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false) const;
763 
768  virtual FunctorCode Accept(Functor &functor);
769  virtual FunctorCode Accept(ConstFunctor &functor) const;
770  virtual FunctorCode AcceptEnd(Functor &functor);
771  virtual FunctorCode AcceptEnd(ConstFunctor &functor) const;
773 
778  void LogDebugTree(int maxDepth = UNLIMITED_DEPTH, int level = 0);
779  virtual std::string LogDebugTreeMsg() { return this->GetClassName(); }
781 
782  //----------------//
783  // Static methods //
784  //----------------//
785 
786  static void SeedID(uint32_t seed = 0);
787 
788  static std::string GenerateHashID();
789 
790  static uint32_t Hash(uint32_t number, bool reverse = false);
791 
792  static bool sortByUlx(Object *a, Object *b);
793 
797  static bool IsPreOrdered(const Object *left, const Object *right);
798 
799 private:
803  void GenerateID();
804 
808  void Init(ClassId classId);
809 
814  bool SkipChildren(bool visibleOnly) const;
815  bool FiltersApply(const Filters *filters, Object *object) const;
817 
818 public:
823  ArrayOfStrAttr m_unsupported;
824 
825 protected:
826  //
827 private:
832  ArrayOfObjects m_children;
833 
837  Object *m_parent;
838 
842  ClassId m_classId;
843 
848  std::string m_id;
850 
855  bool m_isReferenceObject;
856 
863  mutable bool m_isModified;
864 
871  mutable ArrayOfObjects::const_iterator m_iteratorEnd, m_iteratorCurrent;
872  mutable ClassId m_iteratorElementType;
874 
878  std::vector<AttClassId> m_attClasses;
879 
883  std::vector<InterfaceId> m_interfaces;
884 
890  std::string m_comment;
891  std::string m_closingComment;
893 
898  bool m_isAttribute;
899 
903  bool m_isExpansion;
904 
909  std::unique_ptr<ListOfConstObjects> m_plistReferences;
910 
911  //----------------//
912  // Static members //
913  //----------------//
914 
918  static thread_local unsigned long s_objectCounter;
919 
923  static thread_local uint32_t s_xmlIDCounter;
924 };
925 
926 //----------------------------------------------------------------------------
927 // ObjectListInterface
928 //----------------------------------------------------------------------------
929 
938 public:
939  // constructors and destructors
940  ObjectListInterface() = default;
941  virtual ~ObjectListInterface() = default;
942  ObjectListInterface(const ObjectListInterface &listInterface); // copy constructor;
943  ObjectListInterface &operator=(const ObjectListInterface &listInterface); // copy assignment;
944 
948  int GetListIndex(const Object *listElement) const;
949 
954  const Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
955  Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED);
956  const Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
957  Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED);
959 
964  const Object *GetListPrevious(const Object *listElement) const;
965  Object *GetListPrevious(const Object *listElement);
967 
972  const Object *GetListNext(const Object *listElement) const;
973  Object *GetListNext(const Object *listElement);
975 
982  const ListOfConstObjects &GetList() const;
983  ListOfObjects GetList();
985 
989  void ResetList() const;
990 
996  bool HasEmptyList() const;
997  int GetListSize() const;
998  const Object *GetListFront() const;
999  Object *GetListFront();
1000  const Object *GetListBack() const;
1001  Object *GetListBack();
1003 
1004 protected:
1009  virtual void FilterList(ListOfConstObjects &) const {};
1010 
1011 private:
1015  const Object *GetInterfaceOwner() const;
1016 
1017 public:
1018  //
1019 private:
1020  // The flat list of children
1021  mutable ListOfConstObjects m_list;
1022  // The owner object
1023  mutable const Object *m_owner = NULL;
1024 };
1025 
1026 //----------------------------------------------------------------------------
1027 // TextListInterface
1028 //----------------------------------------------------------------------------
1029 
1037 public:
1038  // constructors and destructors
1039  TextListInterface() = default;
1040  virtual ~TextListInterface() = default;
1041 
1045  std::u32string GetText() const;
1046 
1050  void GetTextLines(std::vector<std::u32string> &lines) const;
1051 
1052 protected:
1057  void FilterList(ListOfConstObjects &childList) const override;
1058 
1059 private:
1060  //
1061 public:
1062  //
1063 private:
1064  //
1065 };
1066 
1067 //----------------------------------------------------------------------------
1068 // ObjectComparison
1069 //----------------------------------------------------------------------------
1070 
1077 
1078 public:
1079  ObjectComparison(const ClassId classId) { m_classId = classId; }
1080 
1081  bool operator()(const Object *object)
1082  {
1083  if (m_classId == UNSPECIFIED) {
1084  return true;
1085  }
1086  return (object->GetClassId() == m_classId);
1087  }
1088 
1089 private:
1090  //
1091 public:
1092  //
1093 private:
1094  ClassId m_classId;
1095 };
1096 
1097 //----------------------------------------------------------------------------
1098 // ObjectFactory
1099 //----------------------------------------------------------------------------
1100 
1102 
1103 public:
1108 
1112  Object *Create(const std::string &name);
1113 
1117  Object *Create(ClassId classId);
1118 
1122  void Register(const std::string &name, ClassId classId, std::function<Object *(void)> function);
1123 
1127  ClassId GetClassId(const std::string &name);
1128 
1132  std::string GetClassName(ClassId classId);
1133 
1137  void GetClassIds(const std::vector<std::string> &classStrings, std::vector<ClassId> &classIds);
1138 
1139 public:
1140  mutable std::shared_mutex m_mutex;
1141  MapOfClassIdConstructors m_ctorsRegistry;
1142  MapOfStrClassIds m_classIdsRegistry;
1143 };
1144 
1145 //----------------------------------------------------------------------------
1146 // ClassRegistrar
1147 //----------------------------------------------------------------------------
1148 
1149 template <class T> class ClassRegistrar {
1150 public:
1154  ClassRegistrar(const std::string &name, ClassId classId)
1155  {
1156  ObjectFactory::GetInstance().Register(name, classId, []() -> Object * { return new T(); });
1157  }
1158 
1163  ClassRegistrar(const std::string &name, ClassId pseudoClassId, std::function<Object *()> factory)
1164  {
1165  ObjectFactory::GetInstance().Register(name, pseudoClassId, factory);
1166  }
1167 };
1168 
1169 } // namespace vrv
1170 
1171 #endif
This class represents a basic object in the layout domain.
Definition: boundingbox.h:32
Definition: object.h:1149
ClassRegistrar(const std::string &name, ClassId pseudoClassId, std::function< Object *()> factory)
The contructor registering the name / constructor map taking a custom factory function.
Definition: object.h:1163
ClassRegistrar(const std::string &name, ClassId classId)
The contructor registering the name / constructor map.
Definition: object.h:1154
Definition: comparison.h:32
This abstract class is the base class for all const functors.
Definition: functor.h:126
This class is used to store comparison filters and apply them when necessary.
Definition: comparison.h:613
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
Unary predicate for comparing object types.
Definition: object.h:1076
Definition: object.h:1101
static ObjectFactory & GetInstance()
A static method returning a static object in order to guarantee initialisation.
void GetClassIds(const std::vector< std::string > &classStrings, std::vector< ClassId > &classIds)
Get the correspondings ClassIds from the vector of MEI element string names.
Object * Create(ClassId classId)
Create the object from the ClassId by making a lookup in the register.
ClassId GetClassId(const std::string &name)
Get the ClassId from the MEI element string name by making a lookup in the register.
void Register(const std::string &name, ClassId classId, std::function< Object *(void)> function)
Add the name / constructor map entry to the static register.
Object * Create(const std::string &name)
Create the object from the MEI element string name by making a lookup in the register.
std::string GetClassName(ClassId classId)
Get the MEI element name from the ClassId by making a lookup in the register.
This class represents a basic object.
Definition: object.h:66
Object * FindDescendantByID(const std::string &id, int deepness=UNLIMITED_DEPTH, bool direction=FORWARD)
Look for a descendant with the specified id (returns NULL if not found) This method is a wrapper for ...
void FindAllDescendantsByComparison(ListOfObjects *objects, Comparison *comparison, int deepness=UNLIMITED_DEPTH, bool direction=FORWARD, bool clear=true)
Return all the objects matching the Comparison functor Deepness allow to limit the depth search (Edit...
void ReplaceWithCopyOf(Object *object)
Replace an object with a copy of the other.
bool HasAttribute(std::string attribute, std::string value) const
Check if an Object has an attribute with the specified value.
void ClearChildren()
Clear the children vector and delete all the objects.
Object * GetFirstChildNot(const ClassId classId)
Return the first child that is NOT of the specified type.
void RotateChildren(int first, int middle, int last)
Rotates the child elements of the object leftwards, using std::rotate() with the given indices.
bool HasDescendant(const Object *child, int deepness=UNLIMITED_DEPTH) const
Return true if the object has the child Object as descendant (reference of direct).
virtual bool IsSupportedChild(ClassId classId)
Base method for checking if a child can be added.
void FillFlatList(ListOfConstObjects &list) const
Fill the list of all the children LayerElement.
virtual int GetInsertOrderFor(ClassId) const
Return the child order for a the given ClassId.
Definition: object.h:453
virtual void CloneReset()
Reset pointers after a copy and assignment constructor call.
int GetIdx() const
Return the index position of the object in its parent (-1 if not found)
Object * FindDescendantByType(ClassId classId, int deepness=UNLIMITED_DEPTH, bool direction=FORWARD)
Look for a descendant with the specified type (returns NULL if not found) This method is a wrapper fo...
void Modify(bool modified=true) const
Mark the object and its parent (if any) as modified.
bool IsFloatingObject() const
Wrapper for checking if an element is a floating object (system elements and control elements)
Definition: object.h:92
Object * GetFirstAncestor(const ClassId classId, int maxSteps=-1)
Return the first ancestor of the specified type.
Object * GetChild(int idx)
Child access (generic)
const Resources * GetDocResources() const
Resource access from the document.
Object * Relinquish(int idx)
Give up ownership of the child at the idx position (NULL if not found) This is a method to be used on...
virtual bool AddChildAdditionalCheck(Object *)
Additional check when adding a child.
Definition: object.h:446
virtual bool CopyChildren() const
Indicate whereas children have to be copied in copy / assignment constructors.
Definition: object.h:284
bool IsModified() const
Check if the content was modified or not.
Definition: object.h:689
virtual FunctorCode Accept(Functor &functor)
Interface for class functor visitation.
ListOfObjects FindAllDescendantsByType(ClassId classId, bool continueDepthSearchForMatches=true, int deepness=UNLIMITED_DEPTH)
Return all the objects with specified type.
void ResetParent()
Reset the parent of the Object.
Definition: object.h:429
void CopyAttributesTo(Object *target) const
Copy all the attributes of an obejct to target.
ArrayOfConstObjects GetChildren() const
Return the children as const reference or copy.
ArrayOfObjects & GetChildrenForModification()
Return a reference to the children that allows modification.
Definition: object.h:358
void ClearRelinquishedChildren()
Removes all the children that were previously relinquished.
Object & operator=(const Object &object)
Copy assignement - see copy constructor.
int GetDescendantIndex(const Object *child, const ClassId classId, int depth)
Look for all Objects of a class and return its position (-1 if not found)
bool IsAncestorOf(const Object *object) const
Check if the object is the ancestor of the other one.
int GetChildIndex(const Object *child) const
Look for the Object in the children and return its position (-1 if not found)
ArrayOfStrAttr m_unsupported
Keep an array of unsupported attributes as pairs.
Definition: object.h:823
Object * FindDescendantByComparison(Comparison *comparison, int deepness=UNLIMITED_DEPTH, bool direction=FORWARD)
Return the first element matching the Comparison functor Deepness allow to limit the depth search (Ed...
void SaveObject(Output *output)
Saves the object (and its children) using the specified output stream.
Object(const Object &object)
Copy constructor that also copy the children.
bool IsMilestoneElement() const
Wrapper for checking if an element has a milestone start interface and also if is set as a milestone ...
Object * GetLastAncestorNot(const ClassId classId, int maxSteps=-1)
Return the last ancestor that is NOT of the specified type.
ListOfObjects GetAncestors()
Returns all ancestors.
Object * FindDescendantExtremeByComparison(Comparison *comparison, int deepness=UNLIMITED_DEPTH, bool direction=FORWARD)
Return the element matching the extreme value with an Comparison functor Deepness allow to limit the ...
void SetAsReferenceObject()
Make an object a reference object that do not own children.
void SetParent(Object *parent)
Set the parent of the Object.
bool DeleteChild(Object *child)
Remove and delete the child.
bool(* binaryComp)(Object *, Object *)
Sort children by a function that takes two arguments and returns true if the first argument is less t...
Definition: object.h:265
Object * GetLast(const ClassId classId=UNSPECIFIED)
Return the last child of the object (if any, NULL otherwise)
void MoveChildrenFrom(Object *sourceParent, int idx=-1, bool allowTypeChange=false)
Move all the children of the object passed as parameter to this one.
std::string GetComment() const
Methods for setting / getting comments.
Definition: object.h:309
void SwapWith(Object *object)
Swap an object with another.
void LogDebugTree(int maxDepth=UNLIMITED_DEPTH, int level=0)
Output the class name of the object (or a custom msg) and of its children recursively.
void Process(Functor &functor, int deepness=UNLIMITED_DEPTH, bool skipFirst=false)
Main method that processes functors.
virtual Object * Clone() const
Method call for copying child classes.
virtual bool AddChild(Object *object)
Base method for adding children.
void ReplaceChild(Object *currentChild, Object *replacingChild)
Replace the currentChild with the replacingChild.
void InsertChild(Object *element, int idx)
Insert an element at the idx position.
void MoveItselfTo(Object *targetParent)
Move an object to another parent.
Object * DetachChild(int idx)
Detach the child at the idx position (NULL if not found) The parent pointer is set to NULL.
void StableSort(Compare comp)
Sort the child elements using std::stable_sort.
Definition: object.h:730
bool HasEditorialContent()
Return true if the object contains any editorial content.
int DeleteChildrenByComparison(Comparison *comparison)
Delete the children that match the comparison.
void FindAllDescendantsBetween(ListOfObjects *objects, Comparison *comparison, const Object *start, const Object *end, bool clear=true, int depth=UNLIMITED_DEPTH)
Return all the objects matching the Comparison functor and being between start and end in the tree.
virtual void Reset()
Reset the object, that is 1) removing all children and 2) resetting all attributes.
Object * GetParent()
Get the parent of the Object.
Definition: object.h:415
bool HasNonEditorialContent()
Return true if the object contains anything that is not editorial content.
static bool IsPreOrdered(const Object *left, const Object *right)
Return true if left appears before right in preorder traversal.
int GetAttributes(ArrayOfStrAttr *attributes, bool convertToExternal=true) const
Fill an array of pairs with all attributes and their values.
int GetInsertOrderForIn(ClassId classId, const std::vector< ClassId > &order) const
Find the order from an overriden GetInsertOrderFor method.
Object * GetDirectChild(Object *parent, Object *descendant)
Return reference to the object that is the ancestor of the indicated descendant object and that is a ...
This class is an pseudo interface for elements maintaining a flat list of children LayerElement for p...
Definition: object.h:937
int GetListIndex(const Object *listElement) const
Look for the Object in the list and return its position (-1 if not found)
const Object * GetListPrevious(const Object *listElement) const
Returns the previous object in the list (NULL if not found)
const Object * GetListNext(const Object *listElement) const
Returns the next object in the list (NULL if not found)
virtual void FilterList(ListOfConstObjects &) const
Filter the list for a specific class.
Definition: object.h:1009
const ListOfConstObjects & GetList() const
Return the list.
const Object * GetListFirst(const Object *startFrom, const ClassId classId=UNSPECIFIED) const
Gets the first item of type elementType starting at startFrom.
void ResetList() const
Reset the list of children and call FilterList().
bool HasEmptyList() const
Convenience functions that check if the list is up-to-date If not, the list is updated before returni...
This class is a base class for output classes.
Definition: iobase.h:31
This class provides resource values.
Definition: resources.h:30
This class is an pseudo interface for elements maintaining a flat list of children LayerElement for p...
Definition: object.h:1036
std::u32string GetText() const
Returns a contatenated version of all the text children.
void FilterList(ListOfConstObjects &childList) const override
Filter the list for a specific class.
void GetTextLines(std::vector< std::u32string > &lines) const
Fill an array of lines with concatenated content of each line.