diff --git a/include/Tree/tree.hpp b/include/Tree/tree.hpp
index ca16f78..76ffc2a 100644
--- a/include/Tree/tree.hpp
+++ b/include/Tree/tree.hpp
@@ -23,16 +23,11 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
-
-
-
-
-
-
#include
#include
#include
#include
+#include
/**
* @brief main namespace for the libtree++ library
@@ -57,11 +52,11 @@ namespace Tree
* @brief get the root of the tree
*
*/
- std::shared_ptr getRoot()
+ std::shared_ptr getRoot() const
{
if (parent==nullptr)
{
- return shared_from_this();
+ return std::const_pointer_cast(shared_from_this());
}
return parent->getRoot();
@@ -131,14 +126,14 @@ namespace Tree
*
* @return iterator to the beginning of the list of children
*/
- std::list>::iterator getChildrenBegin() {return children.begin();}
+ std::list>::const_iterator getChildrenBegin() const {return children.begin();}
/**
* @brief returns an iterator to the end of the list of children
*
* @return iterator to the end of the list of children
*/
- std::list>::iterator getChildrenEnd() {return children.end();}
+ std::list>::const_iterator getChildrenEnd() const {return children.end();}
/**
* @brief returns the nr of direct children
@@ -227,7 +222,7 @@ namespace Tree
* @return nullptr - a node of that type could not be found
* @return the found node as a shared_ptr
*/
- std::shared_ptr findNext(const std::string &t);
+ std::shared_ptr findNext(const std::string &t) const;
/**
* @brief finds all nodes of a given type
@@ -236,13 +231,12 @@ namespace Tree
* @param c - a container for holding all found nodes, has to be holding objects of type std::shared_ptr
*/
template
- void findAll(const std::string &t, Container &c)
+ void findAll(const std::string &t, Container &c) const
{
- std::list>::iterator it;
-
+ std::list>::const_iterator it;
if (type() == t)
{
- c.push_back(shared_from_this());
+ c.push_back(std::const_pointer_cast(shared_from_this()));
}
for(it = children.begin(); it != children.end(); ++it)
@@ -259,13 +253,13 @@ namespace Tree
* @param c - a container for holding all found nodes, has to be holding objects of type std::shared_ptr
*/
template
- void findAllBase(const std::string &b, Container &c)
+ void findAllBase(const std::string &b, Container &c) const
{
- std::list>::iterator it;
+ std::list>::const_iterator it;
if (base() == b)
{
- c.push_back(shared_from_this());
+ c.push_back(std::const_pointer_cast(shared_from_this()));
}
for(it = children.begin(); it != children.end(); ++it)
diff --git a/src/Tree/tree.cpp b/src/Tree/tree.cpp
index d946a61..0ab8a05 100644
--- a/src/Tree/tree.cpp
+++ b/src/Tree/tree.cpp
@@ -20,10 +20,10 @@ along with this program. If not, see .
#include
-std::shared_ptr Tree::BaseNode::findNext(const std::string &t)
+std::shared_ptr Tree::BaseNode::findNext(const std::string &t) const
{
- std::list>::iterator childIT;
- std::shared_ptr temp;
+ std::list>::const_iterator childIT;
+ std::shared_ptr temp;
if (type() == t )
{
@@ -72,7 +72,7 @@ void Tree::BaseNode::printTree(const uint32_t depth)
std::cout << toString() << std::endl;
- std::list>::iterator childIT;
+ std::list>::const_iterator childIT;
for(childIT=getChildrenBegin(); childIT != getChildrenEnd(); ++childIT)
{