From 8aff17435c45834867746a3fc649abd257c968f2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 7 Jan 2016 17:34:37 +0000 Subject: [PATCH] Added ETL_CHECK_PUSH_POP to enable empry/full checks for push & pop functions. Normally this not be set as the code will be doing this check when necessary. --- basic_intrusive_forward_list.h | 2 ++ function.h | 4 +++- ideque.h | 13 ++++++++++++- iforward_list.h | 8 ++++++-- ilist.h | 18 ++++++++++++------ intrusive_forward_list.h | 2 ++ ipriority_queue.h | 1 + iqueue.h | 9 ++++++--- istack.h | 9 ++++++--- ivector.h | 6 ++++++ priority_queue.h | 4 ++-- test/test_priority_queue.cpp | 24 ++++++++++++++++++++++++ test/vs2015/etl.vcxproj | 2 +- 13 files changed, 83 insertions(+), 19 deletions(-) diff --git a/basic_intrusive_forward_list.h b/basic_intrusive_forward_list.h index ab92b883..399912c1 100644 --- a/basic_intrusive_forward_list.h +++ b/basic_intrusive_forward_list.h @@ -429,7 +429,9 @@ namespace etl //************************************************************************* void pop_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(basic_intrusive_forward_list_empty)); +#endif remove_node_after(start_node); } diff --git a/function.h b/function.h index d5d91742..caf7b4c9 100644 --- a/function.h +++ b/function.h @@ -69,6 +69,8 @@ namespace etl { public: + typedef void parameter_type; ///< The type of parameter sent to the function. + //************************************************************************* /// The function operator that will be overridden. //************************************************************************* @@ -154,7 +156,7 @@ namespace etl //*************************************************************************** ///\ingroup function - /// Specialisation for static or global functions that take a parameter. + /// Specialisation for static or global functions that takes a parameter. //*************************************************************************** template class function : public ifunction diff --git a/ideque.h b/ideque.h index 76b3319c..c983bbbe 100644 --- a/ideque.h +++ b/ideque.h @@ -1082,7 +1082,9 @@ namespace etl //************************************************************************* void push_back(parameter_t item) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif create_element_back(item); } @@ -1094,8 +1096,9 @@ namespace etl reference push_back() { reference r = *_end; - +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif create_element_back(); return r; @@ -1106,7 +1109,9 @@ namespace etl //************************************************************************* void pop_back() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(deque_empty)); +#endif destroy_element_back(); } @@ -1117,7 +1122,9 @@ namespace etl //************************************************************************* void push_front(parameter_t item) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif create_element_front(item); } @@ -1128,7 +1135,9 @@ namespace etl //************************************************************************* reference push_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif create_element_front(); return *_begin; @@ -1139,7 +1148,9 @@ namespace etl //************************************************************************* void pop_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(deque_empty)); +#endif destroy_element_front(); } diff --git a/iforward_list.h b/iforward_list.h index 76138a86..9782ae45 100644 --- a/iforward_list.h +++ b/iforward_list.h @@ -411,8 +411,9 @@ namespace etl //************************************************************************* void push_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); - +#endif Data_Node& data_node = allocate_data_node(T()); insert_node_after(start_node, data_node); } @@ -422,8 +423,9 @@ namespace etl //************************************************************************* void push_front(parameter_t value) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); - +#endif Data_Node& data_node = allocate_data_node(value); insert_node_after(start_node, data_node); } @@ -433,7 +435,9 @@ namespace etl //************************************************************************* void pop_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_empty)); +#endif remove_node_after(start_node); } diff --git a/ilist.h b/ilist.h index 15793ead..70f4bd40 100644 --- a/ilist.h +++ b/ilist.h @@ -495,8 +495,9 @@ namespace etl //************************************************************************* void push_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); - +#endif Data_Node& data_node = allocate_data_node(T()); insert_node(get_head(), data_node); } @@ -506,8 +507,9 @@ namespace etl //************************************************************************* void push_front(parameter_t value) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); - +#endif Node& data_node = allocate_data_node(value); insert_node(get_head(), data_node); } @@ -517,8 +519,9 @@ namespace etl //************************************************************************* void pop_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(list_empty)); - +#endif Node& node = get_head(); remove_node(node); } @@ -528,8 +531,9 @@ namespace etl //************************************************************************* void push_back() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); - +#endif Data_Node& data_node = allocate_data_node(T()); insert_node(terminal_node, data_node); } @@ -539,8 +543,9 @@ namespace etl //************************************************************************* void push_back(parameter_t value) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); - +#endif Data_Node& data_node = allocate_data_node(value); insert_node(terminal_node, data_node); } @@ -550,8 +555,9 @@ namespace etl //************************************************************************* void pop_back() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(list_empty)); - +#endif Node& node = get_tail(); remove_node(node); } diff --git a/intrusive_forward_list.h b/intrusive_forward_list.h index 0abf45bc..9e3b4546 100644 --- a/intrusive_forward_list.h +++ b/intrusive_forward_list.h @@ -454,7 +454,9 @@ namespace etl //************************************************************************* void pop_front() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(intrusive_forward_list_empty)); +#endif remove_node_after(start_node); } diff --git a/ipriority_queue.h b/ipriority_queue.h index 4b8b8cf5..36a1c017 100644 --- a/ipriority_queue.h +++ b/ipriority_queue.h @@ -65,6 +65,7 @@ namespace etl typedef T value_type; ///< The type stored in the queue. typedef TContainer container_type; ///< The container type used for priority queue. + typedef TCompare compare_type; ///< The comparison type. typedef T& reference; ///< A reference to the type used in the queue. typedef const T& const_reference; ///< A const reference to the type used in the queue. typedef priority_queue_base::size_type size_type; ///< The type used for determining the size of the queue. diff --git a/iqueue.h b/iqueue.h index 86ab1bf6..85fd3194 100644 --- a/iqueue.h +++ b/iqueue.h @@ -114,8 +114,9 @@ namespace etl //************************************************************************* void push(parameter_t value) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); - +#endif new(&p_buffer[in]) T(value); in = (in == (MAX_SIZE - 1)) ? 0 : in + 1; ++current_size; @@ -133,8 +134,9 @@ namespace etl { const size_type next = in; +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); - +#endif new(&p_buffer[in]) T(); in = (in == (MAX_SIZE - 1)) ? 0 : in + 1; ++current_size; @@ -164,8 +166,9 @@ namespace etl //************************************************************************* void pop() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(queue_empty)); - +#endif p_buffer[out].~T(); out = (out == (MAX_SIZE - 1)) ? 0 : out + 1; --current_size; diff --git a/istack.h b/istack.h index f8ba9563..14cb843f 100644 --- a/istack.h +++ b/istack.h @@ -86,8 +86,9 @@ namespace etl //************************************************************************* void push(parameter_t value) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); - +#endif top_index = current_size++; new(&p_buffer[top_index]) T(value); } @@ -101,8 +102,9 @@ namespace etl //************************************************************************* reference push() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); - +#endif top_index = current_size++; new(&p_buffer[top_index]) T(); @@ -137,8 +139,9 @@ namespace etl //************************************************************************* void pop() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!empty(), ETL_ERROR(stack_empty)); - +#endif p_buffer[top_index].~T(); --top_index; --current_size; diff --git a/ivector.h b/ivector.h index 4a0090e8..6c753f6f 100644 --- a/ivector.h +++ b/ivector.h @@ -401,7 +401,9 @@ namespace etl //************************************************************************* void push_back() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)); +#endif create_element(); } @@ -412,7 +414,9 @@ namespace etl //********************************************************************* void push_back(parameter_t value) { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)); +#endif create_element(value); } @@ -422,7 +426,9 @@ namespace etl //************************************************************************* void pop_back() { +#if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(current_size > 0, ETL_ERROR(vector_empty)); +#endif destroy_element(); } diff --git a/priority_queue.h b/priority_queue.h index 042293f2..2d017536 100644 --- a/priority_queue.h +++ b/priority_queue.h @@ -48,8 +48,8 @@ SOFTWARE. namespace etl { //*************************************************************************** - ///\ingroup queue - /// A fixed capacity queue. + ///\ingroup priority_queue + /// A fixed capacity priority queue. /// This queue does not support concurrent access by different threads. /// \tparam T The type this queue should support. /// \tparam SIZE The maximum capacity of the queue. diff --git a/test/test_priority_queue.cpp b/test/test_priority_queue.cpp index e98d3441..e30b8ff0 100644 --- a/test/test_priority_queue.cpp +++ b/test/test_priority_queue.cpp @@ -324,6 +324,30 @@ namespace } } + //************************************************************************* + TEST(test_interface) + { + typedef etl::priority_queue priority_queue_t; + priority_queue_t priority_queue; + etl::ipriority_queue& ipriority_queue = priority_queue; + + std::priority_queue compare_priority_queue; + + ipriority_queue.push(1); + compare_priority_queue.push(1); + + ipriority_queue.push(2); + compare_priority_queue.push(2); + + ipriority_queue.push(3); + compare_priority_queue.push(3); + + ipriority_queue.push(4); + compare_priority_queue.push(4); + CHECK_EQUAL(compare_priority_queue.size(), ipriority_queue.size()); + CHECK_EQUAL(compare_priority_queue.top(), ipriority_queue.top()); + } + //************************************************************************* TEST(test_self_assignment) { diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index d96b3dee..e0ccb5e2 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -53,7 +53,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;PLATFORM_WINDOWS;COMPILER_MICROSOFT;ETL_VERBOSE_ERRORS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;PLATFORM_WINDOWS;COMPILER_MICROSOFT;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions) ../../../unittest-cpp