Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timeline.h
Go to the documentation of this file.
1 
18 #ifndef ION_PROFILE_TIMELINE_H_
19 #define ION_PROFILE_TIMELINE_H_
20 
21 #include <memory>
22 
23 #include "base/macros.h"
24 #include "ion/base/logging.h"
27 
47 class Timeline {
48  public:
49  Timeline() : root_(new TimelineNode("root")) {}
50  explicit Timeline(std::unique_ptr<TimelineNode> root)
51  : root_(std::move(root)) {}
52  Timeline(Timeline&& other) : root_(std::move(other.root_)) {}
53 
57  public:
58  const_iterator(const TimelineNode* node, const TimelineNode* root)
59  : node_(node), root_(root) {}
60  const TimelineNode* operator*() const { return node_; }
62  bool operator==(const const_iterator& other) const {
63  return node_ == other.node_;
64  }
65  bool operator!=(const const_iterator& other) const {
66  return !(*this == other);
67  }
68 
69  private:
70  const TimelineNode* node_;
71  const TimelineNode* root_;
72  };
73 
76  return ++const_iterator(root_.get(), root_.get());
77  }
79  const_iterator end() const { return const_iterator(nullptr, root_.get()); }
80 
83  const TimelineNode* GetRoot() const { return root_.get(); }
84 
85  private:
86  std::unique_ptr<TimelineNode> root_;
87  DISALLOW_COPY_AND_ASSIGN(Timeline);
88 };
89 
90 #endif // ION_PROFILE_TIMELINE_H_
Traverses the hierarchy in pre-order.
Definition: timeline.h:56
const_iterator end() const
Returns a const iterator to the end of the timeline.
Definition: timeline.h:79
const_iterator begin() const
Returns a const iterator over the timeline. The root node is skipped.
Definition: timeline.h:75
const TimelineNode * operator*() const
Definition: timeline.h:60
bool operator==(const const_iterator &other) const
Definition: timeline.h:62
Copyright 2016 Google Inc.
Definition: timeline.h:47
const TimelineNode * GetRoot() const
Returns a pointer to the root node.
Definition: timeline.h:83
Timeline()
Definition: timeline.h:49
const_iterator operator++()
Copyright 2016 Google Inc.
Definition: timeline.cc:26
bool operator!=(const const_iterator &other) const
Definition: timeline.h:65
Copyright 2016 Google Inc.
Definition: timelinenode.h:28
Copyright 2016 Google Inc.
Timeline(std::unique_ptr< TimelineNode > root)
Definition: timeline.h:50
const_iterator(const TimelineNode *node, const TimelineNode *root)
Definition: timeline.h:58
Timeline(Timeline &&other)
Definition: timeline.h:52