Debian Codegraph @

src/atlas/runtime/trace/CallStack.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <cstddef>
14 #include <string>
15 #include <vector>
16
17 namespace atlas {
18 class CodeLocation;
19 }
20
21 namespace atlas {
22 namespace runtime {
23 namespace trace {
24
25 /// @class CallStack
26 /// Instances of CallStack can keep track of nested CodeLocations
27 class CallStack {
28 public:
29 using const_iterator = std::vector<size_t>::const_iterator;
30
31 public:
32 void push(const CodeLocation&, const std::string& id = "");
33 void pop();
34
35 const_iterator begin() const { return stack_.begin(); }
36 const_iterator end() const { return stack_.begin() + size_; }
37
38 size_t hash() const;
39 size_t size() const { return size_; }
40
41 operator bool() const { return size_ > 0; }
42
43 public:
44 CallStack(): stack_(64){};
45 CallStack(const CallStack& other): stack_(other.stack_), size_(other.size_) {}
46 CallStack& operator=(const CallStack& other) {
47 stack_ = other.stack_;
48 size_ = other.size_;
49 hash_ = 0;
50 return *this;
51 }
52
53 private:
54 std::vector<size_t> stack_;
55 size_t size_{0};
56 mutable size_t hash_{0};
57 };
58
59 } // namespace trace
60 } // namespace runtime
61 } // namespace atlas