atlas
CallStack.h
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 <list>
15 #include <string>
16 
17 namespace atlas {
18 class CodeLocation;
19 }
20 
21 namespace atlas {
22 namespace runtime {
23 namespace trace {
24 
27 class CallStack {
28 public:
29  using const_iterator = std::list<size_t>::const_iterator;
30  using const_reverse_iterator = std::list<size_t>::const_reverse_iterator;
31 
32 public:
33  void push_front( const CodeLocation&, const std::string& id = "" );
34  void pop_front();
35 
36  const_iterator begin() const { return stack_.begin(); }
37  const_iterator end() const { return stack_.end(); }
38 
39  const_reverse_iterator rbegin() const { return stack_.rbegin(); }
40  const_reverse_iterator rend() const { return stack_.rend(); }
41 
42  size_t hash() const;
43  size_t size() const { return stack_.size(); }
44 
45  operator bool() const { return not stack_.empty(); }
46 
47 public:
48  CallStack() = default;
49  CallStack( const CallStack& other ) : stack_( other.stack_ ) {}
50  CallStack& operator=( const CallStack& other ) {
51  stack_ = other.stack_;
52  hash_ = 0;
53  return *this;
54  }
55 
56 private:
57  std::list<size_t> stack_;
58  mutable size_t hash_{0};
59 };
60 
61 } // namespace trace
62 } // namespace runtime
63 } // namespace atlas
Instances of CallStack can keep track of nested CodeLocations.
Definition: CallStack.h:27
Definition: CodeLocation.h:19
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33