33 #ifndef DRAIN_TREE_UTILS
34 #define DRAIN_TREE_UTILS "2.1"
41 #include <drain/Log.h>
42 #include <drain/String.h>
71 void erase(TR & tree,
const typename TR::path_t & path){
96 template <
class TR,
class S>
100 for (
const auto & entry: tree){
101 typename TR::path_t p;
103 getPaths(entry.second, container, p);
112 template <
class TR,
class S>
114 void getPaths(
const TR & tree, S & container,
const typename TR::path_t & path){
115 container.push_back(path);
116 for (
const auto & entry: tree){
118 typename TR::path_t p = path;
120 getPaths(entry.second, container, p);
124 template <
class T1,
class T2>
126 void deepCopy(
const T1 & srcTree, T2 & dstTree){
128 for (
const auto & entry: srcTree){
129 deepCopy(entry.second, dstTree.addChild(entry.first));
132 if (dstTree.empty() || !dstTree.isExclusive())
133 dstTree.data = srcTree.data;
145 template <
class T,
class H>
146 static void traverse(H & handler, T & tree,
const typename T::path_t & path =
typename T::path_t()){
149 if (handler.visitPrefix(tree, path)){
157 for (
auto & entry: tree(path).getChildren()){
161 traverse(handler, tree,
typename T::path_t(path, entry.first));
164 if (handler.visitPostfix(tree, path)){
189 template <
class TR,
bool SKIP_EMPTY=false>
192 bool dump(
const TR & tree, std::ostream &ostr = std::cout,
193 bool (* callBack)(
const typename TR::node_data_t &, std::ostream &) =
TreeUtils::dataDumper,
const std::string & indent=
"") {
208 if (callBack !=
nullptr){
210 if (tree.empty() || !tree.isExclusive()){
212 empty = (*callBack)(tree.data, ostr);
222 for (
typename TR::container_t::const_iterator it = tree.begin(); it != tree.end(); it++){
224 std::ostream & ostrChild = ostr;
227 if (it == --tree.end()){
228 ostrChild << indent <<
"└──";
229 indent2 = indent +
" ";
232 ostrChild << indent <<
"├──";
233 indent2 = indent +
"│ ";
235 ostrChild << it->first;
237 if (callBack !=
nullptr){
243 bool empty2 =
dump(it->second, ostrChild, callBack, indent2);
261 void dumpContents(
const TR & tree, std::ostream &ostr = std::cout,
const typename TR::path_t & path =
"") {
263 ostr << tree.data <<
'\n';
264 for (
const auto & entry: tree){
265 ostr << entry.first <<
'\t';
274 void writeINI(
const TR & t, std::ostream & ostr = std::cout,
const typename TR::path_t & prefix =
typename TR::path_t()){
283 void readINI(TR & tree, std::istream & istr){
285 mout.unimplemented(
"future extension");
326 #ifdef DRAIN_TYPE_UTILS
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition: Log.h:507
Collection of functions for investigating and processing trees.
Definition: TreeUtils.h:57
static void getPaths(const TR &tree, S &container)
Returns a list of the node names matching a pattern. The trailing '/' is NOT appended ie....
Definition: TreeUtils.h:98
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:274
static void erase(TR &tree, const typename TR::path_t &path)
Deletes a node (leaf) and its subtrees.
Definition: TreeUtils.h:71
static void getPaths(const TR &tree, S &container, const typename TR::path_t &path)
Returns a list of the node names matching a pattern. The trailing '/' is NOT appended ie....
Definition: TreeUtils.h:114
static bool dataDumper(const T &data, std::ostream &ostr)
Default implementation for recursive dump()
Definition: TreeUtils.h:175
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:261
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:192
static void traverse(H &handler, T &tree, const typename T::path_t &path=typename T::path_t())
Traverse tree, visiting each node as a prefix operation.
Definition: TreeUtils.h:146
Definition: DataSelector.cpp:1277