Skip to content
Snippets Groups Projects
Commit b16b312b authored by Jan Trávníček's avatar Jan Trávníček
Browse files

simplify and comb std tree

parent 47496726
No related branches found
No related tags found
No related merge requests found
...@@ -33,24 +33,22 @@ public: ...@@ -33,24 +33,22 @@ public:
return m_children; return m_children;
} }
   
void nicePrint ( std::ostream & os, const std::string & prefix, const bool last ) const { void nicePrint ( std::ostream & os, std::string prefix, const bool last ) const {
os << prefix; os << prefix;
   
std::string nextPrefix ( prefix );
if ( last ) { if ( last ) {
os << "\\-"; os << "\\-";
nextPrefix += " "; prefix += " ";
} else { } else {
os << "|-"; os << "|-";
nextPrefix += "| "; prefix += "| ";
} }
   
os << getData ( ) << std::endl; os << getData ( ) << std::endl;
   
for ( unsigned int i = 0; i < m_children.size ( ); ++i ) { for ( unsigned int i = 0; i < m_children.size ( ); ++i ) {
os << nextPrefix << "|" << std::endl; os << prefix << "|" << std::endl;
m_children[i].nicePrint ( os, nextPrefix, i == m_children.size ( ) - 1 ); m_children[i].nicePrint ( os, prefix, i == m_children.size ( ) - 1 );
} }
} }
   
......
...@@ -42,24 +42,22 @@ public: ...@@ -42,24 +42,22 @@ public:
return m_children; return m_children;
} }
   
void nicePrint ( std::ostream & os, const std::string & prefix, const bool last ) const { void nicePrint ( std::ostream & os, std::string prefix, const bool last ) const {
os << prefix; os << prefix;
   
std::string nextPrefix ( prefix );
if ( last ) { if ( last ) {
os << "\\-"; os << "\\-";
nextPrefix += " "; prefix += " ";
} else { } else {
os << "|-"; os << "|-";
nextPrefix += "| "; prefix += "| ";
} }
   
os << getData ( ) << std::endl; os << getData ( ) << std::endl;
   
for ( unsigned int i = 0; i < m_children.size ( ); ++i ) { for ( unsigned int i = 0; i < m_children.size ( ); ++i ) {
os << nextPrefix << "|" << std::endl; os << prefix << "|" << std::endl;
m_children[i].nicePrint ( os, nextPrefix, i == m_children.size ( ) - 1 ); m_children[i].nicePrint ( os, prefix, i == m_children.size ( ) - 1 );
} }
} }
   
......
...@@ -11,5 +11,5 @@ ...@@ -11,5 +11,5 @@
#include "extensions/tree_base.hpp" #include "extensions/tree_base.hpp"
#include "extensions/forward_tree.hpp" #include "extensions/forward_tree.hpp"
   
#endif /* __TREE_HEADER_WRAPPER */ #endif /* __TREE_HEADER_WRAPPER_ */
   
...@@ -11,5 +11,5 @@ ...@@ -11,5 +11,5 @@
#include "extensions/tree_base.hpp" #include "extensions/tree_base.hpp"
#include "extensions/tree.hpp" #include "extensions/tree.hpp"
   
#endif /* __TREE_HEADER_WRAPPER */ #endif /* __TREE_HEADER_WRAPPER_ */
   
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment