RTI Routing Service  Version 6.0.0
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
SampleIterator.hpp
1 /* $Id$
2 
3 (c) Copyright, Real-Time Innovations, 2014-2016.
4 All rights reserved.
5 
6 No duplications, whole or partial, manual or electronic, may be made
7 without express written permission. Any such copies, or
8 revisions thereof, must display this notice unaltered.
9 This code contains trade secrets of Real-Time Innovations, Inc.
10 
11 
12 modification history
13 --------------------
14 1.0a,05may14,acr Added ValidSampleIterator and valid_samples helper
15 1.0a,20mar13,acr Created
16 ============================================================================= */
17 
18 #ifndef RTI_ROUTING_PROCESSOR_SAMPLE_ITERATOR_HPP_
19 #define RTI_ROUTING_PROCESSOR_SAMPLE_ITERATOR_HPP_
20 
21 
22 #include <rti/routing/processor/LoanedSample.hpp>
23 
24 
25 namespace rti { namespace routing { namespace processor {
26 
35 template <typename T, typename U>
37 public:
38  // iterator traits
39  typedef std::random_access_iterator_tag iterator_category;
40  typedef const LoanedSample<T,U> value_type;
41  typedef value_type reference;
42  typedef value_type pointer;
43  typedef std::ptrdiff_t difference_type;
44  typedef RTI_RoutingServiceSample* SampleSeqType;
45  typedef RTI_RoutingServiceSampleInfo* InfoSeqType;
46 
48  : _sample_seq(0),
49  _info_seq(0),
50  _length(0),
51  _pos(0)
52  {}
53 
54  explicit SampleIterator(
55  const SampleSeqType sample_seq,
56  const InfoSeqType info_seq,
57  int length,
58  int position = 0)
59  : _sample_seq(sample_seq),
60  _info_seq(info_seq),
61  _length(length),
62  _pos(position)
63  {}
64 
65  SampleIterator (const SampleIterator<T,U> & other)
66  : _sample_seq(other._sample_seq),
67  _info_seq(other._info_seq),
68  _length(other._length),
69  _pos(other._pos)
70  {}
71 
72  SampleIterator & operator = (const SampleIterator<T,U> & other)
73  {
74  _sample_seq = other._sample_seq;
75  _info_seq = other._info_seq;
76  _length = other._length;
77  _pos = other._pos;
78 
79  return *this;
80  }
81 
82  value_type operator * () const {
83  return value_type(_sample_seq[_pos], _info_seq[_pos]);
84  }
85 
86  value_type operator ->() const {
87  return value_type(_sample_seq[_pos], _info_seq[_pos]);
88  }
89 
90  value_type operator [] (difference_type offset) const {
91  return value_type(_sample_seq[_pos + offset], _info_seq[_pos + offset]);
92  }
93 
94  SampleIterator & operator ++ () {
95  ++_pos;
96  return *this;
97  }
98 
99  SampleIterator operator ++ (int) {
100  SampleIterator temp(*this);
101  ++(*this);
102  return temp;
103  }
104 
105  SampleIterator & operator -- () {
106  --_pos;
107  return *this;
108  }
109 
110  SampleIterator operator -- (int) {
111  SampleIterator temp(*this);
112  --(*this);
113  return temp;
114  }
115 
116  SampleIterator & operator -= (difference_type i) {
117  _pos -= i;
118  return *this;
119  }
120 
121  SampleIterator & operator += (difference_type i) {
122  _pos += i;
123  return *this;
124  }
125 
126  friend SampleIterator operator - (const SampleIterator & si,
127  difference_type i) {
128  return SampleIterator(si._sample_seq, si._info_seq, si._pos - i);
129  }
130 
131  friend SampleIterator operator + (const SampleIterator & si,
132  difference_type i) {
133  return SampleIterator(si._sample_seq, si._info_seq, si._pos + i);
134  }
135 
136  friend difference_type operator - (const SampleIterator & s1,
137  const SampleIterator & s2) {
138  return s1._pos - s2._pos;
139  }
140 
141  friend bool operator < (const SampleIterator & s1,
142  const SampleIterator & s2) {
143  return s1._pos < s2._pos;
144  }
145 
146  friend bool operator > (const SampleIterator & s1,
147  const SampleIterator & s2) {
148  return s1._pos > s2._pos;
149  }
150 
151  friend bool operator <= (const SampleIterator & s1,
152  const SampleIterator & s2) {
153  return s1._pos <= s2._pos;
154  }
155 
156  friend bool operator >= (const SampleIterator & s1,
157  const SampleIterator & s2) {
158  return s1._pos >= s2._pos;
159  }
160 
161  friend bool operator == (const SampleIterator & s1,
162  const SampleIterator & s2) {
163  return (s1._sample_seq == s2._sample_seq) && (s1._pos == s2._pos);
164  }
165 
166  friend bool operator != (const SampleIterator & s1,
167  const SampleIterator & s2) {
168  return !(s1 == s2);
169  }
170 
171  bool is_end() const {
172  return (_length == _pos);
173  }
174 
175  // Keep these members public otherwise some of the
176  // converting constructors will not compile.
177 public:
178  SampleSeqType _sample_seq;
179  InfoSeqType _info_seq;
180  int _length;
181  int _pos;
182 };
183 
184 
185 } } }
186 
187 #endif // RTI_ROUTING_PROCESSOR_SAMPLE_ITERATOR_HPP_

RTI Routing Service Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc