diff --git a/private/pool_base.h b/private/pool_base.h
index b9aa7257..7a358166 100644
--- a/private/pool_base.h
+++ b/private/pool_base.h
@@ -93,6 +93,14 @@ namespace etl
{
public:
+ //*************************************************************************
+ /// Returns the maximum number of items in the pool.
+ //*************************************************************************
+ size_t max_size() const
+ {
+ return MAX_SIZE;
+ }
+
//*************************************************************************
/// Returns the number of free items in the pool.
//*************************************************************************
@@ -102,10 +110,27 @@ namespace etl
}
//*************************************************************************
- /// Checks to see if there are no free items in the pool.
- /// \return true if there are none free (or 'empty')
+ /// Returns the number of allocated items in the pool.
//*************************************************************************
- bool none_free() const
+ size_t size() const
+ {
+ return items_allocated;
+ }
+
+ //*************************************************************************
+ /// Checks to see if there are no allocated items in the pool.
+ /// \return true if there are none allocated.
+ //*************************************************************************
+ bool empty() const
+ {
+ return items_allocated == 0;
+ }
+
+ //*************************************************************************
+ /// Checks to see if there are no free items in the pool.
+ /// \return true if there are none free.
+ //*************************************************************************
+ bool full() const
{
return items_allocated == MAX_SIZE;
}
diff --git a/test/test_pool.cpp b/test/test_pool.cpp
index e803934f..950594e7 100644
--- a/test/test_pool.cpp
+++ b/test/test_pool.cpp
@@ -138,7 +138,7 @@ namespace
CHECK(p7 != p4);
CHECK(p7 != p6);
- CHECK(pool.none_free());
+ CHECK(pool.full());
}
//*************************************************************************
@@ -163,24 +163,58 @@ namespace
}
//*************************************************************************
- TEST(test_none_free)
+ TEST(test_max_size)
{
etl::pool pool;
- CHECK_EQUAL(4, pool.available());
+
+ CHECK(pool.max_size() == 4);
+ }
+
+ //*************************************************************************
+ TEST(test_size)
+ {
+ etl::pool pool;
+ CHECK_EQUAL(0, pool.size());
Test_Data* p;
p = pool.allocate();
- CHECK(!pool.none_free());
+ CHECK_EQUAL(1, pool.size());
p = pool.allocate();
- CHECK(!pool.none_free());
+ CHECK_EQUAL(2, pool.size());
p = pool.allocate();
- CHECK(!pool.none_free());
+ CHECK_EQUAL(3, pool.size());
p = pool.allocate();
- CHECK(pool.none_free());
+ CHECK_EQUAL(4, pool.size());
+ }
+
+ //*************************************************************************
+ TEST(test_empty_full)
+ {
+ etl::pool pool;
+ CHECK(pool.empty());
+ CHECK(!pool.full());
+
+ Test_Data* p;
+
+ p = pool.allocate();
+ CHECK(!pool.empty());
+ CHECK(!pool.full());
+
+ p = pool.allocate();
+ CHECK(!pool.empty());
+ CHECK(!pool.full());
+
+ p = pool.allocate();
+ CHECK(!pool.empty());
+ CHECK(!pool.full());
+
+ p = pool.allocate();
+ CHECK(!pool.empty());
+ CHECK(pool.full());
}
//*************************************************************************
@@ -244,42 +278,42 @@ namespace
}
}
- ////*************************************************************************
- //TEST(test_get_iterator)
- //{
- // typedef etl::pool Pool;
+ //*************************************************************************
+ TEST(test_get_iterator)
+ {
+ typedef etl::pool Pool;
- // Pool pool;
- // Test_Data not_in_pool;
+ Pool pool;
+ Test_Data not_in_pool;
- // Test_Data* p1 = pool.allocate();
- // Test_Data* p2 = pool.allocate();
+ Test_Data* p1 = pool.allocate();
+ Test_Data* p2 = pool.allocate();
- // Pool::iterator i_data = pool.get_iterator(*p1);
- // Pool::iterator i_ndata = pool.get_iterator(not_in_pool);
+ Pool::iterator i_data = pool.get_iterator(*p1);
+ Pool::iterator i_ndata = pool.get_iterator(not_in_pool);
- // CHECK(p1 == &*i_data);
- // CHECK(p2 != &*i_data);
- // CHECK(pool.end() == i_ndata);
- //}
+ CHECK(p1 == &*i_data);
+ CHECK(p2 != &*i_data);
+ CHECK(pool.end() == i_ndata);
+ }
- ////*************************************************************************
- //TEST(test_get_iterator_const)
- //{
- // typedef etl::pool Pool;
+ //*************************************************************************
+ TEST(test_get_iterator_const)
+ {
+ typedef etl::pool Pool;
- // Pool pool;
- // const Test_Data not_in_pool;
+ Pool pool;
+ const Test_Data not_in_pool;
- // const Test_Data* p1 = pool.allocate();
- // const Test_Data* p2 = pool.allocate();
+ const Test_Data* p1 = pool.allocate();
+ const Test_Data* p2 = pool.allocate();
- // Pool::const_iterator i_data = pool.get_iterator(*p1);
- // Pool::const_iterator i_ndata = pool.get_iterator(not_in_pool);
+ Pool::const_iterator i_data = pool.get_iterator(*p1);
+ Pool::const_iterator i_ndata = pool.get_iterator(not_in_pool);
- // CHECK(p1 == &*i_data);
- // CHECK(p2 != &*i_data);
- // CHECK(pool.end() == i_ndata);
- //}
+ CHECK(p1 == &*i_data);
+ CHECK(p2 != &*i_data);
+ CHECK(pool.end() == i_ndata);
+ }
};
}