SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
time_sequence.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_TIME_SEQUENCE_H_
3 #define SYDEVS_TIME_SEQUENCE_H_
4 
6 
7 namespace sydevs {
8 
9 
60 {
61 public:
62  class const_iterator;
63  using value_type = std::pair<int64, time_point>;
64 
65  time_sequence();
66 
67  time_sequence(const time_sequence&) = default;
68  time_sequence& operator=(const time_sequence&) = default;
69  time_sequence(time_sequence&&) = default;
70  time_sequence& operator=(time_sequence&&) = default;
71  ~time_sequence() = default;
72 
73  bool empty() const;
74  int64 size() const;
75 
76  void append(const time_point& tp);
77 
78  const_iterator begin() const;
79  const_iterator end() const;
80 
81  const_iterator lower_bound(const time_point& tp) const;
82  const_iterator upper_bound(const time_point& tp) const;
83 
84  const time_point front() const;
85  const time_point back() const;
86  const time_point operator[](int64 rhs) const;
87 
88  const std::vector<value_type>& partitions() const;
89 
90 private:
91  std::vector<value_type> partitions_;
92  std::vector<duration> offsets_;
93 };
94 
95 
96 class time_sequence::const_iterator : public std::iterator<std::random_access_iterator_tag, const time_sequence::value_type, int64>
97 {
98 friend class time_sequence;
99 public:
100  const time_sequence::value_type& operator*() const;
101  const time_sequence::value_type* operator->() const;
102  const time_sequence::value_type operator[](int64 rhs) const;
103 
110 
111  const_iterator operator+(int64 rhs) const;
112  const_iterator operator-(int64 rhs) const;
113 
114  int64 operator-(const_iterator rhs) const;
115 
116  bool operator==(const const_iterator& rhs) const;
117  bool operator!=(const const_iterator& rhs) const;
118  bool operator<(const const_iterator& rhs) const;
119  bool operator>(const const_iterator& rhs) const;
120  bool operator<=(const const_iterator& rhs) const;
121  bool operator>=(const const_iterator& rhs) const;
122 
123 private:
124  const_iterator(const time_sequence& ts, int64 pi, int64 ti);
125 
126  const time_sequence* ts_ptr_;
127  int64 pi_;
129 };
130 
131 
132 inline bool time_sequence::empty() const
133 {
134  return partitions_.empty();
135 }
136 
137 
139 {
140  return int64(offsets_.size());
141 }
142 
143 
144 inline const std::vector<time_sequence::value_type>& time_sequence::partitions() const
145 {
146  return partitions_;
147 }
148 
149 
150 } // namespace
151 
152 #endif
const time_point operator[](int64 rhs) const
Returns the time point associated with the index rhs.
Definition: time_sequence.cpp:109
const_iterator lower_bound(const time_point &tp) const
Returns an iterator to the first position tp could be inserted.
Definition: time_sequence.cpp:43
const std::vector< value_type > & partitions() const
Returns the partition indices and associated time points.
Definition: time_sequence.h:144
const time_point back() const
Returns the last time point.
Definition: time_sequence.cpp:103
bool operator<(const const_iterator &rhs) const
Definition: time_sequence.cpp:252
const_iterator operator+(int64 rhs) const
Definition: time_sequence.cpp:218
const time_sequence::value_type operator[](int64 rhs) const
Definition: time_sequence.cpp:137
bool operator>(const const_iterator &rhs) const
Definition: time_sequence.cpp:258
const_iterator & operator-=(int64 rhs)
Definition: time_sequence.cpp:211
const_iterator operator-(int64 rhs) const
Definition: time_sequence.cpp:226
int64 size() const
Returns the number of time points.
Definition: time_sequence.h:138
bool empty() const
Returns true if the time sequence is empty.
Definition: time_sequence.h:132
void append(const time_point &tp)
Appends tp if it exceeds all previously added time points.
Definition: time_sequence.cpp:14
bool operator==(const const_iterator &rhs) const
Definition: time_sequence.cpp:240
A data structure which represents a sequence of increasing time points.
Definition: time_sequence.h:59
const time_point front() const
Returns the first time point.
Definition: time_sequence.cpp:97
A data structure which represents a point in time as an arbitrary-precision multiple of its shortest ...
Definition: time_point.h:84
bool operator>=(const const_iterator &rhs) const
Definition: time_sequence.cpp:270
const_iterator & operator--()
Definition: time_sequence.cpp:164
const_iterator & operator++()
Definition: time_sequence.cpp:143
const_iterator begin() const
Returns an iterator pointing to the oldest entry.
Definition: time_sequence.cpp:31
const time_sequence::value_type * operator->() const
Definition: time_sequence.cpp:130
const_iterator & operator+=(int64 rhs)
Definition: time_sequence.cpp:185
bool operator<=(const const_iterator &rhs) const
Definition: time_sequence.cpp:264
const float64 pi
Definition: number_types.h:24
Definition: time_sequence.h:96
const_iterator end() const
Returns an iterator pointing beyond the newest entry.
Definition: time_sequence.cpp:37
int64_t int64
Definition: number_types.h:14
std::pair< int64, time_point > value_type
The type used to store each entry.
Definition: time_sequence.h:63
time_sequence & operator=(const time_sequence &)=default
Copy assignment.
const time_sequence::value_type & operator*() const
Definition: time_sequence.cpp:123
~time_sequence()=default
Destructor.
const_iterator upper_bound(const time_point &tp) const
Returns an iterator to the last position tp could be inserted.
Definition: time_sequence.cpp:73
time_sequence()
Constructs an empty time sequence.
Definition: time_sequence.cpp:7
bool operator!=(const const_iterator &rhs) const
Definition: time_sequence.cpp:246