specialisations.hpp
Go to the documentation of this file.
00001 
00006 /*****************************************************************************
00007 ** Ifdefs
00008 *****************************************************************************/
00009 
00010 #ifndef ecl_containers_SPECIALISATIONS_HPP_
00011 #define ecl_containers_SPECIALISATIONS_HPP_
00012 
00013 /*****************************************************************************
00014 ** Includes
00015 *****************************************************************************/
00016 
00017 #include "stencil.hpp"
00018 
00019 /*****************************************************************************
00020 ** Namespaces
00021 *****************************************************************************/
00022 
00023 namespace ecl {
00024 
00025 /*****************************************************************************
00026  ** Interface
00027  *****************************************************************************/
00038 template <>
00039 class ECL_PUBLIC Stencil<unsigned char*>
00040 {
00041 public:
00042   /*********************
00043    ** Typedefs
00044    **********************/
00045   typedef unsigned char value_type; 
00046   typedef unsigned char* iterator; 
00047   typedef const unsigned char* const_iterator; 
00048   typedef unsigned char& reference; 
00049   typedef const unsigned char& const_reference; 
00050   typedef std::size_t size_type; 
00051   typedef std::ptrdiff_t difference_type;
00052   typedef std::reverse_iterator<iterator> reverse_iterator; 
00053   typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 
00054   //typedef formatters::StencilFormatter<value_type,Array> Formatter;
00055 
00056   /*********************
00057    ** C&D's
00058    **********************/
00072   Stencil(iterator underlying_array, const unsigned int& length, iterator begin_iter, iterator end_iter) ecl_assert_throw_decl(StandardException) :
00073   array(underlying_array),
00074   length(length),
00075   b_iter(begin_iter),
00076   e_iter(end_iter)
00077   {
00078     ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
00079     ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
00080   }
00081 
00095   Stencil(iterator underlying_array, const unsigned int& length, const unsigned int& start_index = 0, const unsigned int &n = 0) ecl_assert_throw_decl(StandardException) :
00096   array(underlying_array),
00097   length(length),
00098   b_iter(array+start_index),
00099   e_iter(array+start_index+n)
00100   {
00101     ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
00102     ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
00103   }
00104 
00105   virtual ~Stencil()
00106   {};
00107 
00120   Stencil<unsigned char*> stencil(const unsigned int& start_index, const unsigned int& n) const ecl_assert_throw_decl(StandardException)
00121   {
00122     ecl_assert_throw( b_iter+start_index <= array+length, StandardException(LOC, OutOfRangeError, "Start index provided is larger than the underlying stencil size."));
00123     ecl_assert_throw( b_iter+start_index+n <= array+length, StandardException(LOC, OutOfRangeError, "Finish index provided is larger than the underlying stencil size."));
00124     // cant do out of range errors here (no idea how long the underlying array is!)
00125     return Stencil<unsigned char*>(array,length,b_iter+start_index,b_iter+start_index+n);
00126   }
00127 
00139   void resettle(const unsigned int& start_index, const unsigned int& n) ecl_assert_throw_decl(StandardException)
00140   {
00141 
00142     b_iter = array+start_index;
00143     e_iter = array+start_index+n;
00144     ecl_assert_throw((b_iter <= array + length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
00145     ecl_assert_throw((e_iter <= array + length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
00146   }
00147 
00148   /*********************
00149    ** Assignment
00150    **********************/
00164   containers::BoundedListInitialiser<value_type,iterator> operator<< (const value_type &value)
00165   {
00166     return containers::BoundedListInitialiser<value_type,iterator>(value, begin(), size());
00167   }
00181   Stencil<unsigned char*>& operator=(const Stencil<unsigned char*> &s) ecl_assert_throw_decl(StandardException)
00182   {
00183     array = s.array;
00184     length = s.length;
00185     b_iter = s.b_iter;
00186     e_iter = s.e_iter;
00187     return *this;
00188   }
00189 
00190   /*********************
00191    ** Iterators
00192    **********************/
00198   iterator begin() ecl_assert_throw_decl(StandardException)
00199   {
00200     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00201     return b_iter;
00202   }
00208   const_iterator begin() const ecl_assert_throw_decl(StandardException)
00209   {
00210     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00211     return b_iter;
00212   }
00218   iterator end() ecl_assert_throw_decl(StandardException)
00219   {
00220     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00221     return e_iter;
00222   }
00228   const_iterator end() const ecl_assert_throw_decl(StandardException)
00229   {
00230     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00231     return e_iter;
00232   }
00238   reverse_iterator rbegin() ecl_assert_throw_decl(StandardException)
00239   {
00240     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00241     return reverse_iterator(end());
00242   }
00248   const_reverse_iterator rbegin() const ecl_assert_throw_decl(StandardException)
00249   {
00250     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00251     return const_reverse_iterator(end());
00252   }
00258   reverse_iterator rend() ecl_assert_throw_decl(StandardException)
00259   {
00260     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00261     return reverse_iterator(begin());
00262   }
00268   const_reverse_iterator rend() const ecl_assert_throw_decl(StandardException)
00269   {
00270     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00271     return const_reverse_iterator(begin());
00272   }
00273 
00274   /*********************
00275    ** Front/Back
00276    **********************/
00282   reference front() ecl_assert_throw_decl(StandardException)
00283   {
00284     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00285     return *b_iter;
00286   }
00292   const_reference front() const ecl_assert_throw_decl(StandardException)
00293   {
00294     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00295     return *b_iter;
00296   }
00302   reference back() ecl_assert_throw_decl(StandardException)
00303   {
00304     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00305     return *(e_iter-1);
00306   }
00312   const_reference back() const ecl_assert_throw_decl(StandardException)
00313   {
00314     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00315     return *(e_iter-1);
00316   }
00317 
00318   /*********************
00319    ** Accessors
00320    **********************/
00330   reference operator[](size_type i) ecl_assert_throw_decl(StandardException)
00331   {
00332     ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
00333     ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
00334     return *(b_iter+i);
00335   }
00347   const_reference operator[](size_type i) const ecl_assert_throw_decl(StandardException)
00348   {
00349     ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
00350     ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
00351     return *(b_iter+i);
00352   }
00363   reference at(size_type i) throw(StandardException)
00364   {
00365     if ( b_iter+i <= array )
00366     {
00367       throw StandardException(LOC,OutOfRangeError);
00368     }
00369     if ( b_iter+i >= array+length )
00370     {
00371       throw StandardException(LOC,OutOfRangeError);
00372     }
00373     return *(b_iter+i);
00374   }
00387   const_reference at(size_type i) const throw(StandardException)
00388   {
00389     if ( b_iter+i <= array )
00390     {
00391       throw StandardException(LOC,OutOfRangeError);
00392     }
00393     if ( b_iter+i >= array+length )
00394     {
00395       throw StandardException(LOC,OutOfRangeError);
00396     }
00397     return *(b_iter+i);
00398   }
00399 
00400   /*********************
00401    ** Utilities
00402    **********************/
00408   size_type size() const
00409   { return e_iter-b_iter;}
00410 
00411   /*********************
00412    ** Streaming
00413    **********************/
00429   template <typename OutputStream>
00430   friend OutputStream& operator<<(OutputStream &ostream , const Stencil<unsigned char*> &stencil);
00431 
00432 private:
00433   iterator array;
00434   unsigned int length;
00435   iterator b_iter, e_iter;
00436 };
00437 
00438 /*****************************************************************************
00439  ** Const Specialisations
00440  *****************************************************************************/
00441 
00452 template <>
00453 class ECL_PUBLIC Stencil<const unsigned char*>
00454 {
00455 public:
00456   /*********************
00457    ** Typedefs
00458    **********************/
00459   typedef unsigned char value_type; 
00460   typedef const unsigned char* iterator; 
00461   typedef const unsigned char* const_iterator; 
00462   typedef const unsigned char& reference; 
00463   typedef const unsigned char& const_reference; 
00464   typedef std::size_t size_type; 
00465   typedef std::ptrdiff_t difference_type;
00466   typedef std::reverse_iterator<iterator> reverse_iterator; 
00467   typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 
00468   //typedef formatters::StencilFormatter<value_type,Array> Formatter;
00469 
00470   /*********************
00471    ** C&D's
00472    **********************/
00486   Stencil(const_iterator underlying_array, const unsigned int& length, const_iterator begin_iter, const_iterator end_iter) ecl_assert_throw_decl(StandardException) :
00487   array(underlying_array),
00488   length(length),
00489   b_iter(begin_iter),
00490   e_iter(end_iter)
00491   {
00492     ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
00493     ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
00494   }
00495 
00509   Stencil(const_iterator underlying_array, const unsigned int& length, const unsigned int& start_index = 0, const unsigned int &n = 0) ecl_assert_throw_decl(StandardException) :
00510   array(underlying_array),
00511   length(length),
00512   b_iter(array+start_index),
00513   e_iter(array+start_index+n)
00514   {
00515     ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
00516     ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
00517   }
00518 
00519   virtual ~Stencil()
00520   {};
00521 
00534   Stencil<const unsigned char*> stencil(const unsigned int& start_index, const unsigned int& n) const ecl_assert_throw_decl(StandardException)
00535   {
00536     ecl_assert_throw( b_iter+start_index <= array+length, StandardException(LOC, OutOfRangeError, "Start index provided is larger than the underlying stencil size."));
00537     ecl_assert_throw( b_iter+start_index+n <= array+length, StandardException(LOC, OutOfRangeError, "Finish index provided is larger than the underlying stencil size."));
00538     // cant do out of range errors here (no idea how long the underlying array is!)
00539     return Stencil<const unsigned char*>(array,length,b_iter+start_index,b_iter+start_index+n);
00540   }
00541 
00553   void resettle(const unsigned int& start_index, const unsigned int& n) ecl_assert_throw_decl(StandardException)
00554   {
00555 
00556     b_iter = array+start_index;
00557     e_iter = array+start_index+n;
00558     ecl_assert_throw((b_iter <= array + length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
00559     ecl_assert_throw((e_iter <= array + length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
00560   }
00574   Stencil<const unsigned char*>& operator=(const Stencil<const unsigned char*> &s) ecl_assert_throw_decl(StandardException)
00575   {
00576     array = s.array;
00577     length = s.length;
00578     b_iter = s.b_iter;
00579     e_iter = s.e_iter;
00580     return *this;
00581   }
00582 
00583   /*********************
00584    ** Iterators
00585    **********************/
00591   iterator begin() ecl_assert_throw_decl(StandardException)
00592   {
00593     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00594     return b_iter;
00595   }
00601   const_iterator begin() const ecl_assert_throw_decl(StandardException)
00602   {
00603     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00604     return b_iter;
00605   }
00611   iterator end() ecl_assert_throw_decl(StandardException)
00612   {
00613     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00614     return e_iter;
00615   }
00621   const_iterator end() const ecl_assert_throw_decl(StandardException)
00622   {
00623     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00624     return e_iter;
00625   }
00631   reverse_iterator rbegin() ecl_assert_throw_decl(StandardException)
00632   {
00633     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00634     return reverse_iterator(end());
00635   }
00641   const_reverse_iterator rbegin() const ecl_assert_throw_decl(StandardException)
00642   {
00643     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00644     return const_reverse_iterator(end());
00645   }
00651   reverse_iterator rend() ecl_assert_throw_decl(StandardException)
00652   {
00653     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00654     return reverse_iterator(begin());
00655   }
00661   const_reverse_iterator rend() const ecl_assert_throw_decl(StandardException)
00662   {
00663     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00664     return const_reverse_iterator(begin());
00665   }
00666 
00667   /*********************
00668    ** Front/Back
00669    **********************/
00675   reference front() ecl_assert_throw_decl(StandardException)
00676   {
00677     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00678     return *b_iter;
00679   }
00685   const_reference front() const ecl_assert_throw_decl(StandardException)
00686   {
00687     ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
00688     return *b_iter;
00689   }
00695   reference back() ecl_assert_throw_decl(StandardException)
00696   {
00697     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00698     return *(e_iter-1);
00699   }
00705   const_reference back() const ecl_assert_throw_decl(StandardException)
00706   {
00707     ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
00708     return *(e_iter-1);
00709   }
00710 
00711   /*********************
00712    ** Accessors
00713    **********************/
00723   reference operator[](size_type i) ecl_assert_throw_decl(StandardException)
00724   {
00725     ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
00726     ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
00727     return *(b_iter+i);
00728   }
00740   const_reference operator[](size_type i) const ecl_assert_throw_decl(StandardException)
00741   {
00742     ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
00743     ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
00744     return *(b_iter+i);
00745   }
00756   reference at(size_type i) throw(StandardException)
00757   {
00758     if ( b_iter+i <= array )
00759     {
00760       throw StandardException(LOC,OutOfRangeError);
00761     }
00762     if ( b_iter+i >= array+length )
00763     {
00764       throw StandardException(LOC,OutOfRangeError);
00765     }
00766     return *(b_iter+i);
00767   }
00780   const_reference at(size_type i) const throw(StandardException)
00781   {
00782     if ( b_iter+i <= array )
00783     {
00784       throw StandardException(LOC,OutOfRangeError);
00785     }
00786     if ( b_iter+i >= array+length )
00787     {
00788       throw StandardException(LOC,OutOfRangeError);
00789     }
00790     return *(b_iter+i);
00791   }
00792 
00793   /*********************
00794    ** Utilities
00795    **********************/
00801   size_type size() const
00802   { return e_iter-b_iter;}
00803 
00804   /*********************
00805    ** Streaming
00806    **********************/
00822   template <typename OutputStream>
00823   friend OutputStream& operator<<(OutputStream &ostream , const Stencil<const unsigned char*> &stencil);
00824 
00825 private:
00826   const_iterator array;
00827   unsigned int length;
00828   const_iterator b_iter, e_iter;
00829 };
00830 
00831 } // namespace ecl
00832 
00833 #endif /* ecl_containers_SPECIALISATIONS_HPP_ */


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