33#ifndef DRAIN_TREE_UTILS 
   34#define DRAIN_TREE_UTILS "2.1" 
   42#include <drain/String.h> 
   66    template <
class TR, 
class S>
 
   69        for (
const auto & entry: tree){
 
   70            typename TR::path_t p;
 
   72            getPaths(entry.second, container, p); 
 
 
   81    template <
class TR, 
class S>
 
   83    void getPaths(
const TR & tree, S & container, 
const typename TR::path_t & path){ 
 
   84        container.push_back(path);
 
   85        for (
const auto & entry: tree){
 
   87            typename TR::path_t p = path;
 
   89            getPaths(entry.second, container, p); 
 
 
   93    template <
class T1, 
class T2>
 
   95    void deepCopy(
const T1 & srcTree, T2 & dstTree){
 
   97        for (
const auto & entry: srcTree){
 
   98            deepCopy(entry.second, dstTree.addChild(entry.first));
 
  101        if (dstTree.empty() || !dstTree.isExclusive())
 
  102            dstTree.data = srcTree.data;
 
  117    template <
class T, 
class H>
 
  118    static void traverse(H & visitor, T & tree, 
const typename T::path_t & path = 
typename T::path_t()){
 
  121        if (visitor.visitPrefix(tree, path)){
 
  127        for (
auto & entry: tree(path).getChildren()){
 
  129            traverse(visitor, tree, 
typename T::path_t(path, entry.first));
 
  132        if (visitor.visitPostfix(tree, path)){
 
 
  157    template <
class TR, 
bool SKIP_EMPTY=false>
 
  160    bool dump(
const TR & tree, std::ostream &ostr = std::cout,
 
  161            bool (* callBack)(
const typename TR::node_data_t &, std::ostream &) = 
TreeUtils::dataDumper, 
const std::string &  indent=
"") { 
 
  176        if (callBack != 
nullptr){ 
 
  179            if (! (tree.isExclusive() && tree.hasChildren())){
 
  182                empty = (*callBack)(tree.data, ostr);
 
  192        for (
typename TR::container_t::const_iterator it = tree.begin(); it != tree.end(); it++){
 
  194            std::ostream & ostrChild = ostr; 
 
  197            if (it == --tree.end()){
 
  198                ostrChild   << indent << 
"└──"; 
 
  199                indent2      = indent  + 
"   "; 
 
  202                ostrChild   << indent << 
"├──"; 
 
  203                indent2      = indent  + 
"│  "; 
 
  205            ostrChild << it->first; 
 
  207            if (callBack != 
nullptr){ 
 
  213            bool empty2 = 
dump(it->second, ostrChild, callBack, indent2);
 
 
  231    void dumpContents(
const TR & tree, std::ostream &ostr = std::cout, 
const typename TR::path_t & path = 
"") {
 
  233        ostr << tree.data << 
'\n';
 
  234        for (
const auto & entry: tree){
 
  235            ostr << entry.first << 
'\t';  
 
 
  244    void writeINI(
const TR & t, std::ostream & ostr = std::cout, 
const typename TR::path_t & prefix = 
typename TR::path_t()){
 
 
  253    void readINI(TR & tree, std::istream & istr){
 
  255        mout.unimplemented(
"future extension");
 
 
  297#ifdef DRAIN_TYPE_UTILS 
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:511
Collection of functions for investigating and processing trees.
Definition TreeUtils.h:57
static void getPaths(const TR &tree, S &container)
Retrieve all the paths.
Definition TreeUtils.h:68
static void writeINI(const TR &t, std::ostream &ostr=std::cout, const typename TR::path_t &prefix=typename TR::path_t())
Write a Windows INI file.
Definition TreeUtils.h:244
static void getPaths(const TR &tree, S &container, const typename TR::path_t &path)
Retrieve all the paths.
Definition TreeUtils.h:83
static void traverse(H &visitor, T &tree, const typename T::path_t &path=typename T::path_t())
Traverse tree, visiting each node as a prefix operation.
Definition TreeUtils.h:118
static bool dataDumper(const T &data, std::ostream &ostr)
Default implementation for recursive dump()
Definition TreeUtils.h:143
static void dumpContents(const TR &tree, std::ostream &ostr=std::cout, const typename TR::path_t &path="")
Debugging utility - dumps the tree, also the contents.
Definition TreeUtils.h:231
static bool dump(const TR &tree, std::ostream &ostr=std::cout, bool(*callBack)(const typename TR::node_data_t &, std::ostream &)=TreeUtils::dataDumper, const std::string &indent="")
Render a tree using character graphics.
Definition TreeUtils.h:160
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:270
virtual int visitPrefix(T &tree, const typename T::path_t &path)
Tasks to be executed before traversing child nodes.
Definition TreeUtils.h:282
virtual int visitPostfix(T &tree, const typename T::path_t &path)
Tasks to be executed after traversing child nodes.
Definition TreeUtils.h:288
Definition DataSelector.cpp:1277