diff --git a/src/meiattribute.cpp b/src/meiattribute.cpp index 99df9993..a0dabba3 100644 --- a/src/meiattribute.cpp +++ b/src/meiattribute.cpp @@ -17,11 +17,11 @@ bool mei::MeiAttribute::operator==(const MeiAttribute &other) const { this->value == other.value); } -string mei::MeiAttribute::getName() { +string mei::MeiAttribute::getName() const { return this->name; } -string mei::MeiAttribute::getValue() { +string mei::MeiAttribute::getValue() const { return this->value; } @@ -29,10 +29,10 @@ void mei::MeiAttribute::setValue(string attrvalue) { this->value = attrvalue; } -MeiElement* mei::MeiAttribute::getElement() { +MeiElement* mei::MeiAttribute::getElement() const { return this->element; } void mei::MeiAttribute::setElement(MeiElement *el) { this->element = el; -} \ No newline at end of file +} diff --git a/src/meiattribute.h b/src/meiattribute.h index 4dceb8a6..a55bd1c3 100644 --- a/src/meiattribute.h +++ b/src/meiattribute.h @@ -57,17 +57,17 @@ namespace mei { * Each attribute is created with a name and value, the attribute cannot exist without a name * \return string containing the attribute name. */ - std::string getName(); + std::string getName() const; /** \brief Get the value of the attribute. * \return A string indicating the attribute value */ - std::string getValue(); + std::string getValue() const; /** \brief Set/change the value of an attribute*/ void setValue(std::string attrvalue); - MeiElement* getElement(); + MeiElement* getElement() const; void setElement(MeiElement* el); private: diff --git a/src/meidocument.cpp b/src/meidocument.cpp index 63c00ad9..f43ad729 100644 --- a/src/meidocument.cpp +++ b/src/meidocument.cpp @@ -110,7 +110,7 @@ vector mei::MeiDocument::getElementsByName(string name) { return ret; } -int mei::MeiDocument::getPositionInDocument(MeiElement* element) { +int mei::MeiDocument::getPositionInDocument(MeiElement* element) const { vector els = this->getFlattenedTree(); vector::iterator pos = find(els.begin(), els.end(), element); if (pos != els.end()) { @@ -120,7 +120,7 @@ int mei::MeiDocument::getPositionInDocument(MeiElement* element) { return -1; } -const std::vector &mei::MeiDocument::getFlattenedTree() { +const std::vector &mei::MeiDocument::getFlattenedTree() const { return flattenedDoc; } diff --git a/src/meidocument.h b/src/meidocument.h index 36aff087..deee834b 100644 --- a/src/meidocument.h +++ b/src/meidocument.h @@ -85,7 +85,7 @@ class MEI_EXPORT MeiDocument { /** \brief Gets an element's position in the flattened * tree representation. */ - int getPositionInDocument(MeiElement* element); + int getPositionInDocument(MeiElement* element) const; /** * \brief Adds an ID and an element to the ID Map. @@ -104,7 +104,7 @@ class MEI_EXPORT MeiDocument { void rmIdMap(std::string id); /** \brief Returns the flattened document tree */ - const std::vector &getFlattenedTree(); + const std::vector &getFlattenedTree() const; /** \brief Returns the most immediate previous element elName, given a starting point */ diff --git a/src/meielement.cpp b/src/meielement.cpp index a261ce9b..9828fb24 100644 --- a/src/meielement.cpp +++ b/src/meielement.cpp @@ -98,7 +98,7 @@ void mei::MeiElement::generateAndSetId() { this->setId(out); } -const string mei::MeiElement::getId() { +const string mei::MeiElement::getId() const { return this->id; } @@ -110,11 +110,11 @@ bool mei::MeiElement::hasId() { return this->id != ""; } -const string mei::MeiElement::getName() { +const string mei::MeiElement::getName() const { return this->name; } -const string mei::MeiElement::getValue() { +const string mei::MeiElement::getValue() const { return this->value; } @@ -122,7 +122,7 @@ void mei::MeiElement::setValue(string value) { this->value = value; } -const string mei::MeiElement::getTail() { +const string mei::MeiElement::getTail() const { return this->tail; } @@ -130,7 +130,7 @@ void mei::MeiElement::setTail(string tail) { this->tail = tail; } -const vector& mei::MeiElement::getAttributes() { +const vector& mei::MeiElement::getAttributes() const { return this->attributes; } @@ -142,8 +142,8 @@ void mei::MeiElement::setAttributes(const vector attrs) { } } -MeiAttribute* mei::MeiElement::getAttribute(string name) { - for (vector::iterator iter = attributes.begin(); iter != attributes.end(); ++iter) { +MeiAttribute* mei::MeiElement::getAttribute(string name) const { + for (vector::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) { if ((*iter)->getName() == name) { return *iter; } @@ -151,10 +151,10 @@ MeiAttribute* mei::MeiElement::getAttribute(string name) { return NULL; } -bool mei::MeiElement::hasAttribute(string name) { +bool mei::MeiElement::hasAttribute(string name) const { if (attributes.empty()) return false; - for (vector::iterator iter = attributes.begin(); iter != attributes.end(); ++iter) { + for (vector::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) { if ((*iter)->getName() == name) return true; } return false; @@ -191,7 +191,7 @@ void mei::MeiElement::removeAttribute(string name) { } } -bool mei::MeiElement::hasParent() { +bool mei::MeiElement::hasParent() const { return parent != NULL; } @@ -199,7 +199,7 @@ void mei::MeiElement::setParent(MeiElement *parent) { this->parent = parent; } -mei::MeiElement* mei::MeiElement::getParent() { +mei::MeiElement* mei::MeiElement::getParent() const { return this->parent; } @@ -218,7 +218,7 @@ void mei::MeiElement::setDocument(MeiDocument *document) throw(DocumentRootNotSe } } -MeiDocument* mei::MeiElement::getDocument() { +MeiDocument* mei::MeiElement::getDocument() const { return this->document; } @@ -272,13 +272,13 @@ void mei::MeiElement::setChildren(vector children) { updateDocument(); } -const vector& mei::MeiElement::getChildren() { +const vector& mei::MeiElement::getChildren() const { return this->children; } -const vector mei::MeiElement::getChildrenByName(string name) { +const vector mei::MeiElement::getChildrenByName(string name) const { vector res; - for (vector::iterator iter = this->children.begin(); iter != this->children.end(); ++iter) { + for (vector::const_iterator iter = this->children.begin(); iter != this->children.end(); ++iter) { if ((*iter)->getName() == name) { res.push_back(*iter); } @@ -324,19 +324,19 @@ void mei::MeiElement::removeChildrenByName(string name) { updateDocument(); } -bool mei::MeiElement::hasChildren() { +bool mei::MeiElement::hasChildren() const { // topsy-turvy world! returns true if not empty. return !this->children.empty(); } -bool mei::MeiElement::hasChildren(string cname) { - for (vector::iterator iter = this->children.begin(); iter != this->children.end(); ++iter) { +bool mei::MeiElement::hasChildren(string cname) const { + for (vector::const_iterator iter = this->children.begin(); iter != this->children.end(); ++iter) { if ((*iter)->getName() == cname) return true; } return false; } -mei::MeiElement* mei::MeiElement::getAncestor(string name) { +mei::MeiElement* mei::MeiElement::getAncestor(string name) const { if (parent == NULL) { return NULL; } @@ -346,7 +346,7 @@ mei::MeiElement* mei::MeiElement::getAncestor(string name) { return parent->getAncestor(name); } -bool mei::MeiElement::hasAncestor(string name) { +bool mei::MeiElement::hasAncestor(string name) const { MeiElement* m = getAncestor(name); if (m != NULL) { return true; @@ -372,7 +372,7 @@ vector mei::MeiElement::getDescendantsByName(string name) { return res; } -vector mei::MeiElement::getPeers() { +vector mei::MeiElement::getPeers() const { if (this->parent) { return this->parent->getChildren(); } diff --git a/src/meielement.h b/src/meielement.h index f469331e..5114e417 100644 --- a/src/meielement.h +++ b/src/meielement.h @@ -82,7 +82,7 @@ class MEI_EXPORT MeiElement /** \brief Get the id of this element. */ - const std::string getId(); + const std::string getId() const; /** \brief Set an element's ID. * This is not always necessary since an element @@ -97,14 +97,14 @@ class MEI_EXPORT MeiElement /** \brief Get the name of this element */ - const std::string getName(); + const std::string getName() const; /** \brief get the xml tail of an Mei Element * * \return The xml tail associated with the Mei Element or * an empty string if the Mei Element has no tail */ - const std::string getTail(); + const std::string getTail() const; /** \brief Set the xml tail associated with the Mei Element */ void setTail(std::string tail); @@ -114,7 +114,7 @@ class MEI_EXPORT MeiElement * \return A string indicating the value of the Mei Element or * an empty string if the element has no value */ - const std::string getValue(); + const std::string getValue() const; /** \brief Set the value associated with the Mei Element */ void setValue(std::string value); @@ -123,7 +123,7 @@ class MEI_EXPORT MeiElement * * \return A const vector of the attributes on this element. */ - const std::vector& getAttributes(); + const std::vector& getAttributes() const; /** * \brief add all of the given attributes to this element. @@ -152,7 +152,7 @@ class MEI_EXPORT MeiElement * * \return the attribute with this name, or NULL if the atribute doesn't exist. */ - MeiAttribute* getAttribute(std::string name); + MeiAttribute* getAttribute(std::string name) const; /** * \brief Remove the attribute with the given name. @@ -162,17 +162,17 @@ class MEI_EXPORT MeiElement /** * \brief See if this element has an attribute with the given name. */ - bool hasAttribute(std::string name); + bool hasAttribute(std::string name) const; /** \brief Check if this element has a parent element * * \return True if it does, False if it does not */ - bool hasParent(); + bool hasParent() const; /** \brief Get this element's parent, if it exists. */ - MeiElement *getParent(); + MeiElement *getParent() const; /** \brief Links this element and it's children to the given document * @@ -182,7 +182,7 @@ class MEI_EXPORT MeiElement /** \brief Gets a pointer to the document this element is attached to. */ - MeiDocument* getDocument(); + MeiDocument* getDocument() const; /** \brief Removes the pointer from this element and it's children to its currently assigned document * @@ -215,12 +215,12 @@ class MEI_EXPORT MeiElement /** * \brief Get all of the children of this element. */ - const std::vector& getChildren(); + const std::vector& getChildren() const; /** * \brief Get all of the children of this element that have a given name. */ - const std::vector getChildrenByName(std::string name); + const std::vector getChildrenByName(std::string name) const; /** * \brief Remove all of the children of this element. @@ -245,25 +245,25 @@ class MEI_EXPORT MeiElement /** * \brief Check if this element has any children. */ - bool hasChildren(); + bool hasChildren() const; /** * \brief Check if this element has any children with the given name. */ - bool hasChildren(std::string cname); + bool hasChildren(std::string cname) const; /** * \brief Get the ancestor with a given element name * * \return MeiElement, or NULL if no ancestor is found. */ - MeiElement* getAncestor(std::string name); + MeiElement* getAncestor(std::string name) const; /** * \brief Returns TRUE if this element has an ancestor element * with a given name; FALSE otherwise */ - bool hasAncestor(std::string name); + bool hasAncestor(std::string name) const; /** * \brief Get all descendants of the current element. @@ -287,7 +287,7 @@ class MEI_EXPORT MeiElement * * \return A vector of MeiElements (possibly empty). */ - std::vector getPeers(); + std::vector getPeers() const; /** \brief Gets this item's position in the flattened document structure. * Position is numbered by the order the elements occur, so the first diff --git a/tools/langs/cplusplus.py b/tools/langs/cplusplus.py index 64b3d131..5599ec66 100644 --- a/tools/langs/cplusplus.py +++ b/tools/langs/cplusplus.py @@ -17,13 +17,13 @@ AUTHORS = "Andrew Hankinson, Alastair Porter, and Others" METHODS_HEADER_TEMPLATE = """{documentation} - MeiAttribute* get{attNameUpper}(); + MeiAttribute* get{attNameUpper}() const; void set{attNameUpper}(std::string _{attNameLowerJoined}); - bool has{attNameUpper}(); + bool has{attNameUpper}() const; void remove{attNameUpper}(); """ -METHODS_IMPL_TEMPLATE = """MeiAttribute* mei::{className}::get{attNameUpper}() {{ +METHODS_IMPL_TEMPLATE = """MeiAttribute* mei::{className}::get{attNameUpper}() const {{ if (!{accessor}hasAttribute("{attNameLower}")) {{ return NULL; }} @@ -35,7 +35,7 @@ {accessor}addAttribute(a); }}; -bool mei::{className}::has{attNameUpper}() {{ +bool mei::{className}::has{attNameUpper}() const {{ return {accessor}hasAttribute("{attNameLower}"); }};