FIX: fixed const correctness
This commit is contained in:
parent
ef31885f61
commit
75e6d2007b
@ -23,16 +23,11 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief main namespace for the libtree++ library
|
* @brief main namespace for the libtree++ library
|
||||||
@ -57,11 +52,11 @@ namespace Tree
|
|||||||
* @brief get the root of the tree
|
* @brief get the root of the tree
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<Tree::BaseNode> getRoot()
|
std::shared_ptr<Tree::BaseNode> getRoot() const
|
||||||
{
|
{
|
||||||
if (parent==nullptr)
|
if (parent==nullptr)
|
||||||
{
|
{
|
||||||
return shared_from_this();
|
return std::const_pointer_cast<Tree::BaseNode>(shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent->getRoot();
|
return parent->getRoot();
|
||||||
@ -131,14 +126,14 @@ namespace Tree
|
|||||||
*
|
*
|
||||||
* @return iterator to the beginning of the list of children
|
* @return iterator to the beginning of the list of children
|
||||||
*/
|
*/
|
||||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator getChildrenBegin() {return children.begin();}
|
std::list<std::shared_ptr<Tree::BaseNode>>::const_iterator getChildrenBegin() const {return children.begin();}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief returns an iterator to the end of the list of children
|
* @brief returns an iterator to the end of the list of children
|
||||||
*
|
*
|
||||||
* @return iterator to the end of the list of children
|
* @return iterator to the end of the list of children
|
||||||
*/
|
*/
|
||||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator getChildrenEnd() {return children.end();}
|
std::list<std::shared_ptr<Tree::BaseNode>>::const_iterator getChildrenEnd() const {return children.end();}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief returns the nr of direct children
|
* @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 nullptr - a node of that type could not be found
|
||||||
* @return the found node as a shared_ptr
|
* @return the found node as a shared_ptr
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<Tree::BaseNode> findNext(const std::string &t);
|
std::shared_ptr<const Tree::BaseNode> findNext(const std::string &t) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief finds all nodes of a given type
|
* @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<Tree::BaseNode>
|
* @param c - a container for holding all found nodes, has to be holding objects of type std::shared_ptr<Tree::BaseNode>
|
||||||
*/
|
*/
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
void findAll(const std::string &t, Container &c)
|
void findAll(const std::string &t, Container &c) const
|
||||||
{
|
{
|
||||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator it;
|
std::list<std::shared_ptr<Tree::BaseNode>>::const_iterator it;
|
||||||
|
|
||||||
if (type() == t)
|
if (type() == t)
|
||||||
{
|
{
|
||||||
c.push_back(shared_from_this());
|
c.push_back(std::const_pointer_cast<Tree::BaseNode>(shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(it = children.begin(); it != children.end(); ++it)
|
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<Tree::BaseNode>
|
* @param c - a container for holding all found nodes, has to be holding objects of type std::shared_ptr<Tree::BaseNode>
|
||||||
*/
|
*/
|
||||||
template <class Container>
|
template <class Container>
|
||||||
void findAllBase(const std::string &b, Container &c)
|
void findAllBase(const std::string &b, Container &c) const
|
||||||
{
|
{
|
||||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator it;
|
std::list<std::shared_ptr<Tree::BaseNode>>::const_iterator it;
|
||||||
|
|
||||||
if (base() == b)
|
if (base() == b)
|
||||||
{
|
{
|
||||||
c.push_back(shared_from_this());
|
c.push_back(std::const_pointer_cast<Tree::BaseNode>(shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(it = children.begin(); it != children.end(); ++it)
|
for(it = children.begin(); it != children.end(); ++it)
|
||||||
|
@ -20,10 +20,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#include <Tree/tree.hpp>
|
#include <Tree/tree.hpp>
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<Tree::BaseNode> Tree::BaseNode::findNext(const std::string &t)
|
std::shared_ptr<const Tree::BaseNode> Tree::BaseNode::findNext(const std::string &t) const
|
||||||
{
|
{
|
||||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator childIT;
|
std::list<std::shared_ptr<Tree::BaseNode>>::const_iterator childIT;
|
||||||
std::shared_ptr<Tree::BaseNode> temp;
|
std::shared_ptr<const Tree::BaseNode> temp;
|
||||||
|
|
||||||
if (type() == t )
|
if (type() == t )
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ void Tree::BaseNode::printTree(const uint32_t depth)
|
|||||||
|
|
||||||
std::cout << toString() << std::endl;
|
std::cout << toString() << std::endl;
|
||||||
|
|
||||||
std::list<std::shared_ptr<Tree::BaseNode>>::iterator childIT;
|
std::list<std::shared_ptr<Tree::BaseNode>>::const_iterator childIT;
|
||||||
|
|
||||||
for(childIT=getChildrenBegin(); childIT != getChildrenEnd(); ++childIT)
|
for(childIT=getChildrenBegin(); childIT != getChildrenEnd(); ++childIT)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user