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 PitchInterface;
41 class PositionInterface;
42 class Resources;
43 class ScoreDefInterface;
44 class StemmedDrawingInterface;
45 class TextDirInterface;
46 class TimePointInterface;
47 class TimeSpanningInterface;
48 class VisibilityDrawingInterface;
49 class Zone;
50 
51 #define UNLIMITED_DEPTH -10000
52 #define FORWARD true
53 #define BACKWARD false
54 
55 //----------------------------------------------------------------------------
56 // Object
57 //----------------------------------------------------------------------------
58 
62 class Object : public BoundingBox {
63 public:
69  Object();
70  Object(ClassId classId);
71  virtual ~Object();
72  ClassId GetClassId() const final { return m_classId; }
73  virtual std::string GetClassName() const { return "[MISSING]"; }
75 
82  bool IsReferenceObject() const { return m_isReferenceObject; }
84 
88  bool IsFloatingObject() const { return (this->IsSystemElement() || this->IsControlElement()); }
89 
94  bool IsMilestoneElement() const;
95  Object *GetMilestoneEnd();
97 
103  bool IsControlElement() const { return Object::IsControlElement(m_classId); }
104  bool IsEditorialElement() const { return Object::IsEditorialElement(m_classId); }
105  bool IsLayerElement() const { return Object::IsLayerElement(m_classId); }
106  bool IsPageElement() const { return Object::IsPageElement(m_classId); }
107  bool IsRunningElement() const { return Object::IsRunningElement(m_classId); }
108  bool IsScoreDefElement() const { return Object::IsScoreDefElement(m_classId); }
109  bool IsSystemElement() const { return Object::IsSystemElement(m_classId); }
110  bool IsTextElement() const { return Object::IsTextElement(m_classId); }
112 
119  static bool IsControlElement(ClassId classId)
120  {
121  return ((classId > CONTROL_ELEMENT) && (classId < CONTROL_ELEMENT_max));
122  }
123  static bool IsEditorialElement(ClassId classId)
124  {
125  return ((classId > EDITORIAL_ELEMENT) && (classId < EDITORIAL_ELEMENT_max));
126  }
127  static bool IsLayerElement(ClassId classId) { return ((classId > LAYER_ELEMENT) && (classId < LAYER_ELEMENT_max)); }
128  static bool IsPageElement(ClassId classId) { return ((classId > PAGE_ELEMENT) && (classId < PAGE_ELEMENT_max)); }
129  static bool IsRunningElement(ClassId classId)
130  {
131  return ((classId > RUNNING_ELEMENT) && (classId < RUNNING_ELEMENT_max));
132  }
133  static bool IsScoreDefElement(ClassId classId)
134  {
135  return ((classId > SCOREDEF_ELEMENT) && (classId < SCOREDEF_ELEMENT_max));
136  }
137  static bool IsSystemElement(ClassId classId)
138  {
139  return ((classId > SYSTEM_ELEMENT) && (classId < SYSTEM_ELEMENT_max));
140  }
141  static bool IsTextElement(ClassId classId) { return ((classId > TEXT_ELEMENT) && (classId < TEXT_ELEMENT_max)); }
143 
148  void RegisterAttClass(AttClassId attClassId) { m_attClasses.push_back(attClassId); }
149  bool HasAttClass(AttClassId attClassId) const
150  {
151  return std::find(m_attClasses.begin(), m_attClasses.end(), attClassId) != m_attClasses.end();
152  }
153  void RegisterInterface(std::vector<AttClassId> *attClasses, InterfaceId interfaceId);
154  bool HasInterface(InterfaceId interfaceId) const
155  {
156  return std::find(m_interfaces.begin(), m_interfaces.end(), interfaceId) != m_interfaces.end();
157  }
159 
164  virtual AltSymInterface *GetAltSymInterface() { return NULL; }
165  virtual const AltSymInterface *GetAltSymInterface() const { return NULL; }
166  virtual AreaPosInterface *GetAreaPosInterface() { return NULL; }
167  virtual const AreaPosInterface *GetAreaPosInterface() const { return NULL; }
168  virtual BeamDrawingInterface *GetBeamDrawingInterface() { return NULL; }
169  virtual const BeamDrawingInterface *GetBeamDrawingInterface() const { return NULL; }
170  virtual DurationInterface *GetDurationInterface() { return NULL; }
171  virtual const DurationInterface *GetDurationInterface() const { return NULL; }
172  virtual LinkingInterface *GetLinkingInterface() { return NULL; }
173  virtual const LinkingInterface *GetLinkingInterface() const { return NULL; }
174  virtual FacsimileInterface *GetFacsimileInterface() { return NULL; }
175  virtual const FacsimileInterface *GetFacsimileInterface() const { return NULL; }
176  virtual PitchInterface *GetPitchInterface() { return NULL; }
177  virtual const PitchInterface *GetPitchInterface() const { return NULL; }
178  virtual PlistInterface *GetPlistInterface() { return NULL; }
179  virtual const PlistInterface *GetPlistInterface() const { return NULL; }
180  virtual PositionInterface *GetPositionInterface() { return NULL; }
181  virtual const PositionInterface *GetPositionInterface() const { return NULL; }
182  virtual ScoreDefInterface *GetScoreDefInterface() { return NULL; }
183  virtual const ScoreDefInterface *GetScoreDefInterface() const { return NULL; }
184  virtual StemmedDrawingInterface *GetStemmedDrawingInterface() { return NULL; }
185  virtual const StemmedDrawingInterface *GetStemmedDrawingInterface() const { return NULL; }
186  virtual TextDirInterface *GetTextDirInterface() { return NULL; }
187  virtual const TextDirInterface *GetTextDirInterface() const { return NULL; }
188  virtual TimePointInterface *GetTimePointInterface() { return NULL; }
189  virtual const TimePointInterface *GetTimePointInterface() const { return NULL; }
190  virtual TimeSpanningInterface *GetTimeSpanningInterface() { return NULL; }
191  virtual const TimeSpanningInterface *GetTimeSpanningInterface() const { return NULL; }
192  virtual VisibilityDrawingInterface *GetVisibilityDrawingInterface() { return NULL; }
193  virtual const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const { return NULL; }
195 
199  const Resources *GetDocResources() const;
200 
205  virtual void Reset();
206 
215  Object(const Object &object);
216 
220  Object &operator=(const Object &object);
221 
229  void MoveChildrenFrom(Object *sourceParent, int idx = -1, bool allowTypeChange = false);
230 
235  void ReplaceChild(Object *currentChild, Object *replacingChild);
236 
241  void InsertBefore(Object *child, Object *newChild);
242  void InsertAfter(Object *child, Object *newChild);
244 
250  typedef bool (*binaryComp)(Object *, Object *);
251  void SortChildren(binaryComp comp);
252 
257  void MoveItselfTo(Object *targetParent);
258 
263  virtual Object *Clone() const;
264 
269  virtual bool CopyChildren() const { return true; }
270 
276  virtual void CloneReset();
277 
278  const std::string &GetID() const { return m_id; }
279  void SetID(const std::string &id) { m_id = id; }
280  void SwapID(Object *other);
281  void ResetID();
282 
286  std::string GetComment() const { return m_comment; }
287  void SetComment(std::string comment) { m_comment = comment; }
288  bool HasComment() const { return !m_comment.empty(); }
289  std::string GetClosingComment() const { return m_closingComment; }
290  void SetClosingComment(std::string endComment) { m_closingComment = endComment; }
291  bool HasClosingComment() const { return !m_closingComment.empty(); }
292 
299  int GetChildCount() const { return (int)m_children.size(); }
300  int GetChildCount(const ClassId classId) const;
301  int GetChildCount(const ClassId classId, int depth) const;
302  int GetDescendantCount(const ClassId classId) const;
304 
309  Object *GetChild(int idx);
310  const Object *GetChild(int idx) const;
311  Object *GetChild(int idx, const ClassId classId);
312  const Object *GetChild(int idx, const ClassId classId) const;
314 
321  Object *GetDirectChild(Object *parent, Object *descendant);
322 
327  ArrayOfConstObjects GetChildren() const;
328  const ArrayOfObjects &GetChildren() { return m_children; }
330 
335  ArrayOfObjects &GetChildrenForModification() { return m_children; }
336 
342  void CopyAttributesTo(Object *target) const;
343 
348  int GetAttributes(ArrayOfStrAttr *attributes) const;
349 
353  bool HasAttribute(std::string attribute, std::string value) const;
354 
363  Object *GetFirst(const ClassId classId = UNSPECIFIED);
364  const Object *GetFirst(const ClassId classId = UNSPECIFIED) const;
365  Object *GetNext();
366  const Object *GetNext() const;
368 
374  Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED);
375  const Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED) const;
376  Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED);
377  const Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED) const;
379 
384  Object *GetLast(const ClassId classId = UNSPECIFIED);
385  const Object *GetLast(const ClassId classId = UNSPECIFIED) const;
387 
392  Object *GetParent() { return m_parent; }
393  const Object *GetParent() const { return m_parent; }
395 
400  void SetParent(Object *parent);
401 
406  void ResetParent() { m_parent = NULL; }
407 
412  virtual bool IsSupportedChild(ClassId classId);
413 
418  virtual bool AddChild(Object *object);
419 
423  virtual bool AddChildAdditionalCheck(Object *) { return true; };
424 
430  virtual int GetInsertOrderFor(ClassId) const { return VRV_UNSET; }
431 
435  int GetInsertOrderForIn(ClassId classId, const std::vector<ClassId> &order) const;
436 
440  int GetIdx() const;
441 
446  int GetDrawingX() const override;
447  int GetDrawingY() const override;
449 
455  void ResetCachedDrawingX() const override;
456  void ResetCachedDrawingY() const override;
458 
462  int GetChildIndex(const Object *child) const;
463 
467  int GetDescendantIndex(const Object *child, const ClassId classId, int depth);
468 
472  void InsertChild(Object *element, int idx);
473 
479  void RotateChildren(int first, int middle, int last);
480 
485  Object *DetachChild(int idx);
486 
491  void ReplaceWithCopyOf(Object *object);
492 
497  bool HasDescendant(const Object *child, int deepness = UNLIMITED_DEPTH) const;
498 
504  Object *FindDescendantByID(const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
505  const Object *FindDescendantByID(
506  const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
508 
514  Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
515  const Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
517 
524  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
526  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
528 
535  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
537  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
539 
545  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH);
546  ListOfConstObjects FindAllDescendantsByType(
547  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH) const;
549 
555  void FindAllDescendantsByComparison(ListOfObjects *objects, Comparison *comparison, int deepness = UNLIMITED_DEPTH,
556  bool direction = FORWARD, bool clear = true);
557  void FindAllDescendantsByComparison(ListOfConstObjects *objects, Comparison *comparison,
558  int deepness = UNLIMITED_DEPTH, bool direction = FORWARD, bool clear = true) const;
560 
566  void FindAllDescendantsBetween(ListOfObjects *objects, Comparison *comparison, const Object *start,
567  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH);
568  void FindAllDescendantsBetween(ListOfConstObjects *objects, Comparison *comparison, const Object *start,
569  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH) const;
571 
581  Object *Relinquish(int idx);
582 
588 
593 
598  bool DeleteChild(Object *child);
599 
605 
610  ListOfObjects GetAncestors();
611  ListOfConstObjects GetAncestors() const;
613 
619  Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1);
620  const Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1) const;
622 
624  Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1);
625  const Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1) const;
627 
633  Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1);
634  const Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1) const;
636 
641  Object *GetFirstChildNot(const ClassId classId);
642  const Object *GetFirstChildNot(const ClassId classId) const;
644 
649  void FillFlatList(ListOfConstObjects &list) const;
650 
654  bool IsModified() const { return m_isModified; }
655 
659  void Modify(bool modified = true) const;
660 
665  bool IsAttribute() const { return m_isAttribute; }
666  void IsAttribute(bool isAttribute) { m_isAttribute = isAttribute; }
668 
673  bool IsExpansion() const { return m_isExpansion; }
674  void IsExpansion(bool isExpansion) { m_isExpansion = isExpansion; }
676 
681 
686 
690  void SaveObject(Output *output);
691 
695  template <class Compare> void StableSort(Compare comp)
696  {
697  std::stable_sort(m_children.begin(), m_children.end(), comp);
698  }
699 
700  void ReorderByXPos();
701 
702  Object *FindNextChild(Comparison *comp, Object *start);
703 
704  Object *FindPreviousChild(Comparison *comp, Object *start);
705 
710  bool HasPlistReferences() const { return static_cast<bool>(m_plistReferences); }
711  void ResetPlistReferences() { m_plistReferences.reset(); }
712  const ListOfConstObjects *GetPlistReferences() const { return m_plistReferences.get(); }
713  void AddPlistReference(const Object *object);
715 
725  void Process(Functor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false);
726  void Process(ConstFunctor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false) const;
728 
733  virtual FunctorCode Accept(Functor &functor);
734  virtual FunctorCode Accept(ConstFunctor &functor) const;
735  virtual FunctorCode AcceptEnd(Functor &functor);
736  virtual FunctorCode AcceptEnd(ConstFunctor &functor) const;
738 
743  void LogDebugTree(int maxDepth = UNLIMITED_DEPTH, int level = 0);
744  virtual std::string LogDebugTreeMsg() { return this->GetClassName(); }
746 
747  //----------------//
748  // Static methods //
749  //----------------//
750 
751  static void SeedID(uint32_t seed = 0);
752 
753  static std::string GenerateHashID();
754 
755  static uint32_t Hash(uint32_t number, bool reverse = false);
756 
757  static bool sortByUlx(Object *a, Object *b);
758 
762  static bool IsPreOrdered(const Object *left, const Object *right);
763 
764 private:
768  void GenerateID();
769 
773  void Init(ClassId classId);
774 
779  bool SkipChildren(bool visibleOnly) const;
780  bool FiltersApply(const Filters *filters, Object *object) const;
782 
783 public:
788  ArrayOfStrAttr m_unsupported;
789 
790 protected:
791  //
792 private:
797  ArrayOfObjects m_children;
798 
802  Object *m_parent;
803 
807  ClassId m_classId;
808 
813  std::string m_id;
815 
820  bool m_isReferenceObject;
821 
828  mutable bool m_isModified;
829 
836  mutable ArrayOfObjects::const_iterator m_iteratorEnd, m_iteratorCurrent;
837  mutable ClassId m_iteratorElementType;
839 
843  std::vector<AttClassId> m_attClasses;
844 
848  std::vector<InterfaceId> m_interfaces;
849 
855  std::string m_comment;
856  std::string m_closingComment;
858 
863  bool m_isAttribute;
864 
868  bool m_isExpansion;
869 
874  std::unique_ptr<ListOfConstObjects> m_plistReferences;
875 
876  //----------------//
877  // Static members //
878  //----------------//
879 
883  static thread_local unsigned long s_objectCounter;
884 
888  static thread_local uint32_t s_xmlIDCounter;
889 };
890 
891 //----------------------------------------------------------------------------
892 // ObjectListInterface
893 //----------------------------------------------------------------------------
894 
903 public:
904  // constructors and destructors
905  ObjectListInterface() = default;
906  virtual ~ObjectListInterface() = default;
907  ObjectListInterface(const ObjectListInterface &listInterface); // copy constructor;
908  ObjectListInterface &operator=(const ObjectListInterface &listInterface); // copy assignment;
909 
913  int GetListIndex(const Object *listElement) const;
914 
919  const Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
920  Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED);
921  const Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
922  Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED);
924 
929  const Object *GetListPrevious(const Object *listElement) const;
930  Object *GetListPrevious(const Object *listElement);
932 
937  const Object *GetListNext(const Object *listElement) const;
938  Object *GetListNext(const Object *listElement);
940 
947  const ListOfConstObjects &GetList() const;
948  ListOfObjects GetList();
950 
954  void ResetList() const;
955 
961  bool HasEmptyList() const;
962  int GetListSize() const;
963  const Object *GetListFront() const;
964  Object *GetListFront();
965  const Object *GetListBack() const;
966  Object *GetListBack();
968 
969 protected:
974  virtual void FilterList(ListOfConstObjects &) const {};
975 
976 private:
980  const Object *GetInterfaceOwner() const;
981 
982 public:
983  //
984 private:
985  // The flat list of children
986  mutable ListOfConstObjects m_list;
987  // The owner object
988  mutable const Object *m_owner = NULL;
989 };
990 
991 //----------------------------------------------------------------------------
992 // TextListInterface
993 //----------------------------------------------------------------------------
994 
1002 public:
1003  // constructors and destructors
1004  TextListInterface() = default;
1005  virtual ~TextListInterface() = default;
1006 
1010  std::u32string GetText() const;
1011 
1015  void GetTextLines(std::vector<std::u32string> &lines) const;
1016 
1017 protected:
1022  void FilterList(ListOfConstObjects &childList) const override;
1023 
1024 private:
1025  //
1026 public:
1027  //
1028 private:
1029  //
1030 };
1031 
1032 //----------------------------------------------------------------------------
1033 // ObjectComparison
1034 //----------------------------------------------------------------------------
1035 
1042 
1043 public:
1044  ObjectComparison(const ClassId classId) { m_classId = classId; }
1045 
1046  bool operator()(const Object *object)
1047  {
1048  if (m_classId == UNSPECIFIED) {
1049  return true;
1050  }
1051  return (object->GetClassId() == m_classId);
1052  }
1053 
1054 private:
1055  //
1056 public:
1057  //
1058 private:
1059  ClassId m_classId;
1060 };
1061 
1062 //----------------------------------------------------------------------------
1063 // ObjectFactory
1064 //----------------------------------------------------------------------------
1065 
1067 
1068 public:
1073 
1077  Object *Create(std::string name);
1078 
1082  Object *Create(ClassId classId);
1083 
1087  void Register(std::string name, ClassId classId, std::function<Object *(void)> function);
1088 
1092  ClassId GetClassId(std::string name);
1093 
1097  void GetClassIds(const std::vector<std::string> &classStrings, std::vector<ClassId> &classIds);
1098 
1099 public:
1100  static thread_local MapOfClassIdConstructors s_ctorsRegistry;
1101  static thread_local MapOfStrClassIds s_classIdsRegistry;
1102 };
1103 
1104 //----------------------------------------------------------------------------
1105 // ClassRegistrar
1106 //----------------------------------------------------------------------------
1107 
1108 template <class T> class ClassRegistrar {
1109 public:
1113  ClassRegistrar(std::string name, ClassId classId)
1114  {
1115  ObjectFactory::GetInstance()->Register(name, classId, []() -> Object * { return new T(); });
1116  }
1117 };
1118 
1119 } // namespace vrv
1120 
1121 #endif
This class represents a basic object in the layout domain.
Definition: boundingbox.h:32
Definition: object.h:1108
ClassRegistrar(std::string name, ClassId classId)
The contructor registering the name / constructor map.
Definition: object.h:1113
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:1041
Definition: object.h:1066
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:62
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:430
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:88
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:423
virtual bool CopyChildren() const
Indicate whereas children have to be copied in copy / assignment constructors.
Definition: object.h:269
bool IsModified() const
Check if the content was modified or not.
Definition: object.h:654
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:406
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:335
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:788
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:250
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:286
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:695
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:392
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:902
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:974
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:1001
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.