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>
22 #include <ecl/exceptions/standard_exception.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) ecl_assert_throw_decl(StandardException);
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>
92 BoundedListInitialiser<Type,Iterator,N>& BoundedListInitialiser<Type,Iterator,N>::operator,(const Type &value) ecl_assert_throw_decl(StandardException)
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) ecl_assert_throw_decl(StandardException);
130 
131  virtual ~BoundedListInitialiser() {}
142  BoundedListInitialiser<Type, Iterator, DynamicStorage>& operator,(const Type &value) ecl_assert_throw_decl(StandardException);
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) ecl_assert_throw_decl(StandardException) :
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>
165 BoundedListInitialiser<Type,Iterator,DynamicStorage>& BoundedListInitialiser<Type,Iterator,DynamicStorage>::operator,(const Type &value) ecl_assert_throw_decl(StandardException)
166 {
167  ecl_assert_throw( current_size < upper_bound, StandardException(LOC,OutOfRangeError) );
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_ */
#define ECL_LOCAL
#define LOC
Stringify the line of code you are at.
#define ecl_assert_throw(expression, exception)
Debug mode throw with a logical condition check.
BoundedListInitialiser(const Type &value, Iterator iter)
Definition: initialiser.hpp:84
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
DynamicStorage


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:37