source: src/Common/Stats/Base.h @ 1cb7fab2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 1cb7fab2 was 1cb7fab2, checked in by tdelisle <tdelisle@…>, 5 years ago

Added better support for enabling/disabling/compiling-out statistics

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Heap.h --
8//
9// Author           : Thierry Delisle
10// Created On       : Fri Mar 03 14:53:53 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#pragma once
17
18namespace Stats {
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
32                class TreeImpl {
33                public:
34                        virtual void print(std::ostream &) = 0;
35
36                        const char * const name;
37                        TreeImpl(const char * const name) : name(name) {}
38
39                protected:
40                        virtual ~TreeImpl() = default;
41
42                        TreeImpl * next = nullptr;
43                        TreeTop children;
44
45                        friend struct TreeTop;
46
47                        template<typename func_t>
48                        friend void ForAll(TreeTop & range, size_t level, func_t func, bool destroy);
49                };
50
51                void TreeTop::append(TreeImpl * node) {
52                        if(!head) { head = node; }
53                        else      { tail->next = node;}
54                        tail = node;
55                }
56
57                template<typename func_t>
58                inline void ForAll(TreeTop & range, size_t level, func_t func, bool destroy) {
59                        auto it = range.head;
60                        while(it) {
61                                auto next = it->next;
62                                func(it, level);
63                                ForAll(it->children, level + 1, func);
64                                if(destroy) delete it;
65                                it = next;
66                        }
67                }
68
69                template<TreeTop & top>
70                class Tree : public TreeImpl {
71                public:
72                        Tree(const char * const name) : TreeImpl{name} {
73                                top.append(this);
74                        }
75
76                        Tree(const char * const name, Tree * parent) : TreeImpl{name} {
77                                parent->children.append(this);
78                        }
79                protected:
80                        virtual ~Tree() = default;
81                };
82        }
83}
Note: See TracBrowser for help on using the repository browser.