33#ifndef DRAIN_TREE_UTILS
34#define DRAIN_TREE_UTILS "2.1"
61 template <
class TR,
class S>
64 for (
const auto & entry: tree){
65 typename TR::path_t p;
67 getPaths(entry.second, container, p);
76 template <
class TR,
class S>
78 void getPaths(
const TR & tree, S & container,
const typename TR::path_t & path){
79 container.push_back(path);
80 for (
const auto & entry: tree){
82 typename TR::path_t p = path;
84 getPaths(entry.second, container, p);
88 template <
class T1,
class T2>
90 void deepCopy(
const T1 & srcTree, T2 & dstTree){
92 for (
const auto & entry: srcTree){
93 deepCopy(entry.second, dstTree.addChild(entry.first));
96 if (dstTree.empty() || !dstTree.isExclusive())
97 dstTree.data = srcTree.data;
112 template <
class T,
class H>
113 static void traverse(H & visitor, T & tree,
const typename T::path_t & path =
typename T::path_t()){
116 if (visitor.visitPrefix(tree, path)){
122 for (
auto & entry: tree(path).getChildren()){
124 traverse(visitor, tree,
typename T::path_t(path, entry.first));
127 if (visitor.visitPostfix(tree, path)){
152 template <
class TR,
bool SKIP_EMPTY=false>
155 bool dump(
const TR & tree, std::ostream &ostr = std::cout,
156 bool (* callBack)(
const typename TR::node_data_t &, std::ostream &) =
TreeUtils::dataDumper,
const std::string & indent=
"") {
171 if (callBack !=
nullptr){
174 if (! (tree.isExclusive() && tree.hasChildren())){
177 empty = (*callBack)(tree.data, ostr);
187 for (
typename TR::container_t::const_iterator it = tree.begin(); it != tree.end(); it++){
189 std::ostream & ostrChild = ostr;
192 if (it == --tree.end()){
193 ostrChild << indent <<
"└──";
194 indent2 = indent +
" ";
197 ostrChild << indent <<
"├──";
198 indent2 = indent +
"│ ";
200 ostrChild << it->first;
202 if (callBack !=
nullptr){
208 bool empty2 =
dump(it->second, ostrChild, callBack, indent2);
226 void dumpContents(
const TR & tree, std::ostream &ostr = std::cout,
const typename TR::path_t & path =
"") {
228 ostr << tree.data <<
'\n';
229 for (
const auto & entry: tree){
230 ostr << entry.first <<
'\t';
239 void writeINI(
const TR & t, std::ostream & ostr = std::cout,
const typename TR::path_t & prefix =
typename TR::path_t()){
248 void readINI(TR & tree, std::istream & istr){
250 mout.unimplemented(
"future extension");
293DRAIN_TYPENAME(TreeUtils);
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:512
Collection of functions for investigating and processing trees.
Definition TreeUtils.h:52
static void getPaths(const TR &tree, S &container)
Retrieve all the paths.
Definition TreeUtils.h:63
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:239
static void getPaths(const TR &tree, S &container, const typename TR::path_t &path)
Retrieve all the paths.
Definition TreeUtils.h:78
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:113
static bool dataDumper(const T &data, std::ostream &ostr)
Default implementation for recursive dump()
Definition TreeUtils.h:138
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:226
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:155
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:265
virtual int visitPrefix(T &tree, const typename T::path_t &path)
Tasks to be executed before traversing child nodes.
Definition TreeUtils.h:277
virtual int visitPostfix(T &tree, const typename T::path_t &path)
Tasks to be executed after traversing child nodes.
Definition TreeUtils.h:283
Definition DataSelector.cpp:1277