 |
Verovio
Source code documentation
|
8 #ifndef __VRV_OBJECT_H__
9 #define __VRV_OBJECT_H__
19 #include "attclasses.h"
20 #include "attmodule.h"
21 #include "boundingbox.h"
26 class AltSymInterface;
27 class AreaPosInterface;
29 class DurationInterface;
30 class EditorialElement;
36 class LinkingInterface;
37 class FacsimileInterface;
39 class PositionInterface;
41 class ScoreDefInterface;
42 class StemmedDrawingInterface;
43 class TextDirInterface;
44 class TimePointInterface;
45 class TimeSpanningInterface;
48 #define UNLIMITED_DEPTH -10000
50 #define BACKWARD false
69 ClassId GetClassId()
const final {
return m_classId; }
70 virtual std::string GetClassName()
const {
return "[MISSING]"; }
79 bool IsReferenceObject()
const {
return m_isReferenceObject; }
85 bool IsFloatingObject()
const {
return (this->IsSystemElement() || this->IsControlElement()); }
99 bool IsControlElement()
const {
return Object::IsControlElement(m_classId); }
101 bool IsEditorialElement()
const {
return Object::IsEditorialElement(m_classId); }
102 bool IsLayerElement()
const {
return Object::IsLayerElement(m_classId); }
103 bool IsPageElement()
const {
return Object::IsPageElement(m_classId); }
104 bool IsRunningElement()
const {
return Object::IsRunningElement(m_classId); }
105 bool IsScoreDefElement()
const {
return Object::IsScoreDefElement(m_classId); }
106 bool IsSystemElement()
const {
return Object::IsSystemElement(m_classId); }
107 bool IsTextElement()
const {
return Object::IsTextElement(m_classId); }
115 static bool IsControlElement(ClassId classId)
118 return ((classId > CONTROL_ELEMENT) && (classId < CONTROL_ELEMENT_max));
120 static bool IsEditorialElement(ClassId classId)
122 return ((classId > EDITORIAL_ELEMENT) && (classId < EDITORIAL_ELEMENT_max));
124 static bool IsLayerElement(ClassId classId) {
return ((classId > LAYER_ELEMENT) && (classId < LAYER_ELEMENT_max)); }
125 static bool IsPageElement(ClassId classId) {
return ((classId > PAGE_ELEMENT) && (classId < PAGE_ELEMENT_max)); }
126 static bool IsRunningElement(ClassId classId)
128 return ((classId > RUNNING_ELEMENT) && (classId < RUNNING_ELEMENT_max));
130 static bool IsScoreDefElement(ClassId classId)
132 return ((classId > SCOREDEF_ELEMENT) && (classId < SCOREDEF_ELEMENT_max));
134 static bool IsSystemElement(ClassId classId)
136 return ((classId > SYSTEM_ELEMENT) && (classId < SYSTEM_ELEMENT_max));
138 static bool IsTextElement(ClassId classId) {
return ((classId > TEXT_ELEMENT) && (classId < TEXT_ELEMENT_max)); }
144 void RegisterAttClass(AttClassId attClassId) { m_attClasses.push_back(attClassId); }
146 bool HasAttClass(AttClassId attClassId)
const
148 return std::find(m_attClasses.begin(), m_attClasses.end(), attClassId) != m_attClasses.end();
150 void RegisterInterface(std::vector<AttClassId> *attClasses, InterfaceId interfaceId);
151 bool HasInterface(InterfaceId interfaceId)
const
153 return std::find(m_interfaces.begin(), m_interfaces.end(), interfaceId) != m_interfaces.end();
160 virtual AltSymInterface *GetAltSymInterface() {
return NULL; }
162 virtual const AltSymInterface *GetAltSymInterface()
const {
return NULL; }
163 virtual AreaPosInterface *GetAreaPosInterface() {
return NULL; }
164 virtual const AreaPosInterface *GetAreaPosInterface()
const {
return NULL; }
165 virtual BeamDrawingInterface *GetBeamDrawingInterface() {
return NULL; }
166 virtual const BeamDrawingInterface *GetBeamDrawingInterface()
const {
return NULL; }
167 virtual DurationInterface *GetDurationInterface() {
return NULL; }
168 virtual const DurationInterface *GetDurationInterface()
const {
return NULL; }
169 virtual LinkingInterface *GetLinkingInterface() {
return NULL; }
170 virtual const LinkingInterface *GetLinkingInterface()
const {
return NULL; }
171 virtual FacsimileInterface *GetFacsimileInterface() {
return NULL; }
172 virtual const FacsimileInterface *GetFacsimileInterface()
const {
return NULL; }
173 virtual PitchInterface *GetPitchInterface() {
return NULL; }
174 virtual const PitchInterface *GetPitchInterface()
const {
return NULL; }
175 virtual PlistInterface *GetPlistInterface() {
return NULL; }
176 virtual const PlistInterface *GetPlistInterface()
const {
return NULL; }
177 virtual PositionInterface *GetPositionInterface() {
return NULL; }
178 virtual const PositionInterface *GetPositionInterface()
const {
return NULL; }
179 virtual ScoreDefInterface *GetScoreDefInterface() {
return NULL; }
180 virtual const ScoreDefInterface *GetScoreDefInterface()
const {
return NULL; }
181 virtual StemmedDrawingInterface *GetStemmedDrawingInterface() {
return NULL; }
182 virtual const StemmedDrawingInterface *GetStemmedDrawingInterface()
const {
return NULL; }
183 virtual TextDirInterface *GetTextDirInterface() {
return NULL; }
184 virtual const TextDirInterface *GetTextDirInterface()
const {
return NULL; }
185 virtual TimePointInterface *GetTimePointInterface() {
return NULL; }
186 virtual const TimePointInterface *GetTimePointInterface()
const {
return NULL; }
187 virtual TimeSpanningInterface *GetTimeSpanningInterface() {
return NULL; }
188 virtual const TimeSpanningInterface *GetTimeSpanningInterface()
const {
return NULL; }
200 virtual void Reset();
210 Object(
const Object &
object);
224 void MoveChildrenFrom(Object *sourceParent,
int idx = -1,
bool allowTypeChange =
false);
230 void ReplaceChild(Object *currentChild, Object *replacingChild);
235 void InsertBefore(Object *child, Object *newChild);
237 void InsertAfter(Object *child, Object *newChild);
273 const std::string &GetID()
const {
return m_id; }
274 void SetID(
const std::string &
id) { m_id = id; }
275 void SwapID(Object *other);
282 void SetComment(std::string comment) { m_comment = comment; }
283 bool HasComment()
const {
return !m_comment.empty(); }
284 std::string GetClosingComment()
const {
return m_closingComment; }
285 void SetClosingComment(std::string endComment) { m_closingComment = endComment; }
286 bool HasClosingComment()
const {
return !m_closingComment.empty(); }
293 int GetChildCount()
const {
return (
int)m_children.size(); }
295 int GetChildCount(
const ClassId classId)
const;
296 int GetChildCount(
const ClassId classId,
int depth)
const;
297 int GetDescendantCount(
const ClassId classId)
const;
305 const Object *
GetChild(
int idx)
const;
306 Object *
GetChild(
int idx,
const ClassId classId);
307 const Object *
GetChild(
int idx,
const ClassId classId)
const;
315 const ArrayOfObjects &
GetChildren() {
return m_children; }
340 bool HasAttribute(std::string attribute, std::string value)
const;
349 Object *GetFirst(
const ClassId classId = UNSPECIFIED);
351 const Object *GetFirst(
const ClassId classId = UNSPECIFIED)
const;
353 const Object *GetNext()
const;
360 Object *GetNext(
const Object *child,
const ClassId classId = UNSPECIFIED);
362 const Object *GetNext(
const Object *child,
const ClassId classId = UNSPECIFIED)
const;
363 Object *GetPrevious(
const Object *child,
const ClassId classId = UNSPECIFIED);
364 const Object *GetPrevious(
const Object *child,
const ClassId classId = UNSPECIFIED)
const;
372 const Object *
GetLast(
const ClassId classId = UNSPECIFIED)
const;
380 const Object *
GetParent()
const {
return m_parent; }
432 int GetDrawingX()
const override;
434 int GetDrawingY()
const override;
441 void ResetCachedDrawingX()
const override;
443 void ResetCachedDrawingY()
const override;
493 const std::string &
id,
int deepness = UNLIMITED_DEPTH,
bool direction = FORWARD)
const;
511 Comparison *comparison,
int deepness = UNLIMITED_DEPTH,
bool direction = FORWARD);
513 Comparison *comparison,
int deepness = UNLIMITED_DEPTH,
bool direction = FORWARD)
const;
522 Comparison *comparison,
int deepness = UNLIMITED_DEPTH,
bool direction = FORWARD);
524 Comparison *comparison,
int deepness = UNLIMITED_DEPTH,
bool direction = FORWARD)
const;
532 ClassId classId,
bool continueDepthSearchForMatches =
true,
int deepness = UNLIMITED_DEPTH);
534 ClassId classId,
bool continueDepthSearchForMatches =
true,
int deepness = UNLIMITED_DEPTH)
const;
543 bool direction = FORWARD,
bool clear =
true);
545 int deepness = UNLIMITED_DEPTH,
bool direction = FORWARD,
bool clear =
true)
const;
554 const Object *end,
bool clear =
true,
int depth = UNLIMITED_DEPTH);
556 const Object *end,
bool clear =
true,
int depth = UNLIMITED_DEPTH)
const;
611 Object *GetFirstAncestorInRange(
const ClassId classIdMin,
const ClassId classIdMax,
int maxDepth = -1);
612 const Object *GetFirstAncestorInRange(
const ClassId classIdMin,
const ClassId classIdMax,
int maxDepth = -1)
const;
646 void Modify(
bool modified =
true)
const;
651 bool IsAttribute()
const {
return m_isAttribute; }
653 void IsAttribute(
bool isAttribute) { m_isAttribute = isAttribute; }
659 bool IsExpansion()
const {
return m_isExpansion; }
661 void IsExpansion(
bool isExpansion) { m_isExpansion = isExpansion; }
684 std::stable_sort(m_children.begin(), m_children.end(), comp);
687 void ReorderByXPos();
701 void Process(
Functor &functor,
int deepness = UNLIMITED_DEPTH,
bool skipFirst =
false);
703 void Process(
ConstFunctor &functor,
int deepness = UNLIMITED_DEPTH,
bool skipFirst =
false)
const;
712 virtual FunctorCode AcceptEnd(
Functor &functor);
713 virtual FunctorCode AcceptEnd(
ConstFunctor &functor)
const;
719 void LogDebugTree(
int maxDepth = UNLIMITED_DEPTH,
int level = 0);
721 virtual std::string LogDebugTreeMsg() {
return this->GetClassName(); }
728 static void SeedID(uint32_t seed = 0);
730 static std::string GenerateHashID();
732 static uint32_t Hash(uint32_t number,
bool reverse =
false);
734 static bool sortByUlx(Object *a, Object *b);
739 static bool IsPreOrdered(
const Object *left,
const Object *right);
750 void Init(ClassId classId);
755 bool SkipChildren(
bool visibleOnly)
const;
757 bool FiltersApply(
const Filters *filters, Object *
object)
const;
774 ArrayOfObjects m_children;
797 bool m_isReferenceObject;
805 mutable bool m_isModified;
812 mutable ArrayOfObjects::const_iterator m_iteratorEnd, m_iteratorCurrent;
814 mutable ClassId m_iteratorElementType;
820 std::vector<AttClassId> m_attClasses;
825 std::vector<InterfaceId> m_interfaces;
832 std::string m_comment;
833 std::string m_closingComment;
854 static thread_local
unsigned long s_objectCounter;
859 static thread_local uint32_t s_xmlIDCounter;
892 const Object *GetListFirstBackward(
const Object *startFrom,
const ClassId classId = UNSPECIFIED)
const;
893 Object *GetListFirstBackward(
const Object *startFrom,
const ClassId classId = UNSPECIFIED);
917 const ListOfConstObjects &
GetList()
const;
933 int GetListSize()
const;
934 const Object *GetListFront()
const;
936 const Object *GetListBack()
const;
945 virtual void FilterList(ListOfConstObjects &childList)
const {};
951 const Object *GetInterfaceOwner()
const;
957 mutable ListOfConstObjects m_list;
959 mutable const Object *m_owner = NULL;
981 std::u32string
GetText()
const;
986 void GetTextLines(std::vector<std::u32string> &lines)
const;
993 void FilterList(ListOfConstObjects &childList)
const override;
1017 bool operator()(
const Object *
object)
1019 if (m_classId == UNSPECIFIED) {
1022 return (object->GetClassId() == m_classId);
1058 void Register(std::string name, ClassId classId, std::function<
Object *(
void)>
function);
1068 void GetClassIds(
const std::vector<std::string> &classStrings, std::vector<ClassId> &classIds);
1071 static thread_local MapOfClassIdConstructors s_ctorsRegistry;
1072 static thread_local MapOfStrClassIds s_classIdsRegistry;
void CopyAttributesTo(Object *target) const
Copy all the attributes of an obejct to target.
void Process(Functor &functor, int deepness=UNLIMITED_DEPTH, bool skipFirst=false)
Main method that processes functors.
ClassId GetClassId(std::string name)
Get the ClassId from the MEI element string name by making a lookup in the register.
Object * GetParent()
Get the parent of the Object.
Definition: object.h:379
ClassRegistrar(std::string name, ClassId classId)
The contructor registering the name / constructor map.
Definition: object.h:1084
bool IsMilestoneElement()
Wrapper for checking if an element has a milestone start interface and also if is set as a milestone ...
ListOfObjects GetAncestors()
Returns all ancestors.
void MoveItselfTo(Object *targetParent)
Move an object to another parent.
const Object * GetListPrevious(const Object *listElement) const
Returns the previous object in the list (NULL if not found)
virtual void AddChild(Object *object)
Base method for adding children.
virtual void FilterList(ListOfConstObjects &childList) const
Filter the list for a specific class.
Definition: object.h:945
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 SaveObject(Output *output, bool basic)
Saves the object (and its children) using the specified output stream.
int GetChildIndex(const Object *child) const
Look for the Object in the children and return its position (-1 if not found)
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:245
const Object * GetListFirst(const Object *startFrom, const ClassId classId=UNSPECIFIED) const
Gets the first item of type elementType starting at startFrom.
virtual FunctorCode Accept(Functor &functor)
Interface for class functor visitation.
Unary predicate for comparing object types.
Definition: object.h:1012
bool HasEmptyList() const
Convenience functions that check if the list is up-to-date If not, the list is updated before returni...
void RotateChildren(int first, int middle, int last)
Rotates the child elements of the object leftwards, using std::rotate() with the given indices.
int GetIdx() const
Return the index position of the object in its parent (-1 if not found)
Object * GetFirstChildNot(const ClassId classId)
Return the first child that is NOT of the specified type.
This class represents a basic object.
Definition: object.h:59
virtual void CloneReset()
Reset pointers after a copy and assignment constructor call.
Object * Create(std::string name)
Create the object from the MEI element string name by making a lookup in the register.
void ResetList() const
Reset the list of children and call FilterList().
int GetListIndex(const Object *listElement) const
Look for the Object in the list and return its position (-1 if not found)
void GetTextLines(std::vector< std::u32string > &lines) const
Fill an array of lines with concatenated content of each line.
bool HasNonEditorialContent()
Return true if the object contains anything that is not editorial content.
Object * GetChild(int idx)
Child access (generic)
Object * GetFirstAncestor(const ClassId classId, int maxSteps=-1)
Return the first ancestor of the specified type.
void FilterList(ListOfConstObjects &childList) const override
Filter the list for a specific class.
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 FillFlatList(ListOfConstObjects &list) const
Fill the list of all the children LayerElement.
static bool IsPreOrdered(const Object *left, const Object *right)
Return true if left appears before right in preorder traversal.
const ListOfConstObjects & GetList() const
Return the list.
void MoveChildrenFrom(Object *sourceParent, int idx=-1, bool allowTypeChange=false)
Move all the children of the object passed as parameter to this one.
void ReplaceChild(Object *currentChild, Object *replacingChild)
Replace the currentChild with the replacingChild.
virtual bool IsSupportedChild(ClassId classId)
Base method for checking if a child can be added.
bool DeleteChild(Object *child)
Remove and delete the child.
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
void Modify(bool modified=true) const
Mark the object and its parent (if any) as modified.
virtual Object * Clone() const
Method call for copying child classes.
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)
ArrayOfObjects & GetChildrenForModification()
Return a reference to the children that allows modification.
Definition: object.h:322
ListOfObjects FindAllDescendantsByType(ClassId classId, bool continueDepthSearchForMatches=true, int deepness=UNLIMITED_DEPTH)
Return all the objects with specified type.
This class is an pseudo interface for elements maintaining a flat list of children LayerElement for p...
Definition: object.h:972
This class is an pseudo interface for elements maintaining a flat list of children LayerElement for p...
Definition: object.h:873
Object * DetachChild(int idx)
Detach the child at the idx position (NULL if not found) The parent pointer is set to NULL.
void SetParent(Object *parent)
Set the parent of the Object.
Object & operator=(const Object &object)
Copy assignement - see copy constructor.
ArrayOfStrAttr m_unsupported
Keep an array of unsupported attributes as pairs.
Definition: object.h:765
Definition: object.h:1037
virtual void Reset()
Reset the object, that is 1) removing all children and 2) resetting all attributes.
This abstract class is the base class for all const functors.
Definition: functor.h:126
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 ...
Definition: object.h:1079
bool HasAttribute(std::string attribute, std::string value) const
Check if an Object has an attribute with the specified value.
bool IsFloatingObject() const
Wrapper for checking if an element is a floating object (system elements and control elements)
Definition: object.h:85
static ObjectFactory * GetInstance()
A static method returning a static object in order to guarantee initialisation.
void ClearRelinquishedChildren()
Removes all the children that were previously relinquished.
const Object * GetListNext(const Object *listElement) const
Returns the next object in the list (NULL if not found)
int GetAttributes(ArrayOfStrAttr *attributes) const
Fill an array of pairs with all attributes and their values.
void ReplaceWithCopyOf(Object *object)
Replace an object with a copy of the other.
Object * GetLastAncestorNot(const ClassId classId, int maxSteps=-1)
Return the last ancestor that is NOT of the specified type.
bool HasEditorialContent()
Return true if the object contains any editorial content.
void GetClassIds(const std::vector< std::string > &classStrings, std::vector< ClassId > &classIds)
Get the correspondings ClassIds from the vector of MEI element string names.
virtual bool AddChildAdditionalCheck(Object *child)
Additional check when adding a child.
Definition: object.h:410
Object * GetLast(const ClassId classId=UNSPECIFIED)
Return the last child of the object (if any, NULL otherwise)
void StableSort(Compare comp)
Sort the child elements using std::stable_sort.
Definition: object.h:682
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.
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...
bool IsModified() const
Check if the content was modified or not.
Definition: object.h:641
std::u32string GetText() const
Returns a contatenated version of all the text children.
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...
const Resources * GetDocResources() const
Resource access from the document.
bool HasDescendant(const Object *child, int deepness=UNLIMITED_DEPTH) const
Return true if the object has the child Object as descendant (reference of direct).
ArrayOfConstObjects GetChildren() const
Return the children as const reference or copy.
This class represents a basic object in the layout domain.
Definition: boundingbox.h:32
virtual bool CopyChildren() const
Indicate whereas children have to be copied in copy / assignment constructors.
Definition: object.h:264
void ClearChildren()
Clear the children vector and delete all the objects.
std::string GetComment() const
Methods for setting / getting comments.
Definition: object.h:281
void SetAsReferenceObject()
Make an object a reference object that do not own children.
void ResetParent()
Reset the parent of the Object.
Definition: object.h:393
int GetInsertOrderForIn(ClassId classId, const std::vector< ClassId > &order) const
Find the order from an overriden GetInsertOrderFor method.
void Register(std::string name, ClassId classId, std::function< Object *(void)> function)
Add the name / constructor map entry to the static register.
int DeleteChildrenByComparison(Comparison *comparison)
Delete the children that match the comparison.
Definition: comparison.h:31
virtual int GetInsertOrderFor(ClassId classId) const
Return the child order for a the given ClassId.
Definition: object.h:417
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 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.
void InsertChild(Object *element, int idx)
Insert an element at the idx position.