VISR  0.11.8
Versatile Interactive Scene Renderer
channel_list.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_CHANNEL_LIST_HPP_INCLUDED
4 #define VISR_CHANNEL_LIST_HPP_INCLUDED
5 
6 #include "export_symbols.hpp"
7 
8 #include <iterator>
9 #include <initializer_list>
10 #include <ostream>
11 #include <vector>
12 
13 namespace visr
14 {
15 
16 // Forward declaration
17 class ChannelRange;
18 
24 class VISR_CORE_LIBRARY_SYMBOL ChannelList
25 {
26 public:
27  using IndexType = std::size_t;
28 
32  ChannelList();
33 
41  ChannelList( ChannelRange const & range );
42 
50  ChannelList( std::initializer_list<IndexType> const & initList );
51 
58  ChannelList( std::initializer_list<ChannelRange> const & initList );
59 
69  template< class Container>
70  ChannelList( Container const & container )
71  : ChannelList( std::begin(container), std::end(container) )
72  {
73  }
74 
82  template< class Iterator>
83  ChannelList( Iterator begin, Iterator end )
84  {
85  for( ; begin != end; ++begin )
86  {
87  appendIndex( *begin );
88  }
89  }
90 
94  ~ChannelList();
95 
99  std::size_t size() const;
100 
106  IndexType operator[]( std::size_t idx ) const;
107 
113  IndexType& operator[]( std::size_t idx );
114 
120  IndexType at( std::size_t idx ) const;
121 
127  IndexType& at( std::size_t idx );
128 
129  using ListType = std::vector<IndexType>;
130  using const_iterator = ListType::const_iterator;
131 
137  const_iterator begin() const { return mChannels.begin(); }
138 
144  const_iterator end() const { return mChannels.end(); }
145 private:
146 
150  ListType mChannels;
151 
157  void appendIndex( IndexType index );
158 
162  void appendRange( ChannelRange const & range );
163 };
164 
170 VISR_CORE_LIBRARY_SYMBOL std::ostream & operator<<( std::ostream & str, ChannelList const channels );
171 
177 class VISR_CORE_LIBRARY_SYMBOL ChannelRange
178 {
179 public:
181  using StepType = std::ptrdiff_t;
182 
186  ChannelRange();
187 
193  ChannelRange( IndexType val );
194 
203  ChannelRange( IndexType start, IndexType end, StepType step = 1 );
204 
213  void set( IndexType start, IndexType end, StepType stride = 1 );
214 
218  static bool isValid( IndexType start, IndexType size, StepType stride );
219 
224  bool isValid() const;
225 
229  IndexType size() const;
230 
234  IndexType start() const { return mStart; }
235 
240  IndexType end() const { return mEnd; }
241 
245  StepType step() const { return mStep; }
246 
251  IndexType at( IndexType idx ) const;
252 
257  IndexType operator[]( IndexType idx ) const;
258 
263  IndexType at( IndexType idx );
264 
269  IndexType operator[]( IndexType idx );
270 
271 private:
272  IndexType mStart;
273  IndexType mEnd;
274  StepType mStep;
275 };
276 
280 VISR_CORE_LIBRARY_SYMBOL std::ostream & operator<<( std::ostream & str, ChannelRange const range );
281 
282 } // namespace visr
283 
284 #endif // #ifndef VISR_CHANNEL_LIST_HPP_INCLUDED
ChannelList(Iterator begin, Iterator end)
Definition: channel_list.hpp:83
ChannelList(Container const &container)
Definition: channel_list.hpp:70
ListType::const_iterator const_iterator
Definition: channel_list.hpp:130
IndexType end() const
Definition: channel_list.hpp:240
std::size_t IndexType
Definition: channel_list.hpp:27
std::vector< IndexType > ListType
Definition: channel_list.hpp:129
ChannelList::IndexType IndexType
Definition: channel_list.hpp:180
Definition: channel_list.hpp:24
const_iterator end() const
Definition: channel_list.hpp:144
Definition: options.cpp:10
Definition: channel_list.hpp:177
std::ptrdiff_t StepType
Definition: channel_list.hpp:181
IndexType start() const
Definition: channel_list.hpp:234
std::ostream & operator<<(std::ostream &str, ChannelList const channels)
Definition: channel_list.cpp:182
StepType step() const
Definition: channel_list.hpp:245
const_iterator begin() const
Definition: channel_list.hpp:137