Loading...
Searching...
No Matches
Tree.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32#ifndef DRAIN_TREE_NAME
33#warning "Use TreeOrdered.h or TreeUnordered.h to include this file."
34#endif
35
36
37#include <iterator>
38#include <string>
39#include <map>
40
41
42#include <drain/Log.h>
43#include <drain/TypeName.h>
44#include <drain/TypeUtils.h>
45#include <drain/Variable.h> // NEW 2025 to support several types of initializer_list, not only pair<char*,char*>
46
47
48#include "Path.h"
49
50#include "TreeUtils.h"
51
52namespace drain {
53
54
55
57
146template <class T, bool EXCLUSIVE=false, class P=drain::Path<std::string,'/'> > // , class C=std::less<std::string>
147class DRAIN_TREE_NAME { // : public AmbiValue<T,typename P::elem_t> { //: public TreeBase {
148public:
149
151 typedef T node_data_t;
152 typedef P path_t;
153 typedef typename path_t::elem_t key_t; // deprecating?
154 typedef typename path_t::elem_t path_elem_t;
155
156 typedef std::pair<key_t,tree_t> pair_t;
157
158 typedef DRAIN_TREE_CONTAINER(key_t,tree_t) container_t;
159
160 typedef typename container_t::iterator iterator;
161 typedef typename container_t::const_iterator const_iterator;
162
164 inline
165 DRAIN_TREE_NAME(){}; // : separator(separator) {}; //parent(*this),
166
168 inline
169 DRAIN_TREE_NAME(const node_data_t &data) : data(data){}; //, separator(t.separator) {}; //parent(*this),
170
172 inline
173 DRAIN_TREE_NAME(const DRAIN_TREE_NAME &t) : data(t.data){}; //, separator(t.separator) {}; //parent(*this),
174
175 virtual inline
177
178
180 node_data_t data;
181
183
186 static inline
187 bool dataEmpty(const node_data_t & data){
188 return data.empty();
189 };
190
191 inline
192 bool dataEmpty() const {
193 return dataEmpty(data);
194 };
195
196 // AMBIVALUED
197 virtual inline
198 bool hasMultipleData() const {
199 // Return false, if own, local data (explain ??)
200 // return data.empty(); //???
201 return dataEmpty();
202 };
203
204 virtual inline
205 const node_data_t & getData() const {return data;};
206
207 virtual inline
208 node_data_t & getData(){return data;};
209
210 virtual inline
211 const node_data_t & getData(const key_t & key) const {
212 return retrieveChild(key).data;
213 };
214
215 virtual inline
216 node_data_t & getData(const key_t & key){
217 return retrieveChild(key).data;
218 };
219
220
221
223
231 inline
232 typename container_t::const_iterator begin() const { return children.begin(); };
233
235 inline
236 typename container_t::const_iterator end() const { return children.end(); };
237
239 inline
240 typename container_t::iterator begin(){ return children.begin(); };
241
243 inline
244 typename container_t::iterator end(){ return children.end(); };
245
246
248
253 static inline
255 return EXCLUSIVE;
256 }
257
259 static inline
261 #ifdef DRAIN_TREE_MULTI
262 return true;
263 #else
264 return false;
265 #endif
266 }
267
269 static inline
270 bool isOrdered(){
271 #ifdef DRAIN_TREE_ORDERED
272 return true;
273 #else
274 return false;
275 #endif
276 }
277
278
280
284 // TODO: what to do with the separator?
285 inline
287 // std::cerr << "op=() 1\n";
288 if (&t != this){
289 data = t.data;
290 //if (EXCLUSIVE){ ...or consider deep copy?
292 //}
293 }
294 return *this;
295 };
296
298 // Needed? See next.
299 /* THIS CAUSES PROBLEMS. with int x = tree; vs. tree = x;
300 inline
301 tree_t & operator=(const node_data_t &v){
302 data = v;
303 if (EXCLUSIVE){
304 clearChildren();
305 }
306 return *this;
307 };
308 */
309
310
312
316 template <class T2>
317 inline
318 tree_t & operator=(const T2 &v){
319 // std::cerr << "op=() 2\n";
320 data = v;
321 if (EXCLUSIVE){
323 }
324 return *this;
325 }
326
327
328 // This may cause problems, as non-template, and forces implementation of .data = std::string(str).
329 inline
330 tree_t & operator=(const char *str){
331 return this->operator=(std::string(str));
332 }
333
334
336
340 template <typename K, typename V>
341 inline // 2025/01 experimental.
342 tree_t & operator=(std::initializer_list<std::pair<K,V> > l){
343 for (const auto & entry: l){
344 *this << entry;
345 }
346 return *this;
347 }
348
350
358 inline // 2025/01 experimental.
359 tree_t & operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
360 if (EXCLUSIVE){
361 clearData();
362 }
363 for (const auto & entry: l){
364 this[entry.first] = entry.second;
365 }
366 return *this;
367 }
368
370
375 template <typename V>
376 inline
377 tree_t & operator=(const std::initializer_list<V> & l){
378 if (EXCLUSIVE){
380 }
381 this->data = l;
382 return *this;
383 }
384
386 // See operator<<() below.
387 typedef std::pair<key_t,node_data_t> node_pair_t;
388
389
391 inline
392 tree_t & operator<<(const node_pair_t & entry){
393 if (EXCLUSIVE){
394 clearData();
395 }
396 tree_t & child = retrieveChild(entry.first);
397 child.data = entry.second;
398 return child;
399 }
400
402 inline
403 operator const node_data_t &() const {
404 return data;
405 };
406
408
411 inline
412 operator node_data_t &(){
413 return data;
414 };
415
416
418
422 template <class K>
423 inline
424 tree_t & operator[](const K & key){
425 return retrieveChild(getKey(key)); // 2026/02
426 //return retrieveChild(key); // OLD
427 }
428
430 template <class K>
431 inline
432 const tree_t & operator[](const K & key) const {
433 return retrieveChild(getKey(key)); // 2026/02
434 // return retrieveChild(key); // OLD
435 }
436
437
439
445 inline
446 tree_t & operator()(const path_t & path){
447 /*
448 if (superDebug){
449 std::cout << __FILE__ << "tree_t & operator()(const path_t & path)" << '\n';
450 }
451 */
452 return get(path.begin(), path.end());
453 }
454
456
465 template <class S>
466 inline
467 tree_t & operator()(const S & arg){
468 return operator()(path_t(arg));
469 }
470
472
475 inline
476 tree_t & operator()(const char *arg){
477 return operator()(path_t(arg));
478 // return operator()(std::string(arg));
479 }
480
482
488 inline
489 const tree_t & operator()(const path_t & path) const {
490 return get(path.begin(), path.end());
491 }
492
494 template <class S>
495 inline
496 const tree_t & operator()(const S & arg) const {
497 return operator()(path_t(arg));
498 }
499
501 inline
502 const tree_t & operator()(const char *arg) const {
503 return operator()(path_t(arg));
504 //return operator()(std::string(arg));
505 }
506
508
513 inline
514 void clear(){
515 clearData();
517 };
518
524 inline
525 void clearData(){
526 // Future option: data.clear() (applies to many stl classes, like strings and containers)
527 data = getEmpty().data;
528 };
529
531
536 inline
537 void clearChildren(){ // RAISE/virtualize
538 children.clear();
539 };
540
541
543
548 // ??-> If an ending slash is included, then groups but no datasets will be erased. (?)
549 void erase(const path_t & path){ // RAISE/virtualize
550
551 // drain::Logger mout(__FILE__, __FUNCTION__);
552
553 // Idea: first assign the leaf, and step one back.
554 typename path_t::const_iterator pit = path.end();
555 if (pit == path.begin())
556 return;
557 else {
558 // Move 'it' back one step, to point to the leaf (the last element in chain).
559 --pit;
560
561 // Safe (identity) if it == path.begin():
562 tree_t & parent = this->get(path.begin(), pit);
563
564 #ifdef DRAIN_TREE_ORDERED // map
565
566 // TODO: generalize "find" for find first, etc
567 parent.children.erase(*pit);
568
569 #else
570
571 //drain::Logger(__FILE__, __LINE__, __FUNCTION__).error("unimplemented code");
572 for (iterator it = children.begin(); it != children.end(); ++it){
573 if (it->first == *pit){
574 // drain::Logger(__FILE__, __LINE__, __FUNCTION__).attention("deleting child: ", *pit);
575 parent.children.erase(it);
576 return;
577 }
578 }
579
580
581 #endif
582
583 //parent.eraseChild(*it);
584
585 }
586
587 }
588
591 virtual inline
592 const tree_t & getEmpty() const {
593 return emptyNode;
594 }
595
596 // Ambiguous?
598 virtual inline
599 bool empty() const {
600 //return (data.empty() && !hasChildren());
601 return (dataEmpty() && !hasChildren());
602 };
603
604 inline
605 bool hasChildren() const {
606 return !children.empty();
607 }
608
610
623 virtual inline
624 int hasChildren(const key_t &key) const {
625
626 #ifdef DRAIN_TREE_ORDERED // map
627
628 if (!isMultiple()){
629 return (children.find(key) == children.end()) ? 0 : 1;
630 }
631 // no-break for OrderedMultipleTree
632
633 #endif
634
635 // OrderedMultipleTree (passed through from the above #ifdef-#endif)
636 // OrderedMultipleTree
637 // UnorderedMultipleTree
638
639 size_t count = 0;
640 for (const auto & entry: children){
641 if (entry.first == key){
642 ++count;
643 }
644 }
645 return count;
646
647 };
648
650
658 virtual inline
659 bool hasChild(const key_t &key) const {
660
661 #ifdef DRAIN_TREE_ORDERED
662 // map -> native (NlogN) search
663
664 return (children.find(key) != children.end());
665
666 #else
667 // list -> brute-force search
668
669 for (const auto & entry: children){
670 if (entry.first == key){
671 return true;
672 }
673 }
674 return false;
675
676 #endif
677 };
678
679
680 template <typename K>
681 inline
682 bool hasChild(const K &key) const {
683 return hasChild(getKey(key)); // 2025
684 // return hasChild(static_cast<key_t>(key)); // OLDISH
685 }
686
687
688 inline
689 bool hasPath(const path_t & path) const {
690 return hasPath(path.begin(), path.end());
691 }
692
693
695
702 inline // consider static ?
703 void initChild(tree_t &) const { // child
704 }
705
706
707 static
708 void generateKey(const tree_t & tree, typename P::elem_t & key);
709
711
715 tree_t & addChild(){ // NEW 2026
716 typename P::elem_t key;
717 generateKey(*this, key);
718 //return addChild(key_t());
719 return addChild(key);
720 }
721
732 // retrieve
733
735
746 tree_t & addChild(const key_t & key){ // 2026/01 : explicit arg
747
748 if (key.empty()){ // Should be exceptional... Warning?
749 std::cerr << typeid(tree_t).name() << std::endl;
750 throw std::runtime_error(drain::StringBuilder<':'>(__FILE__,__FUNCTION__, " empty key (ADD static child counter based naming)"));
751 return *this;
752 }
753
754 if (EXCLUSIVE){
755 // EXCLUSIVE = either data or children... so drop data now.
756 this->clearData();
757 }
758
759 #ifdef DRAIN_TREE_ORDERED
760 // Always unique ( ==non-multiple)
761 iterator it = children.find(key);
762 if (it != children.end()){
763 return it->second;
764 }
765 else {
766 tree_t & child = children.insert(children.begin(), pair_t(key, tree_t()))->second;
767 initChild(child);
768 return child;
769 }
770
771 #else
772
773 // If not MULTIPLE, return the child if it exists
774 if (!isMultiple()){
775 for (auto & entry: children){
776 // Brute-force search
777 if (entry.first == key){
778 return entry.second;
779 }
780 }
781 }
782
783 // Add a child.
784 children.push_back(pair_t(key, tree_t()));
785 tree_t & child = children.back().second;
786 initChild(child);
787 return child;
788
789 #endif
790 };
791
793
796 template <typename E>
797 inline
798 tree_t & addChild(const E & key){
799 // Cast ensures forwarding to main function
800 //return addChild(static_cast<key_t>(getKey(key)));
801 return addChild(getKey(key));
802 }
803
804
805
807 inline
809 return prependChild(key_t());
810 }
811
812
813 // Push in the front. This is only available for ordered trees.
815
818 template <typename E>
819 inline
820 tree_t & prependChild(const E & key){
821 return prependChild(getKey(key));
822 }
823
824
825 //virtual
826 tree_t & prependChild(const key_t & key){ // 2026/01 explicit arg
827
828 #ifdef DRAIN_TREE_ORDERED
829
830 return addChild(key);
831
832 #else
833
834 if (key.empty()){ // Should be exceptional... Warning?
835 throw std::runtime_error(drain::StringBuilder<':'>(__FILE__,__FUNCTION__, " empty key (ADD static child counter based naming"));
836 return *this;
837 }
838
839 if (EXCLUSIVE){
840 this->clearData();
841 }
842
843 // Try searching first. So, does not reposition (delete and prepend) if exists.
844 if (!isMultiple()){
845 for (auto & entry: children){
846 if (entry.first == key){
847 return entry.second;
848 }
849 }
850 }
851
852 // Add:
853 children.push_front(pair_t(key, tree_t()));
854 tree_t & child = children.front().second; //children.insert(children.begin(), pair_t(key, tree_t()))->second;
855 initChild(child);
856 return child;
857 //return children.back().second;
858 #endif
859
860 };
861
863 inline
865 return prependChild();
866 }
867
869 inline
870 tree_t & operator++(int){ // int: dummy arg
871 return addChild();
872 }
873
874
875 // Functions perhaps less relevant ....................................
876
878
881 inline
882 container_t & getChildren() { return children; };
883
885 inline
886 const container_t & getChildren() const { return children; };
887
888
889
890 // New
892 inline
893 const node_data_t *operator->() const {
894 return &data;
895 };
896
898 inline
899 node_data_t *operator->(){
900 return &data;
901 };
902
903
905 inline
906 void swap(tree_t &t){
907 children.swap(t.children);
908 swapData(t.data);
909 }
910
912 void swapData(node_data_t &node){
913 if (!(dataEmpty() && dataEmpty(node.empty))) {
914 Logger(__FILE__, __FUNCTION__).unimplemented(TypeName<DRAIN_TREE_NAME>::str(),
915 ": node data exists but is not swapped");
916 }
917 }
918
919
921 /*
922 * As an option, child nodes can be addressed using keys which are not of key_y type, but can be converted to such.
923 */
924 static inline
925 const key_t & getKey(const key_t & key){
926 return key;
927 }
928
930 // NOTE: char * should not be directed to getKey! (But more to inst std::string(key)
931 // Return to temp?
932 static inline
933 key_t getKey(const char * key){
934 return key_t(key);
935 }
936
938 /*
939 * As an option, child nodes can be addressed using keys which are not of key_y type, but can be converted to such.
940 * Note that this version returns a constant reference.
941 */
942 template <typename K>
943 static
944 const key_t & getKey(const K & key); // left undefined!
945
946
947protected:
948
949 container_t children;
950
951 static
952 const tree_t emptyNode;
953
954 virtual
955 tree_t & retrieveChild(const key_t & key){
956
957 if (key.empty())
958 return *this;
959
960 // ! if (EXCLUSIVE) this->clearData();
961
962 #ifdef DRAIN_TREE_ORDERED
963 // Old policy restored; keys must implement empty(), an empty key is indentified to the current node.
964
965 // return children[key];
966 iterator it = children.find(key);
967 if (it != children.end()){
968 return it->second;
969 }
970 else {
971 tree_t & child = children.insert(children.begin(), pair_t(key, tree_t()))->second;
972 initChild(child);
973 return child;
974 //
975 // return children.insert(children.begin(), pair_t(key, tree_t()))->second;
976 }
977
978 #else
979
980 for (auto & entry: children){
981 if (entry.first == key){
982 return entry.second;
983 }
984 }
985 // if (EXCLUSIVE) this->clearData();
986 children.push_back(pair_t(key, tree_t()));
987 tree_t & child = children.back().second; //children.insert(children.begin(), pair_t(key, tree_t()))->second;
988 initChild(child);
989 return child;
990 // return children.back().second;
991
992 #endif
993 };
994
995
996 virtual
997 const tree_t & retrieveChild(const key_t & key) const {
998
999 if (key.empty())
1000 return *this;
1001
1002 #ifdef DRAIN_TREE_ORDERED
1003 const const_iterator it = children.find(key);
1004 if (it != children.end()){
1005 return it->second;
1006 }
1007 #else // traverse
1008 for (const auto & entry: children){
1009 if (entry.first == key){
1010 return entry.second;
1011 }
1012 }
1013 #endif
1014
1015 return getEmpty();
1016 };
1017
1018
1020
1024 bool hasPath(typename path_t::const_iterator it, typename path_t::const_iterator eit) const {
1025
1026 if (it == eit) // empty path
1027 return true;
1028
1029 const typename path_t::elem_t elem = *it;
1030
1031 if (elem.empty())
1032 return hasPath(++it, eit);
1033 else if (!hasChild(elem))
1034 return false;
1035
1036 return this->operator [](elem).hasPath(++it, eit);
1037
1038 }
1039
1041
1043 inline
1044 tree_t & get(typename path_t::const_iterator it, typename path_t::const_iterator eit) {
1045
1046 // Path empty => self-reference
1047 if (it == eit)
1048 return *this;
1049
1050 // Path element is empty => proceed to next element
1051 if (it->empty())
1052 return get(++it, eit);
1053
1054 tree_t & child = operator[](*it);
1055 return child.get(++it, eit);
1056
1057 }
1058
1059
1060
1062
1065 inline
1066 const tree_t & get(typename path_t::const_iterator it, typename path_t::const_iterator eit) const {
1067
1068 // Path empty => self-reference
1069 if (eit == it) // order, 2023/04
1070 return *this;
1071
1072 // Path element is empty => skip it (proceed to next element)
1073 if (it->empty())
1074 return get(++it, eit);
1075
1076 // NEW ~faulty? data1/data1/data1/...
1077
1078 if (hasChild(*it)){
1079 //return retrieveChild(*it); <- ADD <- .get(++it, eit); ?
1080 return retrieveChild(*it).get(++it, eit);
1081 }
1082 else {
1083 return getEmpty();
1084 }
1085
1086 // OLD (limited to map container, reconsider NEW, above!)
1087 /*
1088 typename tree_t::const_iterator child_it = this->children.find(*it);
1089 if (child_it == this->children.end())
1090 return getEmpty();
1091 else
1092 return child_it->second.get(++it, eit);
1093 */
1094
1095 /*
1096 if (!hasChild(*it))
1097 return getEmpty();
1098 const tree_t & child = operator[](*it); // use find? Or better, direct child[key]
1099 //const tree_t & child = this->children[*it]; // use find? Or better, direct child[key] 2023/04
1100
1101 return child.get(++it, eit);
1102 */
1103 }
1104
1105
1106
1107};
1108
1109template <class T, bool EXCLUSIVE, class P>
1110const DRAIN_TREE_NAME<T,EXCLUSIVE, P> DRAIN_TREE_NAME<T,EXCLUSIVE,P>::emptyNode;
1111
1112template <class T, bool EXCLUSIVE, class P>
1113void DRAIN_TREE_NAME<T,EXCLUSIVE, P>::generateKey(const DRAIN_TREE_NAME<T,EXCLUSIVE, P> & tree, typename P::elem_t & key){
1114 std::stringstream k; // ("elem");
1115 k << "elem"; // number with 4 digits overwrites this?
1116 k.width(4); // consider static member prefix
1117 k.fill('0');
1118 k << tree.getChildren().size();
1119 // Also derived classes require this assignment
1120 //key.assign(k.str());
1121 key = k.str();
1122}
1123
1124#define DRAIN_TREE_NODE_SWAP(tree_t) template <> inline void tree_t::swapData(tree_t::node_data_t & node){ data.swap(node)); }
1125
1126
1127
1128// @certified
1129template <class T, bool EXCLUSIVE, class P>
1130struct TypeName<DRAIN_TREE_NAME<T,EXCLUSIVE, P> > {
1131
1133
1134 static
1135 const std::string & str(){
1136
1137 static const std::string name = drain::StringBuilder<>(
1138 tree_t::isOrdered()?"Ordered":"Unordered",
1139 tree_t::isMultiple()?"Multi":"","Tree",
1140 tree_t::isExclusive()?"(Exclusive)":"",
1141 '<', TypeName<typename tree_t::node_data_t>::str(), '>'); // recursion...
1142 //'<', drain::Type::call<drain::simpleName>(typeid(typename tree_t::node_data_t)), '>');
1143 return name;
1144 }
1145
1146};
1147
1148
1149/*
1150template<class T, bool EXCLUSIVE, class P>
1151void OrderedTree<T,EXCLUSIVE,P>::swapData(node_data_t &node) {
1152 if (!(dataEmpty() && node.empty())) {
1153 Logger(__FILE__, __FUNCTION__).unimplemented(TypeName<OrderedTree<T,EXCLUSIVE,P> >::str(),
1154 ": node data exists but is not swapped");
1155 }
1156}
1157*/
1158
1159} // drain::
1160
1161
A templated class for directed rooted trees.
Definition Tree.h:147
virtual int hasChildren(const key_t &key) const
The number of children with name key.
Definition Tree.h:624
void clearChildren()
Clears the children of this node. Does not clear data.
Definition Tree.h:537
tree_t & operator[](const K &key)
NEW 2025 templated child addressing operator.
Definition Tree.h:424
void swap(tree_t &t)
Replace children (but no data?)
Definition Tree.h:906
const tree_t & operator()(const char *arg) const
Redirects the call to operator()(const std::string & arg) .
Definition Tree.h:502
const tree_t & get(typename path_t::const_iterator it, typename path_t::const_iterator eit) const
Given the descendant pointed to by a given path segment.
Definition Tree.h:1066
container_t::const_iterator end() const
Child iterator pointing beyond the last child.
Definition Tree.h:236
tree_t & operator=(const tree_t &t)
Copies the data of another node. Does not copy the children.
Definition Tree.h:286
tree_t & prependChild()
Push in the front. This is only available for unordered trees.
Definition Tree.h:808
node_data_t data
Contents (data) of the node.
Definition Tree.h:180
tree_t & operator=(const std::initializer_list< V > &l)
Assign data.
Definition Tree.h:377
static bool isMultiple()
True, if this tree type can contain children with a same key (path element).
Definition Tree.h:260
container_t::iterator begin()
Child iterator pointing to the first child.
Definition Tree.h:240
const tree_t & operator[](const K &key) const
NEW 2025 templated child addressing operator.
Definition Tree.h:432
tree_t & operator()(const char *arg)
Redirects the call to operator()(const std::string & arg) .
Definition Tree.h:476
virtual const tree_t & getEmpty() const
Definition Tree.h:592
const tree_t & operator()(const path_t &path) const
Returns a descendant if that exists, else returns an empty node. Otherwise like non-const counterpart...
Definition Tree.h:489
static const key_t & getKey(const K &key)
Mapping of keys of external type - for example an enumerated type - to native key_t type.
tree_t & operator++()
Shorthand for prependChild().
Definition Tree.h:864
tree_t & addChild(const E &key)
Converts argument to std:string and calls addChild()
Definition Tree.h:798
virtual bool empty() const
Check if the tree node has empty data and no children.
Definition Tree.h:599
const container_t & getChildren() const
Returns the map containing the children.
Definition Tree.h:886
static key_t getKey(const char *key)
Conversion of char array to key type (which is never a char array).
Definition Tree.h:933
tree_t & operator=(std::initializer_list< std::pair< K, V > > l)
Assign tree structure (of depth one).
Definition Tree.h:342
void initChild(tree_t &) const
Means for automatically setting something, for example the type of a node.
Definition Tree.h:703
DRAIN_TREE_NAME(const DRAIN_TREE_NAME &t)
Copy constructor; copy only node data at the root.
Definition Tree.h:173
const tree_t & operator()(const S &arg) const
Returns a descendant if that exists, else returns an empty node. Otherwise like non-const counterpart...
Definition Tree.h:496
static bool isExclusive()
True, if this tree type can either children or node data, but not both.
Definition Tree.h:254
const node_data_t * operator->() const
Fast access to data, applied widely in TreeXML (HTML/SVG)
Definition Tree.h:893
void swapData(node_data_t &node)
User should redefine (implement) this function for applied node types.
Definition Tree.h:912
tree_t & addChild(const key_t &key)
Ensure that a child node with given key exists. For MULTIPLE, always add one.
Definition Tree.h:746
bool hasPath(typename path_t::const_iterator it, typename path_t::const_iterator eit) const
Checks if there is a node with a given path name.
Definition Tree.h:1024
tree_t & operator=(const T2 &v)
Assigns value to contents.
Definition Tree.h:318
node_data_t * operator->()
Fast access to data, applied widely in TreeXML (HTML/SVG)
Definition Tree.h:899
void erase(const path_t &path)
Deletes a descendant node and hence its subtrees.
Definition Tree.h:549
container_t & getChildren()
Returns the map containing the children.
Definition Tree.h:882
tree_t & operator<<(const node_pair_t &entry)
Experimental. Given pair(elem, data) assigns child[elem] = data;.
Definition Tree.h:392
DRAIN_TREE_NAME()
Default constructor.
Definition Tree.h:165
tree_t & prependChild(const E &key)
Converts argument to std:string and calls addChild()
Definition Tree.h:820
tree_t & operator()(const S &arg)
Returns a descendant. Creates one if not existing already.
Definition Tree.h:467
static const key_t & getKey(const key_t &key)
"Default implementation" of key conversion – the identity mapping.
Definition Tree.h:925
void clearData()
Definition Tree.h:525
virtual bool hasChild(const key_t &key) const
Check if the tree node has a direct descendant with name key.
Definition Tree.h:659
void clear()
Clear children and node data.
Definition Tree.h:514
std::pair< key_t, node_data_t > node_pair_t
Experimental. Given pair<elem, data> assigns child[elem] = data;.
Definition Tree.h:387
container_t::const_iterator begin() const
Iterator interface enables for-each type iteration.
Definition Tree.h:232
container_t::iterator end()
Child iterator end.
Definition Tree.h:244
DRAIN_TREE_NAME(const node_data_t &data)
Copy constructor; copy only node data at the root.
Definition Tree.h:169
tree_t & addChild()
Add a child with an automatically generated key (path element).
Definition Tree.h:715
tree_t & operator()(const path_t &path)
Returns a descendant. Creates one if not existing already.
Definition Tree.h:446
static bool isOrdered()
True, if the keys of the children of a node are stored in an ordered structure (that is,...
Definition Tree.h:270
static bool dataEmpty(const node_data_t &data)
Default implementation. To be redefined (template-implemented).
Definition Tree.h:187
tree_t & operator=(std::initializer_list< std::pair< const char *, const Variable > > l)
Assign tree structure (of depth one).
Definition Tree.h:359
tree_t & get(typename path_t::const_iterator it, typename path_t::const_iterator eit)
Returns a descendant. Creates one, if not present.
Definition Tree.h:1044
tree_t & operator++(int)
Shorthand for appendChild().
Definition Tree.h:870
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:521
Definition Path.h:135
Definition StringBuilder.h:58
Definition Data.h:1473
Default implementation.
Definition TypeName.h:54
static const std::string & str()
Default implementation: name returned by std::type_info::name()
Definition TypeName.h:68