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);
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>
397 void array<Type>::copy_array(
const array<Type> & a_source)
throw()
400 size_t copy_length = min_of(
m_size,a_source.m_size);
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>
447 m_size(a_source.m_size)
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>
535 size_t new_size = m_size + other.
m_size;
536 Type * new_array =
new Type[new_size];
538 Type * target = new_array;
539 Type * a_source = m_array;
543 for (n = 0; n < m_size; ++n)
553 for (n = 0; n < other.
m_size; ++n)
567 template <
typename Type>
570 return &(m_array[0]);
573 template <
typename Type>
576 return &(m_array[0]);
579 template <
typename Type>
582 return &(m_array[m_size]);
585 template <
typename Type>
588 return &(m_array[m_size]);
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);
660 Type * target_ptr = m_array;
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>