source: src/Common/Stats/Base.h@ 874ffa4

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 874ffa4 was 1cb7fab2, checked in by tdelisle <tdelisle@…>, 7 years ago

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

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[675716e]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
[8e70823]16#pragma once
17
18namespace Stats {
19 namespace Base {
[1cb7fab2]20 class TreeImpl;
21
22 struct TreeTop {
23 TreeImpl * head = nullptr;
24 TreeImpl * tail = nullptr;
25
26 inline void append(TreeImpl * node);
27 };
[8e70823]28
[1cb7fab2]29 template<typename func_t>
30 void ForAll(TreeTop & range, size_t level, func_t func, bool destroy = false);
[8e70823]31
[1cb7fab2]32 class TreeImpl {
33 public:
[8e70823]34 virtual void print(std::ostream &) = 0;
35
[1cb7fab2]36 const char * const name;
37 TreeImpl(const char * const name) : name(name) {}
[8e70823]38
39 protected:
40 virtual ~TreeImpl() = default;
41
42 TreeImpl * next = nullptr;
[1cb7fab2]43 TreeTop children;
44
45 friend struct TreeTop;
[8e70823]46
47 template<typename func_t>
[1cb7fab2]48 friend void ForAll(TreeTop & range, size_t level, func_t func, bool destroy);
[8e70823]49 };
50
[1cb7fab2]51 void TreeTop::append(TreeImpl * node) {
52 if(!head) { head = node; }
53 else { tail->next = node;}
54 tail = node;
55 }
56
[8e70823]57 template<typename func_t>
[1cb7fab2]58 inline void ForAll(TreeTop & range, size_t level, func_t func, bool destroy) {
[8e70823]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
[1cb7fab2]69 template<TreeTop & top>
[8e70823]70 class Tree : public TreeImpl {
71 public:
[1cb7fab2]72 Tree(const char * const name) : TreeImpl{name} {
[8e70823]73 top.append(this);
74 }
75
[1cb7fab2]76 Tree(const char * const name, Tree * parent) : TreeImpl{name} {
[8e70823]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.