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 
18 //----------------------------------------------------------------------------
19 
20 #include "attclasses.h"
21 #include "attmodule.h"
22 #include "boundingbox.h"
23 #include "vrvdef.h"
24 
25 namespace vrv {
26 
27 class AltSymInterface;
28 class AreaPosInterface;
29 class Doc;
30 class DurationInterface;
31 class EditorialElement;
32 class Output;
33 class Filters;
34 class Functor;
35 class Functor;
36 class ConstFunctor;
37 class LinkingInterface;
38 class FacsimileInterface;
39 class PitchInterface;
40 class PositionInterface;
41 class Resources;
42 class ScoreDefInterface;
43 class StemmedDrawingInterface;
44 class TextDirInterface;
45 class TimePointInterface;
46 class TimeSpanningInterface;
47 class VisibilityDrawingInterface;
48 class Zone;
49 
50 #define UNLIMITED_DEPTH -10000
51 #define FORWARD true
52 #define BACKWARD false
53 
54 //----------------------------------------------------------------------------
55 // Object
56 //----------------------------------------------------------------------------
57 
61 class Object : public BoundingBox {
62 public:
68  Object();
69  Object(ClassId classId);
70  virtual ~Object();
71  ClassId GetClassId() const final { return m_classId; }
72  virtual std::string GetClassName() const { return "[MISSING]"; }
74 
81  bool IsReferenceObject() const { return m_isReferenceObject; }
83 
87  bool IsFloatingObject() const { return (this->IsSystemElement() || this->IsControlElement()); }
88 
93  bool IsMilestoneElement() const;
94  Object *GetMilestoneEnd();
96 
102  bool IsControlElement() const { return Object::IsControlElement(m_classId); }
103  bool IsEditorialElement() const { return Object::IsEditorialElement(m_classId); }
104  bool IsLayerElement() const { return Object::IsLayerElement(m_classId); }
105  bool IsPageElement() const { return Object::IsPageElement(m_classId); }
106  bool IsRunningElement() const { return Object::IsRunningElement(m_classId); }
107  bool IsScoreDefElement() const { return Object::IsScoreDefElement(m_classId); }
108  bool IsSystemElement() const { return Object::IsSystemElement(m_classId); }
109  bool IsTextElement() const { return Object::IsTextElement(m_classId); }
111 
118  static bool IsControlElement(ClassId classId)
119  {
120  return ((classId > CONTROL_ELEMENT) && (classId < CONTROL_ELEMENT_max));
121  }
122  static bool IsEditorialElement(ClassId classId)
123  {
124  return ((classId > EDITORIAL_ELEMENT) && (classId < EDITORIAL_ELEMENT_max));
125  }
126  static bool IsLayerElement(ClassId classId) { return ((classId > LAYER_ELEMENT) && (classId < LAYER_ELEMENT_max)); }
127  static bool IsPageElement(ClassId classId) { return ((classId > PAGE_ELEMENT) && (classId < PAGE_ELEMENT_max)); }
128  static bool IsRunningElement(ClassId classId)
129  {
130  return ((classId > RUNNING_ELEMENT) && (classId < RUNNING_ELEMENT_max));
131  }
132  static bool IsScoreDefElement(ClassId classId)
133  {
134  return ((classId > SCOREDEF_ELEMENT) && (classId < SCOREDEF_ELEMENT_max));
135  }
136  static bool IsSystemElement(ClassId classId)
137  {
138  return ((classId > SYSTEM_ELEMENT) && (classId < SYSTEM_ELEMENT_max));
139  }
140  static bool IsTextElement(ClassId classId) { return ((classId > TEXT_ELEMENT) && (classId < TEXT_ELEMENT_max)); }
142 
147  void RegisterAttClass(AttClassId attClassId) { m_attClasses.push_back(attClassId); }
148  bool HasAttClass(AttClassId attClassId) const
149  {
150  return std::find(m_attClasses.begin(), m_attClasses.end(), attClassId) != m_attClasses.end();
151  }
152  void RegisterInterface(std::vector<AttClassId> *attClasses, InterfaceId interfaceId);
153  bool HasInterface(InterfaceId interfaceId) const
154  {
155  return std::find(m_interfaces.begin(), m_interfaces.end(), interfaceId) != m_interfaces.end();
156  }
158 
163  virtual AltSymInterface *GetAltSymInterface() { return NULL; }
164  virtual const AltSymInterface *GetAltSymInterface() const { return NULL; }
165  virtual AreaPosInterface *GetAreaPosInterface() { return NULL; }
166  virtual const AreaPosInterface *GetAreaPosInterface() const { return NULL; }
167  virtual BeamDrawingInterface *GetBeamDrawingInterface() { return NULL; }
168  virtual const BeamDrawingInterface *GetBeamDrawingInterface() const { return NULL; }
169  virtual DurationInterface *GetDurationInterface() { return NULL; }
170  virtual const DurationInterface *GetDurationInterface() const { return NULL; }
171  virtual LinkingInterface *GetLinkingInterface() { return NULL; }
172  virtual const LinkingInterface *GetLinkingInterface() const { return NULL; }
173  virtual FacsimileInterface *GetFacsimileInterface() { return NULL; }
174  virtual const FacsimileInterface *GetFacsimileInterface() const { return NULL; }
175  virtual PitchInterface *GetPitchInterface() { return NULL; }
176  virtual const PitchInterface *GetPitchInterface() const { return NULL; }
177  virtual PlistInterface *GetPlistInterface() { return NULL; }
178  virtual const PlistInterface *GetPlistInterface() const { return NULL; }
179  virtual PositionInterface *GetPositionInterface() { return NULL; }
180  virtual const PositionInterface *GetPositionInterface() const { return NULL; }
181  virtual ScoreDefInterface *GetScoreDefInterface() { return NULL; }
182  virtual const ScoreDefInterface *GetScoreDefInterface() const { return NULL; }
183  virtual StemmedDrawingInterface *GetStemmedDrawingInterface() { return NULL; }
184  virtual const StemmedDrawingInterface *GetStemmedDrawingInterface() const { return NULL; }
185  virtual TextDirInterface *GetTextDirInterface() { return NULL; }
186  virtual const TextDirInterface *GetTextDirInterface() const { return NULL; }
187  virtual TimePointInterface *GetTimePointInterface() { return NULL; }
188  virtual const TimePointInterface *GetTimePointInterface() const { return NULL; }
189  virtual TimeSpanningInterface *GetTimeSpanningInterface() { return NULL; }
190  virtual const TimeSpanningInterface *GetTimeSpanningInterface() const { return NULL; }
191  virtual VisibilityDrawingInterface *GetVisibilityDrawingInterface() { return NULL; }
192  virtual const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const { return NULL; }
194 
198  const Resources *GetDocResources() const;
199 
204  virtual void Reset();
205 
214  Object(const Object &object);
215 
219  Object &operator=(const Object &object);
220 
228  void MoveChildrenFrom(Object *sourceParent, int idx = -1, bool allowTypeChange = false);
229 
234  void ReplaceChild(Object *currentChild, Object *replacingChild);
235 
240  void InsertBefore(Object *child, Object *newChild);
241  void InsertAfter(Object *child, Object *newChild);
243 
249  typedef bool (*binaryComp)(Object *, Object *);
250  void SortChildren(binaryComp comp);
251 
256  void MoveItselfTo(Object *targetParent);
257 
262  virtual Object *Clone() const;
263 
268  virtual bool CopyChildren() const { return true; }
269 
275  virtual void CloneReset();
276 
277  const std::string &GetID() const { return m_id; }
278  void SetID(const std::string &id) { m_id = id; }
279  void SwapID(Object *other);
280  void ResetID();
281 
285  std::string GetComment() const { return m_comment; }
286  void SetComment(std::string comment) { m_comment = comment; }
287  bool HasComment() const { return !m_comment.empty(); }
288  std::string GetClosingComment() const { return m_closingComment; }
289  void SetClosingComment(std::string endComment) { m_closingComment = endComment; }
290  bool HasClosingComment() const { return !m_closingComment.empty(); }
291 
298  int GetChildCount() const { return (int)m_children.size(); }
299  int GetChildCount(const ClassId classId) const;
300  int GetChildCount(const ClassId classId, int depth) const;
301  int GetDescendantCount(const ClassId classId) const;
303 
308  Object *GetChild(int idx);
309  const Object *GetChild(int idx) const;
310  Object *GetChild(int idx, const ClassId classId);
311  const Object *GetChild(int idx, const ClassId classId) const;
313 
318  ArrayOfConstObjects GetChildren() const;
319  const ArrayOfObjects &GetChildren() { return m_children; }
321 
326  ArrayOfObjects &GetChildrenForModification() { return m_children; }
327 
333  void CopyAttributesTo(Object *target) const;
334 
339  int GetAttributes(ArrayOfStrAttr *attributes) const;
340 
344  bool HasAttribute(std::string attribute, std::string value) const;
345 
354  Object *GetFirst(const ClassId classId = UNSPECIFIED);
355  const Object *GetFirst(const ClassId classId = UNSPECIFIED) const;
356  Object *GetNext();
357  const Object *GetNext() const;
359 
365  Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED);
366  const Object *GetNext(const Object *child, const ClassId classId = UNSPECIFIED) const;
367  Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED);
368  const Object *GetPrevious(const Object *child, const ClassId classId = UNSPECIFIED) const;
370 
375  Object *GetLast(const ClassId classId = UNSPECIFIED);
376  const Object *GetLast(const ClassId classId = UNSPECIFIED) const;
378 
383  Object *GetParent() { return m_parent; }
384  const Object *GetParent() const { return m_parent; }
386 
391  void SetParent(Object *parent);
392 
397  void ResetParent() { m_parent = NULL; }
398 
403  virtual bool IsSupportedChild(ClassId classId);
404 
409  virtual void AddChild(Object *object);
410 
414  virtual bool AddChildAdditionalCheck(Object *) { return true; };
415 
421  virtual int GetInsertOrderFor(ClassId) const { return VRV_UNSET; }
422 
426  int GetInsertOrderForIn(ClassId classId, const std::vector<ClassId> &order) const;
427 
431  int GetIdx() const;
432 
437  int GetDrawingX() const override;
438  int GetDrawingY() const override;
440 
446  void ResetCachedDrawingX() const override;
447  void ResetCachedDrawingY() const override;
449 
453  int GetChildIndex(const Object *child) const;
454 
458  int GetDescendantIndex(const Object *child, const ClassId classId, int depth);
459 
463  void InsertChild(Object *element, int idx);
464 
470  void RotateChildren(int first, int middle, int last);
471 
476  Object *DetachChild(int idx);
477 
482  void ReplaceWithCopyOf(Object *object);
483 
488  bool HasDescendant(const Object *child, int deepness = UNLIMITED_DEPTH) const;
489 
495  Object *FindDescendantByID(const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
496  const Object *FindDescendantByID(
497  const std::string &id, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
499 
505  Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
506  const Object *FindDescendantByType(ClassId classId, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
508 
515  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
517  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
519 
526  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD);
528  Comparison *comparison, int deepness = UNLIMITED_DEPTH, bool direction = FORWARD) const;
530 
536  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH);
537  ListOfConstObjects FindAllDescendantsByType(
538  ClassId classId, bool continueDepthSearchForMatches = true, int deepness = UNLIMITED_DEPTH) const;
540 
546  void FindAllDescendantsByComparison(ListOfObjects *objects, Comparison *comparison, int deepness = UNLIMITED_DEPTH,
547  bool direction = FORWARD, bool clear = true);
548  void FindAllDescendantsByComparison(ListOfConstObjects *objects, Comparison *comparison,
549  int deepness = UNLIMITED_DEPTH, bool direction = FORWARD, bool clear = true) const;
551 
557  void FindAllDescendantsBetween(ListOfObjects *objects, Comparison *comparison, const Object *start,
558  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH);
559  void FindAllDescendantsBetween(ListOfConstObjects *objects, Comparison *comparison, const Object *start,
560  const Object *end, bool clear = true, int depth = UNLIMITED_DEPTH) const;
562 
572  Object *Relinquish(int idx);
573 
579 
584 
589  bool DeleteChild(Object *child);
590 
596 
601  ListOfObjects GetAncestors();
602  ListOfConstObjects GetAncestors() const;
604 
610  Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1);
611  const Object *GetFirstAncestor(const ClassId classId, int maxSteps = -1) const;
613 
615  Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1);
616  const Object *GetFirstAncestorInRange(const ClassId classIdMin, const ClassId classIdMax, int maxDepth = -1) const;
618 
624  Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1);
625  const Object *GetLastAncestorNot(const ClassId classId, int maxSteps = -1) const;
627 
632  Object *GetFirstChildNot(const ClassId classId);
633  const Object *GetFirstChildNot(const ClassId classId) const;
635 
640  void FillFlatList(ListOfConstObjects &list) const;
641 
645  bool IsModified() const { return m_isModified; }
646 
650  void Modify(bool modified = true) const;
651 
656  bool IsAttribute() const { return m_isAttribute; }
657  void IsAttribute(bool isAttribute) { m_isAttribute = isAttribute; }
659 
664  bool IsExpansion() const { return m_isExpansion; }
665  void IsExpansion(bool isExpansion) { m_isExpansion = isExpansion; }
667 
672 
677 
681  void SaveObject(Output *output);
682 
686  template <class Compare> void StableSort(Compare comp)
687  {
688  std::stable_sort(m_children.begin(), m_children.end(), comp);
689  }
690 
691  void ReorderByXPos();
692 
693  Object *FindNextChild(Comparison *comp, Object *start);
694 
695  Object *FindPreviousChild(Comparison *comp, Object *start);
696 
701  bool HasPlistReferences() const { return static_cast<bool>(m_plistReferences); }
702  void ResetPlistReferences() { m_plistReferences.reset(); }
703  const ListOfConstObjects *GetPlistReferences() const { return m_plistReferences.get(); }
704  void AddPlistReference(const Object *object);
706 
716  void Process(Functor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false);
717  void Process(ConstFunctor &functor, int deepness = UNLIMITED_DEPTH, bool skipFirst = false) const;
719 
724  virtual FunctorCode Accept(Functor &functor);
725  virtual FunctorCode Accept(ConstFunctor &functor) const;
726  virtual FunctorCode AcceptEnd(Functor &functor);
727  virtual FunctorCode AcceptEnd(ConstFunctor &functor) const;
729 
734  void LogDebugTree(int maxDepth = UNLIMITED_DEPTH, int level = 0);
735  virtual std::string LogDebugTreeMsg() { return this->GetClassName(); }
737 
738  //----------------//
739  // Static methods //
740  //----------------//
741 
742  static void SeedID(uint32_t seed = 0);
743 
744  static std::string GenerateHashID();
745 
746  static uint32_t Hash(uint32_t number, bool reverse = false);
747 
748  static bool sortByUlx(Object *a, Object *b);
749 
753  static bool IsPreOrdered(const Object *left, const Object *right);
754 
755 private:
759  void GenerateID();
760 
764  void Init(ClassId classId);
765 
770  bool SkipChildren(bool visibleOnly) const;
771  bool FiltersApply(const Filters *filters, Object *object) const;
773 
774 public:
779  ArrayOfStrAttr m_unsupported;
780 
781 protected:
782  //
783 private:
788  ArrayOfObjects m_children;
789 
793  Object *m_parent;
794 
798  ClassId m_classId;
799 
804  std::string m_id;
806 
811  bool m_isReferenceObject;
812 
819  mutable bool m_isModified;
820 
827  mutable ArrayOfObjects::const_iterator m_iteratorEnd, m_iteratorCurrent;
828  mutable ClassId m_iteratorElementType;
830 
834  std::vector<AttClassId> m_attClasses;
835 
839  std::vector<InterfaceId> m_interfaces;
840 
846  std::string m_comment;
847  std::string m_closingComment;
849 
854  bool m_isAttribute;
855 
859  bool m_isExpansion;
860 
865  std::unique_ptr<ListOfConstObjects> m_plistReferences;
866 
867  //----------------//
868  // Static members //
869  //----------------//
870 
874  static thread_local unsigned long s_objectCounter;
875 
879  static thread_local uint32_t s_xmlIDCounter;
880 };
881 
882 //----------------------------------------------------------------------------
883 // ObjectListInterface
884 //----------------------------------------------------------------------------
885 
894 public:
895  // constructors and destructors
896  ObjectListInterface() = default;
897  virtual ~ObjectListInterface() = default;
898  ObjectListInterface(const ObjectListInterface &listInterface); // copy constructor;
899  ObjectListInterface &operator=(const ObjectListInterface &listInterface); // copy assignment;
900 
904  int GetListIndex(const Object *listElement) const;
905 
910  const Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
911  Object *GetListFirst(const Object *startFrom, const ClassId classId = UNSPECIFIED);
912  const Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED) const;
913  Object *GetListFirstBackward(const Object *startFrom, const ClassId classId = UNSPECIFIED);
915 
920  const Object *GetListPrevious(const Object *listElement) const;
921  Object *GetListPrevious(const Object *listElement);
923 
928  const Object *GetListNext(const Object *listElement) const;
929  Object *GetListNext(const Object *listElement);
931 
938  const ListOfConstObjects &GetList() const;
939  ListOfObjects GetList();
941 
945  void ResetList() const;
946 
952  bool HasEmptyList() const;
953  int GetListSize() const;
954  const Object *GetListFront() const;
955  Object *GetListFront();
956  const Object *GetListBack() const;
957  Object *GetListBack();
959 
960 protected:
965  virtual void FilterList(ListOfConstObjects &) const {};
966 
967 private:
971  const Object *GetInterfaceOwner() const;
972 
973 public:
974  //
975 private:
976  // The flat list of children
977  mutable ListOfConstObjects m_list;
978  // The owner object
979  mutable const Object *m_owner = NULL;
980 };
981 
982 //----------------------------------------------------------------------------
983 // TextListInterface
984 //----------------------------------------------------------------------------
985 
993 public:
994  // constructors and destructors
995  TextListInterface() = default;
996  virtual ~TextListInterface() = default;
997 
1001  std::u32string GetText() const;
1002 
1006  void GetTextLines(std::vector<std::u32string> &lines) const;
1007 
1008 protected:
1013  void FilterList(ListOfConstObjects &childList) const override;
1014 
1015 private:
1016  //
1017 public:
1018  //
1019 private:
1020  //
1021 };
1022 
1023 //----------------------------------------------------------------------------
1024 // ObjectComparison
1025 //----------------------------------------------------------------------------
1026 
1033 
1034 public:
1035  ObjectComparison(const ClassId classId) { m_classId = classId; }
1036 
1037  bool operator()(const Object *object)
1038  {
1039  if (m_classId == UNSPECIFIED) {
1040  return true;
1041  }
1042  return (object->GetClassId() == m_classId);
1043  }
1044 
1045 private:
1046  //
1047 public:
1048  //
1049 private:
1050  ClassId m_classId;
1051 };
1052 
1053 //----------------------------------------------------------------------------
1054 // ObjectFactory
1055 //----------------------------------------------------------------------------
1056 
1058 
1059 public:
1064 
1068  Object *Create(std::string name);
1069 
1073  Object *Create(ClassId classId);
1074 
1078  void Register(std::string name, ClassId classId, std::function<Object *(void)> function);
1079 
1083  ClassId GetClassId(std::string name);
1084 
1088  void GetClassIds(const std::vector<std::string> &classStrings, std::vector<ClassId> &classIds);
1089 
1090 public:
1091  static thread_local MapOfClassIdConstructors s_ctorsRegistry;
1092  static thread_local MapOfStrClassIds s_classIdsRegistry;
1093 };
1094 
1095 //----------------------------------------------------------------------------
1096 // ClassRegistrar
1097 //----------------------------------------------------------------------------
1098 
1099 template <class T> class ClassRegistrar {
1100 public:
1104  ClassRegistrar(std::string name, ClassId classId)
1105  {
1106  ObjectFactory::GetInstance()->Register(name, classId, []() -> Object * { return new T(); });
1107  }
1108 };
1109 
1110 } // namespace vrv
1111 
1112 #endif
This class represents a basic object in the layout domain.
Definition: boundingbox.h:32
Definition: object.h:1099
ClassRegistrar(std::string name, ClassId classId)
The contructor registering the name / constructor map.
Definition: object.h:1104
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:1032
Definition: object.h:1057
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:61
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:421
virtual void CloneReset()
Reset pointers after a copy and assignment constructor call.
virtual void AddChild(Object *object)
Base method for adding children.
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:87
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:414
virtual bool CopyChildren() const
Indicate whereas children have to be copied in copy / assignment constructors.
Definition: object.h:268
bool IsModified() const
Check if the content was modified or not.
Definition: object.h:645
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:397
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:326
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:779
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:249
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:285
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.
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:686
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:383
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.
This class is an pseudo interface for elements maintaining a flat list of children LayerElement for p...
Definition: object.h:893
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:965
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:992
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.