specialisations.hpp
Go to the documentation of this file.
1 
6 /*****************************************************************************
7 ** Ifdefs
8 *****************************************************************************/
9 
10 #ifndef ecl_containers_SPECIALISATIONS_HPP_
11 #define ecl_containers_SPECIALISATIONS_HPP_
12 
13 /*****************************************************************************
14 ** Includes
15 *****************************************************************************/
16 
17 #include "stencil.hpp"
18 
19 /*****************************************************************************
20 ** Namespaces
21 *****************************************************************************/
22 
23 namespace ecl {
24 
25 /*****************************************************************************
26  ** Interface
27  *****************************************************************************/
38 template <>
39 class ECL_PUBLIC Stencil<unsigned char*>
40 {
41 public:
42  /*********************
43  ** Typedefs
44  **********************/
45  typedef unsigned char value_type;
46  typedef unsigned char* iterator;
47  typedef const unsigned char* const_iterator;
48  typedef unsigned char& reference;
49  typedef const unsigned char& const_reference;
50  typedef std::size_t size_type;
51  typedef std::ptrdiff_t difference_type;
52  typedef std::reverse_iterator<iterator> reverse_iterator;
53  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
54  //typedef formatters::StencilFormatter<value_type,Array> Formatter;
55 
56  /*********************
57  ** C&D's
58  **********************/
72  Stencil(iterator underlying_array, const unsigned int& length, iterator begin_iter, iterator end_iter) :
73  array(underlying_array),
74  length(length),
75  b_iter(begin_iter),
76  e_iter(end_iter)
77  {
78  ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
79  ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
80  }
81 
95  Stencil(iterator underlying_array, const unsigned int& length, const unsigned int& start_index = 0, const unsigned int &n = 0) :
96  array(underlying_array),
97  length(length),
98  b_iter(array+start_index),
99  e_iter(array+start_index+n)
100  {
101  ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
102  ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
103  }
104 
105  virtual ~Stencil()
106  {};
107 
120  Stencil<unsigned char*> stencil(const unsigned int& start_index, const unsigned int& n) const
121  {
122  ecl_assert_throw( b_iter+start_index <= array+length, StandardException(LOC, OutOfRangeError, "Start index provided is larger than the underlying stencil size."));
123  ecl_assert_throw( b_iter+start_index+n <= array+length, StandardException(LOC, OutOfRangeError, "Finish index provided is larger than the underlying stencil size."));
124  // cant do out of range errors here (no idea how long the underlying array is!)
125  return Stencil<unsigned char*>(array,length,b_iter+start_index,b_iter+start_index+n);
126  }
127 
139  void resettle(const unsigned int& start_index, const unsigned int& n)
140  {
141 
142  b_iter = array+start_index;
143  e_iter = array+start_index+n;
144  ecl_assert_throw((b_iter <= array + length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
145  ecl_assert_throw((e_iter <= array + length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
146  }
147 
148  /*********************
149  ** Assignment
150  **********************/
164  containers::BoundedListInitialiser<value_type,iterator> operator<< (const value_type &value)
165  {
166  return containers::BoundedListInitialiser<value_type,iterator>(value, begin(), size());
167  }
181  Stencil<unsigned char*>& operator=(const Stencil<unsigned char*> &s)
182  {
183  array = s.array;
184  length = s.length;
185  b_iter = s.b_iter;
186  e_iter = s.e_iter;
187  return *this;
188  }
189 
190  /*********************
191  ** Iterators
192  **********************/
198  iterator begin()
199  {
200  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
201  return b_iter;
202  }
208  const_iterator begin() const
209  {
210  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
211  return b_iter;
212  }
218  iterator end()
219  {
220  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
221  return e_iter;
222  }
228  const_iterator end() const
229  {
230  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
231  return e_iter;
232  }
238  reverse_iterator rbegin()
239  {
240  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
241  return reverse_iterator(end());
242  }
248  const_reverse_iterator rbegin() const
249  {
250  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
251  return const_reverse_iterator(end());
252  }
258  reverse_iterator rend()
259  {
260  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
261  return reverse_iterator(begin());
262  }
268  const_reverse_iterator rend() const
269  {
270  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
271  return const_reverse_iterator(begin());
272  }
273 
274  /*********************
275  ** Front/Back
276  **********************/
282  reference front()
283  {
284  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
285  return *b_iter;
286  }
292  const_reference front() const
293  {
294  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
295  return *b_iter;
296  }
302  reference back()
303  {
304  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
305  return *(e_iter-1);
306  }
312  const_reference back() const
313  {
314  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
315  return *(e_iter-1);
316  }
317 
318  /*********************
319  ** Accessors
320  **********************/
330  reference operator[](size_type i)
331  {
333  ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
334  return *(b_iter+i);
335  }
347  const_reference operator[](size_type i) const
348  {
349  ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
350  ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
351  return *(b_iter+i);
352  }
363  reference at(size_type i)
364  {
365  if ( b_iter+i <= array )
366  {
367  throw StandardException(LOC,OutOfRangeError);
368  }
369  if ( b_iter+i >= array+length )
370  {
371  throw StandardException(LOC,OutOfRangeError);
372  }
373  return *(b_iter+i);
374  }
387  const_reference at(size_type i) const
388  {
389  if ( b_iter+i <= array )
390  {
391  throw StandardException(LOC,OutOfRangeError);
392  }
393  if ( b_iter+i >= array+length )
394  {
395  throw StandardException(LOC,OutOfRangeError);
396  }
397  return *(b_iter+i);
398  }
399 
400  /*********************
401  ** Utilities
402  **********************/
408  size_type size() const
409  { return e_iter-b_iter;}
410 
411  /*********************
412  ** Streaming
413  **********************/
429  template <typename OutputStream>
430  friend OutputStream& operator<<(OutputStream &ostream , const Stencil<unsigned char*> &stencil);
431 
432 private:
433  iterator array;
434  unsigned int length;
435  iterator b_iter, e_iter;
436 };
437 
438 /*****************************************************************************
439  ** Const Specialisations
440  *****************************************************************************/
441 
452 template <>
453 class ECL_PUBLIC Stencil<const unsigned char*>
454 {
455 public:
456  /*********************
457  ** Typedefs
458  **********************/
459  typedef unsigned char value_type;
460  typedef const unsigned char* iterator;
461  typedef const unsigned char* const_iterator;
462  typedef const unsigned char& reference;
463  typedef const unsigned char& const_reference;
464  typedef std::size_t size_type;
465  typedef std::ptrdiff_t difference_type;
466  typedef std::reverse_iterator<iterator> reverse_iterator;
467  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
468  //typedef formatters::StencilFormatter<value_type,Array> Formatter;
469 
470  /*********************
471  ** C&D's
472  **********************/
486  Stencil(const_iterator underlying_array, const unsigned int& length, const_iterator begin_iter, const_iterator end_iter) :
487  array(underlying_array),
488  length(length),
489  b_iter(begin_iter),
490  e_iter(end_iter)
491  {
492  ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
493  ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
494  }
495 
509  Stencil(const_iterator underlying_array, const unsigned int& length, const unsigned int& start_index = 0, const unsigned int &n = 0) :
510  array(underlying_array),
511  length(length),
512  b_iter(array+start_index),
513  e_iter(array+start_index+n)
514  {
515  ecl_assert_throw((b_iter <= array+length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
516  ecl_assert_throw((e_iter <= array+length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
517  }
518 
519  virtual ~Stencil()
520  {};
521 
534  Stencil<const unsigned char*> stencil(const unsigned int& start_index, const unsigned int& n) const
535  {
536  ecl_assert_throw( b_iter+start_index <= array+length, StandardException(LOC, OutOfRangeError, "Start index provided is larger than the underlying stencil size."));
537  ecl_assert_throw( b_iter+start_index+n <= array+length, StandardException(LOC, OutOfRangeError, "Finish index provided is larger than the underlying stencil size."));
538  // cant do out of range errors here (no idea how long the underlying array is!)
539  return Stencil<const unsigned char*>(array,length,b_iter+start_index,b_iter+start_index+n);
540  }
541 
553  void resettle(const unsigned int& start_index, const unsigned int& n)
554  {
555 
556  b_iter = array+start_index;
557  e_iter = array+start_index+n;
558  ecl_assert_throw((b_iter <= array + length), StandardException(LOC, OutOfRangeError, "Begin iterator out of range."));
559  ecl_assert_throw((e_iter <= array + length), StandardException(LOC, OutOfRangeError, "End iterator out of range."));
560  }
574  Stencil<const unsigned char*>& operator=(const Stencil<const unsigned char*> &s)
575  {
576  array = s.array;
577  length = s.length;
578  b_iter = s.b_iter;
579  e_iter = s.e_iter;
580  return *this;
581  }
582 
583  /*********************
584  ** Iterators
585  **********************/
591  iterator begin()
592  {
593  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
594  return b_iter;
595  }
601  const_iterator begin() const
602  {
603  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
604  return b_iter;
605  }
611  iterator end()
612  {
613  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
614  return e_iter;
615  }
621  const_iterator end() const
622  {
623  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
624  return e_iter;
625  }
631  reverse_iterator rbegin()
632  {
633  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
634  return reverse_iterator(end());
635  }
641  const_reverse_iterator rbegin() const
642  {
643  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
644  return const_reverse_iterator(end());
645  }
651  reverse_iterator rend()
652  {
653  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
654  return reverse_iterator(begin());
655  }
661  const_reverse_iterator rend() const
662  {
663  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
664  return const_reverse_iterator(begin());
665  }
666 
667  /*********************
668  ** Front/Back
669  **********************/
675  reference front()
676  {
677  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
678  return *b_iter;
679  }
685  const_reference front() const
686  {
687  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
688  return *b_iter;
689  }
695  reference back()
696  {
697  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
698  return *(e_iter-1);
699  }
705  const_reference back() const
706  {
707  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
708  return *(e_iter-1);
709  }
710 
711  /*********************
712  ** Accessors
713  **********************/
723  reference operator[](size_type i)
724  {
726  ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
727  return *(b_iter+i);
728  }
740  const_reference operator[](size_type i) const
741  {
742  ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
743  ecl_assert_throw( b_iter+i <= array+length, StandardException(LOC,OutOfRangeError));
744  return *(b_iter+i);
745  }
756  reference at(size_type i)
757  {
758  if ( b_iter+i <= array )
759  {
760  throw StandardException(LOC,OutOfRangeError);
761  }
762  if ( b_iter+i >= array+length )
763  {
765  }
766  return *(b_iter+i);
767  }
780  const_reference at(size_type i) const
781  {
782  if ( b_iter+i <= array )
783  {
784  throw StandardException(LOC,OutOfRangeError);
785  }
786  if ( b_iter+i >= array+length )
787  {
789  }
790  return *(b_iter+i);
791  }
792 
793  /*********************
794  ** Utilities
795  **********************/
801  size_type size() const
802  { return e_iter-b_iter;}
803 
804  /*********************
805  ** Streaming
806  **********************/
822  template <typename OutputStream>
823  friend OutputStream& operator<<(OutputStream &ostream , const Stencil<const unsigned char*> &stencil);
824 
825 private:
826  const_iterator array;
827  unsigned int length;
828  const_iterator b_iter, e_iter;
829 };
830 
831 } // namespace ecl
832 
833 #endif /* ecl_containers_SPECIALISATIONS_HPP_ */
ecl::Stencil< const unsigned char * >::difference_type
std::ptrdiff_t difference_type
Definition: specialisations.hpp:473
ecl::Stencil< unsigned char * >::iterator
unsigned char * iterator
Uses the array's iterator type.
Definition: specialisations.hpp:60
ecl::Stencil< unsigned char * >
Stencil variant operating on a raw unsigned char array.
Definition: specialisations.hpp:45
ecl::operator<<
OutputStream & operator<<(OutputStream &ostream, Format< std::string > &formatter)
stencil.hpp
Windows over ecl type containers.
ecl::Stencil
A safe windowing class that opens onto array-like containers.
Definition: stencil/formatters.hpp:46
ecl::Stencil< unsigned char * >::reference
unsigned char & reference
Uses the array's element reference type.
Definition: specialisations.hpp:62
LOC
#define LOC
ecl::Stencil< unsigned char * >::size_type
std::size_t size_type
Uses the array's type used to denote the length of the array.
Definition: specialisations.hpp:64
ecl::Stencil< unsigned char * >::value_type
unsigned char value_type
Uses the array's element type.
Definition: specialisations.hpp:59
ecl::Stencil< unsigned char * >::difference_type
std::ptrdiff_t difference_type
Definition: specialisations.hpp:65
ecl::StandardException
ecl_assert_throw
#define ecl_assert_throw(expression, exception)
ecl::Stencil< const unsigned char * >::value_type
unsigned char value_type
Uses the array's element type.
Definition: specialisations.hpp:467
ecl::Stencil< unsigned char * >::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Uses the array's constant reverse iterator type.
Definition: specialisations.hpp:67
ecl::Stencil< const unsigned char * >::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Uses the array's constant reverse iterator type.
Definition: specialisations.hpp:475
ecl::Stencil< unsigned char * >::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Uses the array's reverse iterator type.
Definition: specialisations.hpp:66
ecl::Stencil< const unsigned char * >::size_type
std::size_t size_type
Uses the array's type used to denote the length of the array.
Definition: specialisations.hpp:472
ecl::OutOfRangeError
OutOfRangeError
ecl
Embedded control libraries.
ECL_PUBLIC
#define ECL_PUBLIC
ecl::Stencil< const unsigned char * >::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Uses the array's reverse iterator type.
Definition: specialisations.hpp:474


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