initialiser.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_CONTAINERS_INITIALISER_HPP_
00013 #define ECL_CONTAINERS_INITIALISER_HPP_
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <cstddef>  // size_t
00020 #include "definitions.hpp"
00021 #include <ecl/config/macros.hpp>
00022 #include <ecl/exceptions/standard_exception.hpp>
00023 
00024 /*****************************************************************************
00025 ** Namespaces
00026 *****************************************************************************/
00027 
00028 namespace ecl {
00029 namespace containers {
00030 
00031 /*****************************************************************************
00032 ** Interface [BoundedListInitialiser]
00033 *****************************************************************************/
00048 template<class Type, class Iterator, std::size_t N = ecl::DynamicStorage>
00049 class ECL_LOCAL BoundedListInitialiser {
00050 
00051     public:
00058         BoundedListInitialiser(const Type &value, Iterator iter);
00059 
00060         virtual ~BoundedListInitialiser() {}
00061 
00072         BoundedListInitialiser<Type, Iterator, N>& operator,(const Type &value) ecl_assert_throw_decl(StandardException);
00073 
00074     protected:
00075         Iterator iterator;
00076         std::size_t current_size;
00077 };
00078 
00079 /*****************************************************************************
00080 ** Implementation [BoundedListInitialiser]
00081 *****************************************************************************/
00082 
00083 template <typename Type, typename Iterator, std::size_t N>
00084 BoundedListInitialiser<Type,Iterator,N>::BoundedListInitialiser(const Type &value, Iterator iter) :
00085     iterator(iter),
00086     current_size(1)
00087 {
00088     *iterator = value;
00089     ++iterator;
00090 }
00091 template <typename Type,typename Iterator,std::size_t N>
00092 BoundedListInitialiser<Type,Iterator,N>& BoundedListInitialiser<Type,Iterator,N>::operator,(const Type &value) ecl_assert_throw_decl(StandardException)
00093 {
00094     ecl_assert_throw( current_size < N, StandardException(LOC,OutOfRangeError) );
00095     *iterator = value;
00096     iterator++;
00097     current_size++;
00098     return *this;
00099 }
00100 
00101 /*****************************************************************************
00102 ** Interface [BoundedListInitialiser][Dynamic]
00103 *****************************************************************************/
00116 template<class Type, class Iterator>
00117 class ECL_LOCAL BoundedListInitialiser<Type,Iterator,DynamicStorage> {
00118 
00119     public:
00129         BoundedListInitialiser(const Type &value, Iterator iter, std::size_t bound) ecl_assert_throw_decl(StandardException);
00130 
00131         virtual ~BoundedListInitialiser() {}
00142         BoundedListInitialiser<Type, Iterator, DynamicStorage>& operator,(const Type &value) ecl_assert_throw_decl(StandardException);
00143 
00144     protected:
00145         Iterator iterator;
00146         std::size_t current_size;
00147         const std::size_t upper_bound;
00148 };
00149 
00150 /*****************************************************************************
00151 ** Implementation [BoundedListInitialiser]
00152 *****************************************************************************/
00153 
00154 template <typename Type, typename Iterator>
00155 BoundedListInitialiser<Type,Iterator,DynamicStorage>::BoundedListInitialiser(const Type &value, Iterator iter, std::size_t bound) ecl_assert_throw_decl(StandardException) :
00156     iterator(iter),
00157     current_size(1),
00158     upper_bound(bound)
00159 {
00160     ecl_assert_throw( current_size <= upper_bound, StandardException(LOC,OutOfRangeError) );
00161     *iterator = value;
00162     ++iterator;
00163 }
00164 template <typename Type,typename Iterator>
00165 BoundedListInitialiser<Type,Iterator,DynamicStorage>& BoundedListInitialiser<Type,Iterator,DynamicStorage>::operator,(const Type &value) ecl_assert_throw_decl(StandardException)
00166 {
00167     ecl_assert_throw( current_size < upper_bound, StandardException(LOC,OutOfRangeError) );
00168     *iterator = value;
00169     iterator++;
00170     current_size++;
00171     return *this;
00172 }
00173 
00174 }; // namespace containers
00175 }; // namespace ecl
00176 
00177 #endif /* ECL_CONTAINERS_INITIALISER_HPP_ */


ecl_containers
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:42