Containers are now deleteable through a pointer to their 'ixxxx' class.

This commit is contained in:
John Wellbelove 2018-01-30 08:47:49 +00:00
parent 0d34769247
commit eb222f54bb
44 changed files with 1059 additions and 543 deletions

View File

@ -622,6 +622,17 @@ namespace etl
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//*************************************************************************
/// Destructor.
//*************************************************************************
~ideque()
{
if (!empty())
{
initialise();
}
}
//*************************************************************************
/// Assigns a range to the deque.
//*************************************************************************

View File

@ -108,6 +108,17 @@ namespace etl
public:
//*************************************************************************
/// Destructor.
//*************************************************************************
~iflat_map()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the flat_map.
///\return An iterator to the beginning of the flat_map.

View File

@ -110,6 +110,17 @@ namespace etl
public:
//*************************************************************************
/// Destructor.
//*************************************************************************
~iflat_multimap()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the flat_multimap.
///\return An iterator to the beginning of the flat_multimap.

View File

@ -86,6 +86,17 @@ namespace etl
public:
//*************************************************************************
/// Destructor.
//*************************************************************************
~iflat_multiset()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the flat_multiset.
///\return An iterator to the beginning of the flat_multiset.

View File

@ -86,6 +86,17 @@ namespace etl
public:
//*************************************************************************
/// Destructor.
//*************************************************************************
~iflat_set()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the flat_set.
///\return An iterator to the beginning of the flat_set.

View File

@ -477,6 +477,17 @@ namespace etl
typedef typename std::iterator_traits<iterator>::difference_type difference_type;
//*************************************************************************
/// Destructor.
//*************************************************************************
~iforward_list()
{
if (!empty())
{
clear();
}
}
//*************************************************************************
/// Gets the beginning of the forward_list.
//*************************************************************************

View File

@ -583,6 +583,17 @@ namespace etl
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//*************************************************************************
/// Destructor.
//*************************************************************************
~ilist()
{
if (!empty())
{
initialise();
}
}
//*************************************************************************
/// Gets the beginning of the list.
//*************************************************************************

View File

@ -801,6 +801,16 @@ namespace etl
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//*************************************************************************
/// Destructor.
//*************************************************************************
~imap()
{
if (!empty())
{
clear();
}
}
//*************************************************************************
/// Gets the beginning of the map.

View File

@ -952,6 +952,16 @@ namespace etl
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//*************************************************************************
/// Destructor.
//*************************************************************************
~imultimap()
{
if (!empty())
{
clear();
}
}
//*************************************************************************
/// Gets the beginning of the multimap.

View File

@ -932,6 +932,16 @@ namespace etl
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//*************************************************************************
/// Destructor.
//*************************************************************************
~imultiset()
{
if (!empty())
{
clear();
}
}
//*************************************************************************
/// Gets the beginning of the multiset.

View File

@ -239,6 +239,17 @@ namespace etl
public:
//*************************************************************************
/// Destructor.
//*************************************************************************
~iqueue()
{
if (!empty())
{
clear();
}
}
//*************************************************************************
/// Gets a reference to the value at the front of the queue.<br>
/// \return A reference to the value at the front of the queue.

View File

@ -786,6 +786,17 @@ namespace etl
return *this;
}
//*************************************************************************
/// Destructor.
//*************************************************************************
~iset()
{
if (!empty())
{
clear();
}
}
//*************************************************************************
/// Gets the beginning of the set.
//*************************************************************************

View File

@ -230,6 +230,17 @@ namespace etl
public:
//*************************************************************************
/// Destructor.
//*************************************************************************
~istack()
{
if (!empty())
{
clear();
}
}
//*************************************************************************
/// Gets a reference to the value at the top of the stack.<br>
/// \return A reference to the value at the top of the stack.

View File

@ -480,6 +480,17 @@ namespace etl
typedef typename std::iterator_traits<iterator>::difference_type difference_type;
//*************************************************************************
/// Destructor.
//*************************************************************************
~iunordered_map()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the unordered_map.
///\return An iterator to the beginning of the unordered_map.

View File

@ -480,6 +480,17 @@ namespace etl
typedef typename std::iterator_traits<iterator>::difference_type difference_type;
//*************************************************************************
/// Destructor.
//*************************************************************************
~iunordered_multimap()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the unordered_multimap.
///\return An iterator to the beginning of the unordered_multimap.

View File

@ -475,6 +475,17 @@ namespace etl
typedef typename std::iterator_traits<iterator>::difference_type difference_type;
//*************************************************************************
/// Destructor.
//*************************************************************************
~iunordered_multiset()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the unordered_multiset.
///\return An iterator to the beginning of the unordered_multiset.

View File

@ -476,6 +476,17 @@ namespace etl
typedef typename std::iterator_traits<iterator>::difference_type difference_type;
//*************************************************************************
/// Destructor.
//*************************************************************************
~iunordered_set()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the unordered_set.
///\return An iterator to the beginning of the unordered_set.

View File

@ -93,6 +93,17 @@ namespace etl
public:
//*************************************************************************
/// Destructor.
//*************************************************************************
~ivector()
{
if (!empty())
{
clear();
}
}
//*********************************************************************
/// Returns an iterator to the beginning of the vector.
///\return An iterator to the beginning of the vector.

File diff suppressed because it is too large Load Diff

View File

@ -31,11 +31,13 @@ SOFTWARE.
#include <ostream>
#include "instance_count.h"
//*****************************************************************************
// Default constructor.
//*****************************************************************************
template <typename T>
class TestDataDC
class TestDataDC : public etl::instance_count<TestDataDC<T>>
{
public:
@ -88,7 +90,7 @@ std::ostream& operator << (std::ostream& s, const TestDataDC<T>& rhs)
// No default constructor.
//*****************************************************************************
template <typename T>
class TestDataNDC
class TestDataNDC : public etl::instance_count<TestDataNDC<T>>
{
public:

View File

@ -107,6 +107,19 @@ namespace
CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST(test_destruct_via_ideque)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(SIZE, N999);
CHECK_EQUAL(int(current_count + SIZE), NDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, NDC::get_instance_count());
}
//*************************************************************************
TEST(test_constructor_fill_excess)
{

View File

@ -238,6 +238,19 @@ namespace
CHECK_EQUAL(data.max_size(), SIZE);
}
//*************************************************************************
TEST(test_destruct_via_iflat_map)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, NDC::get_instance_count());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{

View File

@ -197,6 +197,19 @@ namespace
CHECK_EQUAL(data.max_size(), SIZE);
}
//*************************************************************************
TEST(test_destruct_via_iflat_multimap)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, NDC::get_instance_count());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{
@ -499,7 +512,7 @@ namespace
DataNDC data(compare_data.begin(), compare_data.end());
data.clear();
CHECK_EQUAL(data.size(), size_t(0));
// Do it again to check that clear() didn't screw up the internals.
data.assign(compare_data.begin(), compare_data.end());
CHECK_EQUAL(data.size(), compare_data.size());

View File

@ -154,6 +154,19 @@ namespace
CHECK_EQUAL(data.max_size(), SIZE);
}
//*************************************************************************
TEST(test_destruct_via_iflat_multiset)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, NDC::get_instance_count());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{

View File

@ -101,7 +101,7 @@ namespace
std::vector<NDC> initial_data;
std::vector<NDC> excess_data;
std::vector<NDC> different_data;
std::vector<int> int_data;
//*************************************************************************
@ -147,6 +147,19 @@ namespace
CHECK_EQUAL(data.max_size(), SIZE);
}
//*************************************************************************
TEST(test_destruct_via_iflat_set)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, NDC::get_instance_count());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{

View File

@ -129,6 +129,19 @@ namespace
CHECK(!data.empty());
}
//*************************************************************************
TEST(test_destruct_via_iforward_list)
{
int current_count = ItemNDC::get_instance_count();
DataNDC* pdata = new DataNDC(sorted_data.begin(), sorted_data.end());
CHECK_EQUAL(int(current_count + sorted_data.size()), ItemNDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, ItemNDC::get_instance_count());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_copy_constructor)
{

View File

@ -35,7 +35,7 @@ SOFTWARE.
#include <numeric>
namespace
{
{
SUITE(test_instance_count)
{
//*************************************************************************
@ -47,25 +47,29 @@ namespace
struct Test2 : public etl::instance_count<Test2>
{};
CHECK_EQUAL(0U, Test1::get_instance_count());
CHECK_EQUAL(0U, Test2::get_instance_count());
CHECK_EQUAL(0, Test1::get_instance_count());
CHECK_EQUAL(0, Test2::get_instance_count());
Test1 test1a;
CHECK_EQUAL(1U, Test1::get_instance_count());
CHECK_EQUAL(0U, Test2::get_instance_count());
CHECK_EQUAL(1, Test1::get_instance_count());
CHECK_EQUAL(0, Test2::get_instance_count());
Test1 test1b;
Test2 test2a;
CHECK_EQUAL(2U, Test1::get_instance_count());
CHECK_EQUAL(1U, Test2::get_instance_count());
CHECK_EQUAL(2, Test1::get_instance_count());
CHECK_EQUAL(1, Test2::get_instance_count());
Test2* ptest2b = new Test2;
CHECK_EQUAL(2U, Test1::get_instance_count());
CHECK_EQUAL(2U, Test2::get_instance_count());
CHECK_EQUAL(2, Test1::get_instance_count());
CHECK_EQUAL(2, Test2::get_instance_count());
Test2 test2c(test2a);
CHECK_EQUAL(2, Test1::get_instance_count());
CHECK_EQUAL(3, Test2::get_instance_count());
delete ptest2b;
CHECK_EQUAL(2U, Test1::get_instance_count());
CHECK_EQUAL(1U, Test2::get_instance_count());
CHECK_EQUAL(2, Test1::get_instance_count());
CHECK_EQUAL(2, Test2::get_instance_count());
}
};
}

View File

@ -100,6 +100,19 @@ namespace
CHECK_EQUAL(data.max_size(), SIZE);
}
//*************************************************************************
TEST(test_destruct_via_ilist)
{
int current_count = ItemNDC::get_instance_count();
DataNDC* pdata = new DataNDC(sorted_data.begin(), sorted_data.end());
CHECK_EQUAL(int(current_count + sorted_data.size()), ItemNDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, ItemNDC::get_instance_count());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_size)
{

View File

@ -183,6 +183,15 @@ namespace
CHECK_EQUAL(data.max_size(), MAX_SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_destruct_via_imap)
{
Data* pdata = new Data(initial_data.begin(), initial_data.end());
IData* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{

View File

@ -183,6 +183,15 @@ namespace
CHECK_EQUAL(data.max_size(), MAX_SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_destruct_via_imultimap)
{
Data* pdata = new Data(initial_data.begin(), initial_data.end());
IData* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{

View File

@ -175,6 +175,15 @@ namespace
CHECK_EQUAL(data.max_size(), MAX_SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_destruct_via_imultiset)
{
Data* pdata = new Data(initial_data.begin(), initial_data.end());
IData* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{

View File

@ -78,6 +78,23 @@ namespace
CHECK_EQUAL(priority_queue.max_size(), SIZE);
}
//*************************************************************************
TEST(test_delete_via_ipriority_queue)
{
typedef etl::priority_queue<int, 4> priority_queue_t;
priority_queue_t* ppriority_queue = new etl::priority_queue<int, 4>;
etl::ipriority_queue<int, priority_queue_t::container_type, priority_queue_t::compare_type>* pipriority_queue = ppriority_queue;
pipriority_queue->push(1);
pipriority_queue->push(2);
pipriority_queue->push(3);
pipriority_queue->push(4);
delete pipriority_queue;
}
//*************************************************************************
TEST(test_copy_constructor)
{

View File

@ -97,6 +97,21 @@ namespace
}
}
//*************************************************************************
TEST(test_delete_via_iqueue)
{
etl::queue<int, 4>* pqueue = new etl::queue<int, 4>;
etl::iqueue<int>* piqueue = pqueue;
piqueue->push(1);
piqueue->push(2);
piqueue->push(3);
piqueue->push(4);
delete piqueue;
}
//*************************************************************************
TEST(test_size)
{

View File

@ -227,6 +227,17 @@ namespace
CHECK(!data.empty());
}
//*************************************************************************
TEST(test_destruct_via_ireference_flat_map)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_begin)
{

View File

@ -185,6 +185,17 @@ namespace
CHECK(!data.empty());
}
//*************************************************************************
TEST(test_destruct_via_ireference_flat_multimap)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_begin)
{

View File

@ -171,6 +171,17 @@ namespace
CHECK(!data.empty());
}
//*************************************************************************
TEST(test_destruct_via_ireference_flat_multiset)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_begin)
{

View File

@ -167,6 +167,17 @@ namespace
CHECK(!data.empty());
}
//*************************************************************************
TEST(test_destruct_via_ireference_flat_set)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_begin)
{

View File

@ -186,6 +186,15 @@ namespace
CHECK_EQUAL(data.max_size(), MAX_SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_destruct_via_iset)
{
Data* pdata = new Data(initial_data.begin(), initial_data.end());
IData* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range)
{

View File

@ -102,6 +102,21 @@ namespace
}
}
//*************************************************************************
TEST(test_delete_via_istack)
{
etl::stack<int, 4>* pstack = new etl::stack<int, 4>;
etl::istack<int>* pistack = pstack;
pistack->push(1);
pistack->push(2);
pistack->push(3);
pistack->push(4);
delete pistack;
}
//*************************************************************************
TEST(test_empty)
{

View File

@ -231,6 +231,17 @@ namespace
CHECK(data.full());
}
//*************************************************************************
TEST(test_destruct_via_iunordered_map)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment)
{

View File

@ -208,6 +208,17 @@ namespace
CHECK(data.full());
}
//*************************************************************************
TEST(test_destruct_via_iunordered_multimap)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment)
{

View File

@ -142,6 +142,17 @@ namespace
CHECK(data.full());
}
//*************************************************************************
TEST(test_destruct_via_iunordered_multiset)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment)
{

View File

@ -134,6 +134,17 @@ namespace
CHECK(data.full());
}
//*************************************************************************
TEST(test_destruct_via_iunordered_set)
{
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end());
IDataNDC* pidata = pdata;
delete pidata;
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment)
{

View File

@ -36,7 +36,7 @@
#include "data.h"
namespace
{
{
SUITE(test_vector_non_trivial)
{
static const size_t SIZE = 10;
@ -44,6 +44,8 @@ namespace
typedef TestDataNDC<std::string> NDC;
typedef TestDataDC<std::string> DC;
static NDC ndc("NDC");
typedef etl::vector<NDC, SIZE> DataNDC;
typedef etl::ivector<NDC> IDataNDC;
typedef std::vector<NDC> CompareDataNDC;
@ -51,7 +53,7 @@ namespace
typedef etl::vector<DC, SIZE> DataDC;
typedef etl::ivector<DC> IDataDC;
typedef std::vector<DC> CompareDataDC;
CompareDataNDC initial_data;
CompareDataNDC less_data;
CompareDataNDC greater_data;
@ -89,6 +91,22 @@ namespace
CHECK_EQUAL(data.max_size(), SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_destruct_via_ivector)
{
const size_t INITIAL_SIZE = 5;
const NDC INITIAL_VALUE("1");
int current_count = NDC::get_instance_count();
DataNDC* pdata = new DataNDC(INITIAL_SIZE, INITIAL_VALUE);
CHECK_EQUAL(int(current_count + INITIAL_SIZE), NDC::get_instance_count());
IDataNDC* pidata = pdata;
delete pidata;
CHECK_EQUAL(current_count, NDC::get_instance_count());
}
//*************************************************************************
TEST(test_iterator_comparison_empty)
{
@ -152,7 +170,7 @@ namespace
DataNDC data(initial_data.begin(), initial_data.end());
DataNDC data2(data);
CHECK(data2 == data);
data2[2] = NDC("X");
CHECK(data2 != data);
}
@ -400,7 +418,7 @@ namespace
CHECK(data.back() == compare_data.back());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_data)
{
@ -676,7 +694,7 @@ namespace
const size_t INITIAL_SIZE = 5;
const size_t INSERT_SIZE = 3;
const NDC INITIAL_VALUE("1");
for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset)
{
CompareDataNDC compare_data;
@ -770,7 +788,7 @@ namespace
offset = 4;
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full);
offset = data.size();
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full);
@ -813,7 +831,7 @@ namespace
CHECK(is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_clear)
{