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 <string>
17 #include <unordered_set>
18 
19 //----------------------------------------------------------------------------
20 
21 #include "attclasses.h"
22 #include "attmodule.h"
23 #include "boundingbox.h"
24 #include "vrvdef.h"
25 
26 namespace vrv {
27 
28 class AltSymInterface;
29 class AreaPosInterface;
30 class Doc;
31 class DurationInterface;
32 class EditorialElement;
33 class Output;
34 class Filters;
35 class Functor;
36 class Functor;
37 class ConstFunctor;
38 class LinkingInterface;
39 class FacsimileInterface;
40 class OffsetInterface;
41 class OffsetSpanningInterface;
42 class PitchInterface;
43 class PositionInterface;
44 class Resources;
45 class ScoreDefInterface;
46 class StemmedDrawingInterface;
47 class TextDirInterface;
48 class TimePointInterface;
49 class TimeSpanningInterface;
50 class VisibilityDrawingInterface;
51 class Zone;
52 
53 #define UNLIMITED_DEPTH -10000
54 #define FORWARD true
55 #define BACKWARD false
56 
57 //----------------------------------------------------------------------------
58 // Object
59 //----------------------------------------------------------------------------
60 
64 class Object : public BoundingBox {
65 public:
71  Object();
72  Object(ClassId classId);
73  virtual ~Object();
74  ClassId GetClassId() const final { return m_classId; }
75  virtual std::string GetClassName() const { return "[MISSING]"; }
77 
84  bool IsReferenceObject() const { return m_isReferenceObject; }
86 
90  bool IsFloatingObject() const { return (this->IsSystemElement() || this->IsControlElement()); }
91 
96  bool IsMilestoneElement() const;
97  Object *GetMilestoneEnd();
99 
105  bool IsControlElement() const { return Object::IsControlElement(m_classId); }
106  bool IsEditorialElement() const { return Object::IsEditorialElement(m_classId); }
107  bool IsLayerElement() const { return Object::IsLayerElement(m_classId); }
108  bool IsPageElement() const { return Object::IsPageElement(m_classId); }
109  bool IsRunningElement() const { return Object::IsRunningElement(m_classId); }
110  bool IsScoreDefElement() const { return Object::IsScoreDefElement(m_classId); }
111  bool IsSystemElement() const { return Object::IsSystemElement(m_classId); }
112  bool IsTextElement() const { return Object::IsTextElement(m_classId); }
114 
121  static bool IsControlElement(ClassId classId)
122  {
123  return ((classId > CONTROL_ELEMENT) && (classId < CONTROL_ELEMENT_max));
124  }
125  static bool IsEditorialElement(ClassId classId)
126  {
127  return ((classId > EDITORIAL_ELEMENT) && (classId < EDITORIAL_ELEMENT_max));
128  }
129  static bool IsLayerElement(ClassId classId) { return ((classId > LAYER_ELEMENT) && (classId < LAYER_ELEMENT_max)); }
130  static bool IsPageElement(ClassId classId) { return ((classId > PAGE_ELEMENT) && (classId < PAGE_ELEMENT_max)); }
131  static bool IsRunningElement(ClassId classId)
132  {
133  return ((classId > RUNNING_ELEMENT) && (classId < RUNNING_ELEMENT_max));
134  }
135  static bool IsScoreDefElement(ClassId classId)
136  {
137  return ((classId > SCOREDEF_ELEMENT) && (classId < SCOREDEF_ELEMENT_max));
138  }
139  static bool IsSystemElement(ClassId classId)
140  {
141  return ((classId > SYSTEM_ELEMENT) && (classId < SYSTEM_ELEMENT_max));
142  }
143  static bool IsTextElement(ClassId classId) { return ((classId > TEXT_ELEMENT) && (classId < TEXT_ELEMENT_max)); }
145 
150  void RegisterAttClass(AttClassId attClassId) { m_attClasses.push_back(attClassId); }
151  bool HasAttClass(AttClassId attClassId) const
152  {
153  return std::find(m_attClasses.begin(), m_attClasses.end(), attClassId) != m_attClasses.end();
154  }
155  void RegisterInterface(std::vector<AttClassId> *attClasses, InterfaceId interfaceId);
156  bool HasInterface(InterfaceId interfaceId) const
157  {
158  return std::find(m_interfaces.begin(), m_interfaces.end(), interfaceId) != m_interfaces.end();
159  }
161 
166  virtual AltSymInterface *GetAltSymInterface() { return NULL; }
167  virtual const AltSymInterface *GetAltSymInterface() const { return NULL; }
168  virtual AreaPosInterface *GetAreaPosInterface() { return NULL; }
169  virtual const AreaPosInterface *GetAreaPosInterface() const { return NULL; }
170  virtual BeamDrawingInterface *GetBeamDrawingInterface() { return NULL; }
171  virtual const BeamDrawingInterface *GetBeamDrawingInterface() const { return NULL; }
172  virtual DurationInterface *GetDurationInterface() { return NULL; }
173  virtual const DurationInterface *GetDurationInterface() const { return NULL; }
174  virtual LinkingInterface *GetLinkingInterface() { return NULL; }
175  virtual const LinkingInterface *GetLinkingInterface() const { return NULL; }
176  virtual FacsimileInterface *GetFacsimileInterface() { return NULL; }
177  virtual const FacsimileInterface *GetFacsimileInterface() const { return NULL; }
178  virtual OffsetInterface *GetOffsetInterface() { return NULL; }
179  virtual const OffsetInterface *GetOffsetInterface() const { return NULL; }
180  virtual OffsetSpanningInterface *GetOffsetSpanningInterface() { return NULL; }
181  virtual const OffsetSpanningInterface *GetOffsetSpanningInterface() const { return NULL; }
182  virtual PitchInterface *GetPitchInterface() { return NULL; }
183  virtual const PitchInterface *GetPitchInterface() const { return NULL; }
184  virtual PlistInterface *GetPlistInterface() { return NULL; }
185  virtual const PlistInterface *GetPlistInterface() const { return NULL; }
186  virtual PositionInterface *GetPositionInterface() { return NULL; }
187  virtual const PositionInterface *GetPositionInterface() const { return NULL; }
188  virtual ScoreDefInterface *GetScoreDefInterface() { return NULL; }
189  virtual const ScoreDefInterface *GetScoreDefInterface() const { return NULL; }
190  virtual StemmedDrawingInterface *GetStemmedDrawingInterface() { return NULL; }
191  virtual const StemmedDrawingInterface *GetStemmedDrawingInterface() const { return NULL; }
192  virtual TextDirInterface *GetTextDirInterface() { return NULL; }
193  virtual const TextDirInterface *GetTextDirInterface() const { return NULL; }
194  virtual TimePointInterface *GetTimePointInterface() { return NULL; }
195  virtual const TimePointInterface *GetTimePointInterface() const { return NULL; }
196  virtual TimeSpanningInterface *GetTimeSpanningInterface() { return NULL; }
197  virtual const TimeSpanningInterface *GetTimeSpanningInterface() const { return NULL; }
198  virtual VisibilityDrawingInterface *GetVisibilityDrawingInterface() { return NULL; }
199  virtual const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const { return NULL; }
201 
205  const Resources *GetDocResources() const;
206 
211  virtual void Reset();
212 
221  Object(const Object &object);
222 
226  Object &operator=(const Object &object);
227 
235  void MoveChildrenFrom(Object *sourceParent, int idx = -1, bool allowTypeChange = false);
236 
241  void ReplaceChild(Object *currentChild, Object *replacingChild);
242 
247  void InsertBefore(Object *child, Object *newChild);
248  void InsertAfter(Object *child, Object *newChild);
250 
256  typedef bool (*binaryComp)(Object *, Object *);
257  void SortChildren(binaryComp comp);
258 
263  void MoveItselfTo(Object *targetParent);
264 
269  virtual Object *Clone() const;
270 
275  virtual bool CopyChildren() const { return true; }
276 
282  virtual void CloneReset();
283 
284  const std::string &GetID() const { return m_id; }
285  void SetID(const std::string &id) { m_id = id; }
286  void SwapID(Object *other);
287  void ResetID();
288 
292  std::string GetComment() const { return m_comment; }
293  void SetComment(std::string comment) { m_comment = comment; }
294  bool HasComment() const { return !m_comment.empty(); }
295  std::string GetClosingComment() const { return m_closingComment; }
296  void SetClosingComment(std::string endComment) { m_closingComment = endComment; }
297  bool HasClosingComment() const { return !m_closingComment.empty(); }
298 
305  int GetChildCount() const { return (int)m_children.size(); }
306  int GetChildCount(const ClassId classId) const;
307  int GetChildCount(const ClassId classId, int depth) const;
308  int GetDescendantCount(const ClassId classId) const;
310 
315  Object *GetChild(int idx);
316  const Object *GetChild(int idx) const;
317  Object *GetChild(int idx, const ClassId classId);
318  const Object *GetChild(int idx, const ClassId classId) const;
320 
327  Object *GetDirectChild(Object *parent, Object *descendant);
328 
333  ArrayOfConstObjects GetChildren() const;
334  const ArrayOfObjects &GetChildren() { return m_children; }
336 
341  ArrayOfObjects &GetChildrenForModification() { return m_children; }
342 
348  void CopyAttributesTo(Object *target) const;
349 
354  int GetAttributes(ArrayOfStrAttr *attributes) const;
355 
359  bool HasAttribute(std::string attribute, std::string value) const;
360 
369  Object *GetFirst(const ClassId classId = UNSPECIFIED);
370  const Object *GetFirst(const ClassId classId = UNSPECIFIED) const;
371  Object *GetNext();
372  const Object *GetNext() const;
374 
380  Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED);
381  const Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED) const;
382  Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED);
383  const Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED) const;
385 
390  Object *GetLast(const ClassId classId = UNSPECIFIED);
391  const Object *GetLast(const ClassId classId = UNSPECIFIED) const;
393 
398  Object *GetParent() { return m_parent; }
399  const Object *GetParent() const { return m_parent; }
401 
406  void SetParent(Object *parent);
407 
412  void ResetParent() { m_parent = NULL; }
413 
418  virtual bool IsSupportedChild(ClassId classId);
419 
424  virtual bool AddChild(Object *object);
425 
429  virtual bool AddChildAdditionalCheck(Object *) { return true; };
430 
436  virtual int GetInsertOrderFor(ClassId) const { return VRV_UNSET; }
437 
441  int GetInsertOrderForIn(ClassId classId, const std::vector<ClassId> &order) const;
442 
446  int GetIdx() const;
447 
452  int GetDrawingX() const override;
453  int GetDrawingY() const override;
455 
461  void ResetCachedDrawingX() const override;
462  void ResetCachedDrawingY() const override;
464 
468  int GetChildIndex(const Object *child) const;
469 
473  int GetDescendantIndex(const Object *child, const ClassId classId, int depth);
474 
478  void InsertChild(Object *element, int idx);
479 
485  void RotateChildren(int first, int middle, int last);
486 
491  Object *DetachChild(int idx);
492 
497  void ReplaceWithCopyOf(Object *object);
498 
503  bool HasDescendant(const Object *child, int deepness = UNLIMITED_DEPTH) const;
504 
510  Object *FindDescendantByID(const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
511  const Object *FindDescendantByID(
512  const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
514 
520  Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
521  const Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
523 
530  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
532  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
534 
541  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
543  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
545 
551  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH);
552  ListOfConstObjects FindAllDescendantsByType(
553  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH) const;
555 
561  void FindAllDescendantsByComparison(ListOfObjects *objects, Comparison *comparison, int deepness = UNLIMITED_DEPTH,
562  bool direction = FORWARD, bool clear = true);
563  void FindAllDescendantsByComparison(ListOfConstObjects *objects, Comparison *comparison,
564  int deepness = UNLIMITED_DEPTH, bool direction = FORWARD, bool clear = true) const;
566 
572  void FindAllDescendantsBetween(ListOfObjects *objects, Comparison *comparison, const Object *start,
573  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH);
574  void FindAllDescendantsBetween(ListOfConstObjects *objects, Comparison *comparison, const Object *start,
575  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH) const;
577 
587  Object *Relinquish(int idx);
588 
594 
599 
604  bool DeleteChild(Object *child);
605 
611 
616  ListOfObjects GetAncestors();
617  ListOfConstObjects GetAncestors() const;
619 
625  Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1);
626  const Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1) const;
628 
630  Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1);
631  const Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1) const;
633 
639  Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1);
640  const Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1) const;
642 
647  Object *GetFirstChildNot(const ClassId classId);
648  const Object *GetFirstChildNot(const ClassId classId) const;
650 
655  void FillFlatList(ListOfConstObjects &list) const;
656 
660  bool IsModified() const { return m_isModified; }
661 
665  void Modify(bool modified = true) const;
666 
671  bool IsAttribute() const { return m_isAttribute; }
672  void IsAttribute(bool isAttribute) { m_isAttribute = isAttribute; }
674 
679  bool IsExpansion() const { return m_isExpansion; }
680  void IsExpansion(bool isExpansion) { m_isExpansion = isExpansion; }
682 
687 
692 
696  void SaveObject(Output *output);
697 
701  template <class Compare> void StableSort(Compare comp)
702  {
703  std::stable_sort(m_children.begin(), m_children.end(), comp);
704  }
705 
706  void ReorderByXPos();
707 
708  Object *FindNextChild(Comparison *comp, Object *start);
709 
710  Object *FindPreviousChild(Comparison *comp, Object *start);
711 
716  bool HasPlistReferences() const { return static_cast<bool>(m_plistReferences); }
717  void ResetPlistReferences() { m_plistReferences.reset(); }
718  const ListOfConstObjects *GetPlistReferences() const { return m_plistReferences.get(); }
719  void AddPlistReference(const Object *object);
721 
731  void Process(Functor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false);
732  void Process(ConstFunctor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false) const;
734 
739  virtual FunctorCode Accept(Functor &functor);
740  virtual FunctorCode Accept(ConstFunctor &functor) const;
741  virtual FunctorCode AcceptEnd(Functor &functor);
742  virtual FunctorCode AcceptEnd(ConstFunctor &functor) const;
744 
749  void LogDebugTree(int maxDepth = UNLIMITED_DEPTH, int level = 0);
750  virtual std::string LogDebugTreeMsg() { return this->GetClassName(); }
752 
753  //----------------//
754  // Static methods //
755  //----------------//
756 
757  static void SeedID(uint32_t seed = 0);
758 
759  static std::string GenerateHashID();
760 
761  static uint32_t Hash(uint32_t number, bool reverse = false);
762 
763  static bool sortByUlx(Object *a, Object *b);
764 
768  static bool IsPreOrdered(const Object *left, const Object *right);
769 
770 private:
774  void GenerateID();
775 
779  void Init(ClassId classId);
780 
785  bool SkipChildren(bool visibleOnly) const;
786  bool FiltersApply(const Filters *filters, Object *object) const;
788 
789 public:
794  ArrayOfStrAttr m_unsupported;
795 
796 protected:
797  //
798 private:
803  ArrayOfObjects m_children;
804 
808  Object *m_parent;
809 
813  ClassId m_classId;
814 
819  std::string m_id;
821 
826  bool m_isReferenceObject;
827 
834  mutable bool m_isModified;
835 
842  mutable ArrayOfObjects::const_iterator m_iteratorEnd, m_iteratorCurrent;
843  mutable ClassId m_iteratorElementType;
845 
849  std::vector<AttClassId> m_attClasses;
850 
854  std::vector<InterfaceId> m_interfaces;
855 
861  std::string m_comment;
862  std::string m_closingComment;
864 
869  bool m_isAttribute;
870 
874  bool m_isExpansion;
875 
880  std::unique_ptr<ListOfConstObjects> m_plistReferences;
881 
882  //----------------//
883  // Static members //
884  //----------------//
885 
889  static thread_local unsigned long s_objectCounter;
890 
894  static thread_local uint32_t s_xmlIDCounter;
895 };
896 
897 //----------------------------------------------------------------------------
898 // ObjectListInterface
899 //----------------------------------------------------------------------------
900 
909 public:
910  // constructors and destructors
911  ObjectListInterface() = default;
912  virtual ~ObjectListInterface() = default;
913  ObjectListInterface(const ObjectListInterface &listInterface); // copy constructor;
914  ObjectListInterface &operator=(const ObjectListInterface &listInterface); // copy assignment;
915 
919  int GetListIndex(const Object *listElement) const;
920 
925  const Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
926  Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED);
927  const Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
928  Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED);
930 
935  const Object *GetListPrevious(const Object *listElement) const;
936  Object *GetListPrevious(const Object *listElement);
938 
943  const Object *GetListNext(const Object *listElement) const;
944  Object *GetListNext(const Object *listElement);
946 
953  const ListOfConstObjects &GetList() const;
954  ListOfObjects GetList();
956 
960  void ResetList() const;
961 
967  bool HasEmptyList() const;
968  int GetListSize() const;
969  const Object *GetListFront() const;
970  Object *GetListFront();
971  const Object *GetListBack() const;
972  Object *GetListBack();
974 
975 protected:
980  virtual void FilterList(ListOfConstObjects &) const {};
981 
982 private:
986  const Object *GetInterfaceOwner() const;
987 
988 public:
989  //
990 private:
991  // The flat list of children
992  mutable ListOfConstObjects m_list;
993  // The owner object
994  mutable const Object *m_owner = NULL;
995 };
996 
997 //----------------------------------------------------------------------------
998 // TextListInterface
999 //----------------------------------------------------------------------------
1000 
1008 public:
1009  // constructors and destructors
1010  TextListInterface() = default;
1011  virtual ~TextListInterface() = default;
1012 
1016  std::u32string GetText() const;
1017 
1021  void GetTextLines(std::vector<std::u32string> &lines) const;
1022 
1023 protected:
1028  void FilterList(ListOfConstObjects &childList) const override;
1029 
1030 private:
1031  //
1032 public:
1033  //
1034 private:
1035  //
1036 };
1037 
1038 //----------------------------------------------------------------------------
1039 // ObjectComparison
1040 //----------------------------------------------------------------------------
1041 
1048 
1049 public:
1050  ObjectComparison(const ClassId classId) { m_classId = classId; }
1051 
1052  bool operator()(const Object *object)
1053  {
1054  if (m_classId == UNSPECIFIED) {
1055  return true;
1056  }
1057  return (object->GetClassId() == m_classId);
1058  }
1059 
1060 private:
1061  //
1062 public:
1063  //
1064 private:
1065  ClassId m_classId;
1066 };
1067 
1068 //----------------------------------------------------------------------------
1069 // ObjectFactory
1070 //----------------------------------------------------------------------------
1071 
1073 
1074 public:
1079 
1083  Object *Create(std::string name);
1084 
1088  Object *Create(ClassId classId);
1089 
1093  void Register(std::string name, ClassId classId, std::function<Object *(void)> function);
1094 
1098  ClassId GetClassId(std::string name);
1099 
1103  void GetClassIds(const std::vector<std::string> &classStrings, std::vector<ClassId> &classIds);
1104 
1105 public:
1106  static thread_local MapOfClassIdConstructors s_ctorsRegistry;
1107  static thread_local MapOfStrClassIds s_classIdsRegistry;
1108 };
1109 
1110 //----------------------------------------------------------------------------
1111 // ClassRegistrar
1112 //----------------------------------------------------------------------------
1113 
1114 template <class T> class ClassRegistrar {
1115 public:
1119  ClassRegistrar(std::string name, ClassId classId)
1120  {
1121  ObjectFactory::GetInstance()->Register(name, classId, []() -> Object * { return new T(); });
1122  }
1123 };
1124 
1125 } // namespace vrv
1126 
1127 #endif
This class represents a basic object in the layout domain.
Definition: boundingbox.h:32
Definition: object.h:1114
ClassRegistrar(std::string name, ClassId classId)
The contructor registering the name / constructor map.
Definition: object.h:1119
Definition: comparison.h:31
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:588
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
Unary predicate for comparing object types.
Definition: object.h:1047
Definition: object.h:1072
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(std::string name)
Get the ClassId from the MEI element string name by making a lookup in the register.
Object * Create(std::string name)
Create the object from the MEI element string name by making a lookup in the register.
void Register(std::string name, ClassId classId, std::function< Object *(void)> function)
Add the name / constructor map entry to the static register.
static ObjectFactory * GetInstance()
A static method returning a static object in order to guarantee initialisation.
This class represents a basic object.
Definition: object.h:64
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:436
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:90
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:429
virtual bool CopyChildren() const
Indicate whereas children have to be copied in copy / assignment constructors.
Definition: object.h:275
bool IsModified() const
Check if the content was modified or not.
Definition: object.h:660
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:412
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:341
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)
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:794
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:256
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:292
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:701
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:398
bool HasNonEditorialContent()
Return true if the object contains anything that is not editorial content.
int GetAttributes(ArrayOfStrAttr *attributes) const
Fill an array of pairs with all attributes and their values.
static bool IsPreOrdered(const Object *left, const Object *right)
Return true if left appears before right in preorder traversal.
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:908
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:980
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:1007
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.