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) ecl_assert_throw_decl(StandardException) :
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) ecl_assert_throw_decl(StandardException) :
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 ecl_assert_throw_decl(StandardException)
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) ecl_assert_throw_decl(StandardException)
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) ecl_assert_throw_decl(StandardException)
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() ecl_assert_throw_decl(StandardException)
199  {
200  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
201  return b_iter;
202  }
208  const_iterator begin() const ecl_assert_throw_decl(StandardException)
209  {
210  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
211  return b_iter;
212  }
218  iterator end() ecl_assert_throw_decl(StandardException)
219  {
220  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
221  return e_iter;
222  }
228  const_iterator end() const ecl_assert_throw_decl(StandardException)
229  {
230  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
231  return e_iter;
232  }
238  reverse_iterator rbegin() ecl_assert_throw_decl(StandardException)
239  {
240  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
241  return reverse_iterator(end());
242  }
248  const_reverse_iterator rbegin() const ecl_assert_throw_decl(StandardException)
249  {
250  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
251  return const_reverse_iterator(end());
252  }
258  reverse_iterator rend() ecl_assert_throw_decl(StandardException)
259  {
260  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
261  return reverse_iterator(begin());
262  }
268  const_reverse_iterator rend() const ecl_assert_throw_decl(StandardException)
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() ecl_assert_throw_decl(StandardException)
283  {
284  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
285  return *b_iter;
286  }
292  const_reference front() const ecl_assert_throw_decl(StandardException)
293  {
294  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
295  return *b_iter;
296  }
302  reference back() ecl_assert_throw_decl(StandardException)
303  {
304  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
305  return *(e_iter-1);
306  }
312  const_reference back() const ecl_assert_throw_decl(StandardException)
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) ecl_assert_throw_decl(StandardException)
331  {
332  ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
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 ecl_assert_throw_decl(StandardException)
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) throw(StandardException)
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 throw(StandardException)
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) ecl_assert_throw_decl(StandardException) :
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) ecl_assert_throw_decl(StandardException) :
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 ecl_assert_throw_decl(StandardException)
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) ecl_assert_throw_decl(StandardException)
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) ecl_assert_throw_decl(StandardException)
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() ecl_assert_throw_decl(StandardException)
592  {
593  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
594  return b_iter;
595  }
601  const_iterator begin() const ecl_assert_throw_decl(StandardException)
602  {
603  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
604  return b_iter;
605  }
611  iterator end() ecl_assert_throw_decl(StandardException)
612  {
613  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
614  return e_iter;
615  }
621  const_iterator end() const ecl_assert_throw_decl(StandardException)
622  {
623  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
624  return e_iter;
625  }
631  reverse_iterator rbegin() ecl_assert_throw_decl(StandardException)
632  {
633  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
634  return reverse_iterator(end());
635  }
641  const_reverse_iterator rbegin() const ecl_assert_throw_decl(StandardException)
642  {
643  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
644  return const_reverse_iterator(end());
645  }
651  reverse_iterator rend() ecl_assert_throw_decl(StandardException)
652  {
653  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
654  return reverse_iterator(begin());
655  }
661  const_reverse_iterator rend() const ecl_assert_throw_decl(StandardException)
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() ecl_assert_throw_decl(StandardException)
676  {
677  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
678  return *b_iter;
679  }
685  const_reference front() const ecl_assert_throw_decl(StandardException)
686  {
687  ecl_assert_throw( b_iter <= array+length, StandardException(LOC,OutOfRangeError));
688  return *b_iter;
689  }
695  reference back() ecl_assert_throw_decl(StandardException)
696  {
697  ecl_assert_throw( e_iter <= array+length, StandardException(LOC,OutOfRangeError));
698  return *(e_iter-1);
699  }
705  const_reference back() const ecl_assert_throw_decl(StandardException)
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) ecl_assert_throw_decl(StandardException)
724  {
725  ecl_assert_throw( b_iter+i >= array, StandardException(LOC,OutOfRangeError));
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 ecl_assert_throw_decl(StandardException)
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) throw(StandardException)
757  {
758  if ( b_iter+i <= array )
759  {
760  throw StandardException(LOC,OutOfRangeError);
761  }
762  if ( b_iter+i >= array+length )
763  {
764  throw StandardException(LOC,OutOfRangeError);
765  }
766  return *(b_iter+i);
767  }
780  const_reference at(size_type i) const throw(StandardException)
781  {
782  if ( b_iter+i <= array )
783  {
784  throw StandardException(LOC,OutOfRangeError);
785  }
786  if ( b_iter+i >= array+length )
787  {
788  throw StandardException(LOC,OutOfRangeError);
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_ */
XmlRpcServer s
#define LOC
Stringify the line of code you are at.
OutputStream & operator<<(OutputStream &ostream, const Void void_object)
Output stream operator for Void objects.
Definition: void.hpp:76
#define ecl_assert_throw(expression, exception)
Debug mode throw with a logical condition check.
OutOfRangeError
array
ecl_geometry_PUBLIC int size(const Trajectory2D &trajectory)
#define ECL_PUBLIC
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
Windows over ecl type containers.
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13