37 #if !defined(LIBCOYOTL_ARRAY_H) 38 #define LIBCOYOTL_ARRAY_H 42 #pragma warning(disable : 4290 4101) // "exception specification ignored", "unused var" 48 #include "validator.h" 51 #if defined(LIBCOYOTL_BOUNDS_CHECKING) 54 #define LIBCOYOTL_ARRAY_EXCEPTIONS validation_error<size_t> 55 #define LIBCOYOTL_ARRAY_CHECK_INDEX(n) validate_less(n,m_size,LIBCOYOTL_LOCATION); 57 #define LIBCOYOTL_ARRAY_EXCEPTIONS 58 #define LIBCOYOTL_ARRAY_CHECK_INDEX(n) 71 template <
typename Type>
113 array(
size_t a_length);
122 array(
size_t a_length,
const Type & a_init_value);
138 array(
size_t a_length,
const Type * a_carray);
155 array & operator = (const
array<Type> & a_source) throw();
163 array & operator = (const Type & a_value) throw();
171 array & operator = (const Type * a_carray) throw();
180 const Type *
c_array() const throw();
188 Type & operator [] (
size_t n) throw(LIBCOYOTL_ARRAY_EXCEPTIONS);
196 Type operator [] (
size_t n) const throw(LIBCOYOTL_ARRAY_EXCEPTIONS);
211 iterator
begin() throw();
218 const_iterator
begin() const throw();
225 iterator
end() throw();
232 const_iterator
end() const throw();
239 iterator
rbegin() throw();
246 const_iterator
rbegin() const throw();
253 iterator
rend() throw();
260 const_iterator
rend() const throw();
269 bool operator == (const
array<Type> & a_comparand) const throw();
278 bool operator != (const
array<Type> & a_comparand) const throw();
287 bool operator < (const
array<Type> & a_comparand) const throw();
296 bool operator <= (const
array<Type> & a_comparand) const throw();
305 bool operator > (const
array<Type> & a_comparand) const throw();
314 bool operator >= (const
array<Type> & a_comparand) const throw();
322 void swap(
array<Type> & a_source) throw();
330 size_t size() const throw();
346 bool empty() const throw();
357 void assign_value(const Type & a_value) throw();
360 void copy_carray(const Type * a_carray) throw();
363 void copy_array(const
array<Type> & a_source) throw();
367 template <typename Type>
368 void array<Type>::assign_value(const Type & a_value) throw()
372 for (
size_t n = 0; n <
m_size; ++n)
374 *element_ptr = a_value;
380 template <
typename Type>
385 const Type * carray_ptr = a_carray;
387 for (
size_t n = 0; n <
m_size; ++n)
389 *target_ptr = *carray_ptr;
396 template <
typename Type>
404 const Type * source_ptr = a_source.
m_array;
406 for (
size_t n = 0; n < copy_length; ++n)
408 *target_ptr = *source_ptr;
415 template <
typename Type>
421 enforce_lower_limit(
m_size,
size_t(1));
428 template <
typename Type>
434 enforce_lower_limit(
m_size,
size_t(1));
440 assign_value(a_init_value);
444 template <
typename Type>
453 copy_array(a_source);
457 template <
typename Type>
463 validate_not(a_carray,(
const Type *)NULL,LIBCOYOTL_LOCATION);
466 enforce_lower_limit(
m_size,
size_t(1));
472 copy_carray(a_carray);
476 template <
typename Type>
486 template <
typename Type>
489 copy_array(a_source);
494 template <
typename Type>
497 assign_value(a_value);
502 template <
typename Type>
505 copy_carray(a_source);
510 template <
typename Type>
517 template <
typename Type>
520 LIBCOYOTL_ARRAY_CHECK_INDEX(n)
524 template <
typename Type>
527 LIBCOYOTL_ARRAY_CHECK_INDEX(n)
532 template <
typename Type>
536 Type * new_array =
new Type[new_size];
538 Type * target = new_array;
543 for (n = 0; n <
m_size; ++n)
553 for (n = 0; n < other.
m_size; ++n)
567 template <
typename Type>
573 template <
typename Type>
579 template <
typename Type>
585 template <
typename Type>
591 template <
typename Type>
597 template <
typename Type>
603 template <
typename Type>
609 template <
typename Type>
616 template <
typename Type>
619 return equal(
begin(),
end(),a_array.begin());
622 template <
typename Type>
625 return !(*
this == a_array);
628 template <
typename Type>
631 return lexicographical_compare(
begin(),
end(),a_array.begin(),a_array.end());
634 template <
typename Type>
637 return (a_array < *
this);
640 template <
typename Type>
643 return !(*
this > a_array);
646 template <
typename Type>
649 return !(*
this < a_array);
653 template <
typename Type>
657 validate_equals(
m_size,a_source.
m_size,LIBCOYOTL_LOCATION);
661 Type * source_ptr = a_source.
m_array;
663 for (
size_t n = 0; n <
m_size; ++n)
665 Type temp = *target_ptr;
666 *target_ptr = *source_ptr;
675 template <
typename Type>
682 template <
typename Type>
689 template <
typename Type>
bool operator>(const array< Type > &a_comparand) const
Greater-than operator.
Definition: array.h:635
bool operator!=(const array< Type > &a_comparand) const
Inequality operator.
Definition: array.h:623
Type value_type
Type of an array element.
Definition: array.h:76
Type * pointer
type of a pointer to an element
Definition: array.h:79
const Type * c_array() const
Conversion to C-style array.
Definition: array.h:511
size_t max_size() const
Maximum container size.
Definition: array.h:683
iterator begin()
Obtain beginning-of-sequence iterator.
Definition: array.h:568
Type & operator[](size_t n)
Element access.
Definition: array.h:518
bool operator>=(const array< Type > &a_comparand) const
Greater-than-or-equal-to operator.
Definition: array.h:647
bool operator<(const array< Type > &a_comparand) const
Less-than operator.
Definition: array.h:629
iterator rend()
Obtain end-of-sequence reverse iterator.
Definition: array.h:604
const Type * const_reverse_iterator
Constant reverse iterator type.
Definition: array.h:106
Type * iterator
Iterator type.
Definition: array.h:97
size_t m_size
Length of the array.
Definition: array.h:353
iterator rbegin()
Obtain beginning-of-sequence reverse iterator.
Definition: array.h:592
void append(const array< Type > &a_array)
Appending arrays.
Definition: array.h:533
bool operator==(const array< Type > &a_comparand) const
Equals operator.
Definition: array.h:617
bool operator<=(const array< Type > &a_comparand) const
Less-than-or-equal-to operator.
Definition: array.h:641
Type * m_array
Underlying allocated array.
Definition: array.h:350
size_t size_type
Size type for indexing array elements.
Definition: array.h:94
virtual ~array()
Virtual destructor.
Definition: array.h:477
ptrdiff_t difference_type
Difference type between two element pointers.
Definition: array.h:91
iterator end()
Obtain end-of-sequence iterator.
Definition: array.h:580
const Type * const_pointer
Type of a constant pointer to an element.
Definition: array.h:82
Type * reverse_iterator
Reverse iterator type.
Definition: array.h:103
array(size_t a_length)
Default constructor.
Definition: array.h:416
const Type & const_reference
Type of a constant reference to an element.
Definition: array.h:88
Type & reference
Type of a reference to an element.
Definition: array.h:85
void swap(array< Type > &a_source)
Exchanges the corresponding elements of two arrays.
Definition: array.h:654
array & operator=(const array< Type > &a_source)
Assignment operator.
Definition: array.h:487
bool empty() const
Empty container check.
Definition: array.h:690
const Type * const_iterator
Constant iterator type.
Definition: array.h:100
A STL-compatible array class.
Definition: array.h:72
size_t size() const
Number of elements.
Definition: array.h:676