Changeset 1cb7fab2 for src/Common/Stats/Base.h
- Timestamp:
- Mar 4, 2019, 2:53:55 PM (5 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 874ffa4
- Parents:
- 675716e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Stats/Base.h
r675716e r1cb7fab2 16 16 #pragma once 17 17 18 #include <string>19 20 18 namespace Stats { 21 19 namespace Base { 20 class TreeImpl; 21 22 struct TreeTop { 23 TreeImpl * head = nullptr; 24 TreeImpl * tail = nullptr; 25 26 inline void append(TreeImpl * node); 27 }; 28 29 template<typename func_t> 30 void ForAll(TreeTop & range, size_t level, func_t func, bool destroy = false); 31 22 32 class TreeImpl { 23 33 public: 24 struct Top {25 TreeImpl * head = nullptr;26 TreeImpl * tail = nullptr;27 28 void append(TreeImpl * node) {29 if(!head) { head = node; }30 else { tail->next = node;}31 tail = node;32 }33 };34 35 34 virtual void print(std::ostream &) = 0; 36 35 37 const std::stringname;38 TreeImpl(const std::string &name) : name(name) {}36 const char * const name; 37 TreeImpl(const char * const name) : name(name) {} 39 38 40 39 protected: … … 42 41 43 42 TreeImpl * next = nullptr; 44 Top children; 43 TreeTop children; 44 45 friend struct TreeTop; 45 46 46 47 template<typename func_t> 47 friend void ForAll(Tree Impl::Top & range, size_t level, func_t func, bool destroy = false);48 friend void ForAll(TreeTop & range, size_t level, func_t func, bool destroy); 48 49 }; 49 50 51 void TreeTop::append(TreeImpl * node) { 52 if(!head) { head = node; } 53 else { tail->next = node;} 54 tail = node; 55 } 56 50 57 template<typename func_t> 51 inline void ForAll(Tree Impl::Top & range, size_t level, func_t func, bool destroy) {58 inline void ForAll(TreeTop & range, size_t level, func_t func, bool destroy) { 52 59 auto it = range.head; 53 60 while(it) { … … 60 67 } 61 68 62 template<Tree Impl::Top & top>69 template<TreeTop & top> 63 70 class Tree : public TreeImpl { 64 71 public: 65 Tree(const std::string &name) : TreeImpl{name} {72 Tree(const char * const name) : TreeImpl{name} { 66 73 top.append(this); 67 74 } 68 75 69 Tree(const std::string &name, Tree * parent) : TreeImpl{name} {76 Tree(const char * const name, Tree * parent) : TreeImpl{name} { 70 77 parent->children.append(this); 71 78 }
Note: See TracChangeset
for help on using the changeset viewer.