initialiser.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_CONTAINERS_INITIALISER_HPP_
13 #define ECL_CONTAINERS_INITIALISER_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <cstddef> // size_t
20 #include "definitions.hpp"
21 #include <ecl/config/macros.hpp>
23 
24 /*****************************************************************************
25 ** Namespaces
26 *****************************************************************************/
27 
28 namespace ecl {
29 namespace containers {
30 
31 /*****************************************************************************
32 ** Interface [BoundedListInitialiser]
33 *****************************************************************************/
48 template<class Type, class Iterator, std::size_t N = ecl::DynamicStorage>
49 class ECL_LOCAL BoundedListInitialiser {
50 
51  public:
58  BoundedListInitialiser(const Type &value, Iterator iter);
59 
60  virtual ~BoundedListInitialiser() {}
61 
72  BoundedListInitialiser<Type, Iterator, N>& operator,(const Type &value);
73 
74  protected:
75  Iterator iterator;
76  std::size_t current_size;
77 };
78 
79 /*****************************************************************************
80 ** Implementation [BoundedListInitialiser]
81 *****************************************************************************/
82 
83 template <typename Type, typename Iterator, std::size_t N>
85  iterator(iter),
86  current_size(1)
87 {
88  *iterator = value;
89  ++iterator;
90 }
91 template <typename Type,typename Iterator,std::size_t N>
93 {
94  ecl_assert_throw( current_size < N, StandardException(LOC,OutOfRangeError) );
95  *iterator = value;
96  iterator++;
97  current_size++;
98  return *this;
99 }
100 
101 /*****************************************************************************
102 ** Interface [BoundedListInitialiser][Dynamic]
103 *****************************************************************************/
116 template<class Type, class Iterator>
117 class ECL_LOCAL BoundedListInitialiser<Type,Iterator,DynamicStorage> {
118 
119  public:
129  BoundedListInitialiser(const Type &value, Iterator iter, std::size_t bound);
130 
131  virtual ~BoundedListInitialiser() {}
142  BoundedListInitialiser<Type, Iterator, DynamicStorage>& operator,(const Type &value);
143 
144  protected:
145  Iterator iterator;
146  std::size_t current_size;
147  const std::size_t upper_bound;
148 };
149 
150 /*****************************************************************************
151 ** Implementation [BoundedListInitialiser]
152 *****************************************************************************/
153 
154 template <typename Type, typename Iterator>
155 BoundedListInitialiser<Type,Iterator,DynamicStorage>::BoundedListInitialiser(const Type &value, Iterator iter, std::size_t bound) :
156  iterator(iter),
157  current_size(1),
158  upper_bound(bound)
159 {
160  ecl_assert_throw( current_size <= upper_bound, StandardException(LOC,OutOfRangeError) );
161  *iterator = value;
162  ++iterator;
163 }
164 template <typename Type,typename Iterator>
166 {
168  *iterator = value;
169  iterator++;
170  current_size++;
171  return *this;
172 }
173 
174 }; // namespace containers
175 }; // namespace ecl
176 
177 #endif /* ECL_CONTAINERS_INITIALISER_HPP_ */
ecl::containers::BoundedListInitialiser::operator,
BoundedListInitialiser< Type, Iterator, N > & operator,(const Type &value)
Definition: initialiser.hpp:104
ecl::containers::BoundedListInitialiser::iterator
Iterator iterator
Definition: initialiser.hpp:95
ECL_LOCAL
#define ECL_LOCAL
ecl::DynamicStorage
@ DynamicStorage
Definition: definitions.hpp:42
ecl::StandardException
ecl::containers::BoundedListInitialiser< Type, Iterator, DynamicStorage >
Convenience initialiser with bounds checking for dynamic containers.
Definition: initialiser.hpp:129
definitions.hpp
Some common container definitions.
ecl_assert_throw
#define ecl_assert_throw(expression, exception)
standard_exception.hpp
ecl::containers::BoundedListInitialiser::BoundedListInitialiser
BoundedListInitialiser(const Type &value, Iterator iter)
Definition: initialiser.hpp:96
ecl::containers::BoundedListInitialiser
Convenience initialiser with bounds checking for fixed size containers.
Definition: initialiser.hpp:61
macros.hpp
ecl::containers::BoundedListInitialiser::current_size
std::size_t current_size
Definition: initialiser.hpp:96
ecl::OutOfRangeError
OutOfRangeError
ecl
Embedded control libraries.


ecl_containers
Author(s): Daniel Stonier
autogenerated on Sun Aug 2 2020 03:12:14