mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added type size test and error to ipool::allocate
This commit is contained in:
parent
ce7db33844
commit
259dbfa741
20
src/pool.h
20
src/pool.h
@ -90,7 +90,20 @@ namespace etl
|
||||
public:
|
||||
|
||||
pool_object_not_in_pool(string_type file_name, numeric_type line_number)
|
||||
: pool_exception(ETL_ERROR_TEXT("pool:notinpool", ETL_FILE"B"), file_name, line_number)
|
||||
: pool_exception(ETL_ERROR_TEXT("pool:not in pool", ETL_FILE"B"), file_name, line_number)
|
||||
{}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// The exception thrown when an the type requested is larger than the element size.
|
||||
///\ingroup pool
|
||||
//***************************************************************************
|
||||
class pool_element_size : public pool_exception
|
||||
{
|
||||
public:
|
||||
|
||||
pool_element_size(string_type file_name, numeric_type line_number)
|
||||
: pool_exception(ETL_ERROR_TEXT("pool:element size", ETL_FILE"C"), file_name, line_number)
|
||||
{}
|
||||
};
|
||||
|
||||
@ -112,6 +125,11 @@ namespace etl
|
||||
template <typename T>
|
||||
T* allocate()
|
||||
{
|
||||
if (sizeof(T) > ITEM_SIZE)
|
||||
{
|
||||
ETL_ASSERT(false, ETL_ERROR(etl::pool_element_size));
|
||||
}
|
||||
|
||||
return reinterpret_cast<T*>(allocate_item());
|
||||
}
|
||||
|
||||
|
||||
@ -264,6 +264,16 @@ namespace
|
||||
|
||||
CHECK_EQUAL(4U, pool.available());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_type_error)
|
||||
{
|
||||
etl::pool<uint32_t, 4> pool;
|
||||
|
||||
etl::ipool& ip = pool;
|
||||
|
||||
CHECK_THROW(ip.allocate<double>(), etl::pool_element_size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user