Commit fb266ade authored by Davis King's avatar Davis King

Turned the array into a single implementation object. Now arrays can be

created using the normal array<type> obj; syntax.  Additionally, all extensions
were put into the array object directly and the implementation is the
flat single array implementation.
parent 98d63d48
......@@ -3,103 +3,7 @@
#ifndef DLIB_ARRAy_
#define DLIB_ARRAy_
#include "array/array_kernel_1.h"
#include "array/array_kernel_2.h"
#include "array/array_kernel_c.h"
#include "array/array_sort_1.h"
#include "array/array_sort_2.h"
#include "array/array_expand_1.h"
#include "array/array_expand_c.h"
#include "algs.h"
namespace dlib
{
template <
typename T,
typename mem_manager = default_memory_manager
>
class array
{
array() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef array_kernel_1<T,mem_manager>
kernel_1a;
typedef array_kernel_c<kernel_1a >
kernel_1a_c;
// kernel_2a
typedef array_kernel_2<T,mem_manager>
kernel_2a;
typedef array_kernel_c<kernel_2a >
kernel_2a_c;
//---------- extensions ------------
// sort_1 extend kernel_1a
typedef array_sort_1<kernel_1a>
sort_1a;
typedef array_sort_1<kernel_1a_c>
sort_1a_c;
// sort_1 extend kernel_2a
typedef array_sort_1<kernel_2a>
sort_1b;
typedef array_sort_1<kernel_2a_c>
sort_1b_c;
// sort_2 extend kernel_1a
typedef array_sort_2<kernel_1a>
sort_2a;
typedef array_sort_2<kernel_1a_c>
sort_2a_c;
// sort_2 extend kernel_2a
typedef array_sort_2<kernel_2a>
sort_2b;
typedef array_sort_2<kernel_2a_c>
sort_2b_c;
// expand_1 extend sort_1a
typedef array_expand_1<sort_1a>
expand_1a;
typedef array_expand_c<array_kernel_c<expand_1a> >
expand_1a_c;
// expand_1 extend sort_1b
typedef array_expand_1<sort_1b>
expand_1b;
typedef array_expand_c<array_kernel_c<expand_1b> >
expand_1b_c;
// expand_1 extend sort_2a
typedef array_expand_1<sort_2a>
expand_1c;
typedef array_expand_c<array_kernel_c<expand_1c> >
expand_1c_c;
// expand_1 extend sort_2b
typedef array_expand_1<sort_2b>
expand_1d;
typedef array_expand_c<array_kernel_c<expand_1d> >
expand_1d_c;
};
}
#endif // DLIB_ARRAy_
This diff is collapsed.
......@@ -28,8 +28,8 @@ namespace dlib
mem_manager::type can be set to anything.
POINTERS AND REFERENCES TO INTERNAL DATA
swap(), max_size(), set_size(), and operator[] functions do
not invalidate pointers or references to internal data.
front(), back(), swap(), max_size(), set_size(), and operator[]
functions do not invalidate pointers or references to internal data.
All other functions have no such guarantee.
INITIAL VALUE
......@@ -66,7 +66,7 @@ namespace dlib
- std::bad_alloc or any exception thrown by T's constructor
!*/
virtual ~array (
~array (
);
/*!
ensures
......@@ -153,6 +153,96 @@ namespace dlib
- swaps *this and item
!*/
void sort (
);
/*!
requires
- T must be a type with that is comparable via operator<
ensures
- for all elements in #*this the ith element is <= the i+1 element
- #at_start() == true
throws
- std::bad_alloc or any exception thrown by T's constructor
data may be lost if sort() throws
!*/
void resize (
unsigned long new_size
);
/*!
ensures
- #size() == new_size
- #max_size() == max(new_size,max_size())
- for all i < size() && i < new_size:
- #(*this)[i] == (*this)[i]
(i.e. All the original elements of *this which were at index
values less than new_size are unmodified.)
- for all valid i >= size():
- #(*this)[i] has an undefined value
(i.e. any new elements of the array have an undefined value)
throws
- std::bad_alloc or any exception thrown by T's constructor.
If an exception is thrown then it has no effect on *this.
!*/
const T& back (
) const;
/*!
requires
- size() != 0
ensures
- returns a const reference to (*this)[size()-1]
!*/
T& back (
);
/*!
requires
- size() != 0
ensures
- returns a non-const reference to (*this)[size()-1]
!*/
void pop_back (
T& item
);
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- swaps (*this)[size()-1] into item
- All elements with an index less than size()-1 are
unmodified by this operation.
!*/
void pop_back (
);
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- All elements with an index less than size()-1 are
unmodified by this operation.
!*/
void push_back (
T& item
);
/*!
ensures
- #size() == size()+1
- swaps item into (*this)[#size()-1]
- #back() == item
- #item has some undefined value (whatever happens to
get swapped out of the array)
throws
- std::bad_alloc or any exception thrown by T's constructor.
If an exception is thrown then it has no effect on *this.
!*/
private:
// restricted functions
......
......@@ -590,7 +590,22 @@ namespace
DLIB_TEST(a1.size() == 0);
}
}
struct stuff
{
int whatever;
};
void another_array_test()
{
array<stuff> a;
a.resize(5);
a[0].whatever = 0;
stuff temp;
temp.whatever = 99;
a.push_back(temp);
DLIB_TEST(a.size() == 6);
DLIB_TEST(a[5].whatever == 99);
}
......@@ -606,41 +621,12 @@ namespace
void perform_test (
)
{
// test a checking version first for good measure
dlog << LINFO << "testing expand_1a_c";
print_spinner();
array_expand_test<array<unsigned long>::expand_1a_c>();
dlog << LINFO << "testing expand_1a";
print_spinner();
array_expand_test<array<unsigned long>::expand_1a>();
dlog << LINFO << "testing expand_1b";
print_spinner();
array_expand_test<array<unsigned long>::expand_1b>();
dlog << LINFO << "testing expand_1b_c";
print_spinner();
array_expand_test<array<unsigned long>::expand_1b_c>();
dlog << LINFO << "testing expand_1c";
print_spinner();
array_expand_test<array<unsigned long>::expand_1c>();
dlog << LINFO << "testing expand_1c_c";
print_spinner();
array_expand_test<array<unsigned long>::expand_1c_c>();
dlog << LINFO << "testing expand_1d";
print_spinner();
array_expand_test<array<unsigned long>::expand_1d>();
dlog << LINFO << "testing expand_1d_c";
print_spinner();
array_expand_test<array<unsigned long>::expand_1d_c>();
another_array_test();
// test a checking version first for good measure
print_spinner();
array_expand_test<array<unsigned long> >();
}
} a;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment