From e0dd8eae1a070a61bc191419cc9af1777cade091 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 8 Dec 2014 20:13:24 +0000 Subject: [PATCH] Changed to stddef.h Added error_hander support --- forward_list.h | 6 ++--- forward_list_base.h | 17 +++++++++---- iforward_list.h | 61 +++++++++++++++++++++++++++++++++------------ 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/forward_list.h b/forward_list.h index e8d78c35..fda596e3 100644 --- a/forward_list.h +++ b/forward_list.h @@ -29,7 +29,7 @@ SOFTWARE. #ifndef __ETL_LIST__ #define __ETL_LIST__ -#include +#include #include "iforward_list.h" #include "container.h" @@ -66,7 +66,7 @@ namespace etl //************************************************************************* /// Default constructor. //************************************************************************* - inline forward_list() + forward_list() : iforward_list(&node_pool[0], MAX_SIZE) { } @@ -74,7 +74,7 @@ namespace etl //************************************************************************* /// Construct from size and value. //************************************************************************* - inline explicit forward_list(size_t initialSize, typename iforward_list::parameter_t value = T()) + explicit forward_list(size_t initialSize, typename iforward_list::parameter_t value = T()) : iforward_list(&node_pool[0], MAX_SIZE) { iforward_list::assign(initialSize, value); diff --git a/forward_list_base.h b/forward_list_base.h index ca7e4e97..d93bfde3 100644 --- a/forward_list_base.h +++ b/forward_list_base.h @@ -33,12 +33,11 @@ SOFTWARE. #ifndef __ETL_LIST_BASE__ #define __ETL_LIST_BASE__ -#include +#include #include "exception.h" namespace etl { -#ifdef ETL_USE_EXCEPTIONS //*************************************************************************** /// Exception for the forward_list. ///\ingroup forward_list @@ -62,7 +61,7 @@ namespace etl public: forward_list_full() - : forward_list_exception("List full") + : forward_list_exception("forward list: full") { } }; @@ -76,11 +75,10 @@ namespace etl public: forward_list_iterator() - : forward_list_exception("Iterator problem") + : forward_list_exception("forward_list: iterator problem") { } }; -#endif //*************************************************************************** /// The base class for all forward_lists. @@ -124,6 +122,15 @@ namespace etl return count == MAX_SIZE; } + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return max_size() - size(); + } + protected: //************************************************************************* diff --git a/iforward_list.h b/iforward_list.h index 2de84ac6..62a9e2f2 100644 --- a/iforward_list.h +++ b/iforward_list.h @@ -37,7 +37,7 @@ SOFTWARE. #include #include #include -#include +#include #include "nullptr.h" #include "forward_list_base.h" @@ -374,8 +374,8 @@ namespace etl //************************************************************************* /// Assigns a range of values to the forward_list. - /// If ETL_USE_EXCEPTIONS is defined throws etl::forward_list_full if the forward_list does not have enough free space. - /// If ETL_USE_EXCEPTIONS & _DEBUG are defined throws forward_list_iterator if the iterators are reversed. + /// If ETL_THROW_EXCEPTIONS is defined throws etl::forward_list_full if the forward_list does not have enough free space. + /// If ETL_THROW_EXCEPTIONS & _DEBUG are defined throws forward_list_iterator if the iterators are reversed. //************************************************************************* template void assign(TIterator first, TIterator last) @@ -398,11 +398,15 @@ namespace etl join(data_node, end_node); p_last_node = &data_node; } -#ifdef ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); } +#else + { + error_handler::error(forward_list_full()); + } #endif } @@ -440,11 +444,15 @@ namespace etl join(data_node, end_node); p_last_node = &data_node; } -#ifdef ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); } +#else + { + error_handler::error(forward_list_full()); + } #endif } @@ -470,11 +478,15 @@ namespace etl insert_node(get_head(), data_node); } -#ifdef ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); } +#else + { + error_handler::error(forward_list_full()); + } #endif } @@ -490,11 +502,15 @@ namespace etl insert_node_after(get_head(), data_node); } -#ifdef ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); } +#else + { + error_handler::error(forward_list_full()); + } #endif } @@ -519,7 +535,7 @@ namespace etl //************************************************************************* /// Resizes the forward_list. - /// If ETL_USE_EXCEPTIONS is defined, will throw an etl::forward_list_full + /// If ETL_THROW_EXCEPTIONS is defined, will throw an etl::forward_list_full /// if n is larger than the maximum size. //************************************************************************* void resize(size_t n, T value) @@ -550,11 +566,15 @@ namespace etl } } } -#if ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); } +#else + { + error_handler::error(forward_list_full()); + } #endif } @@ -600,14 +620,15 @@ namespace etl return iterator(data_node); } -#if ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); return end(); } #else { + error_handler::error(forward_list_full()); return end(); } #endif @@ -629,11 +650,15 @@ namespace etl insert_node(*position.p_node, data_node); } } -#if ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); } +#else + { + error_handler::error(forward_list_full()); + } #endif } @@ -655,11 +680,15 @@ namespace etl ++first; ++position; } -#if ETL_USE_EXCEPTIONS else +#ifdef ETL_THROW_EXCEPTIONS { throw forward_list_full(); } +#else + { + error_handler::error(forward_list_full()); + } #endif } } @@ -944,7 +973,7 @@ namespace etl //************************************************************************* /// Downcast a Node* to a Data_Node* //************************************************************************* - inline static Data_Node* data_cast(Node* p_node) + static Data_Node* data_cast(Node* p_node) { return static_cast(p_node); } @@ -952,7 +981,7 @@ namespace etl //************************************************************************* /// Downcast a Node& to a Data_Node& //************************************************************************* - inline static Data_Node& data_cast(Node& node) + static Data_Node& data_cast(Node& node) { return static_cast(node); } @@ -960,7 +989,7 @@ namespace etl //************************************************************************* /// Downcast a const Node* to a const Data_Node* //************************************************************************* - inline static const Data_Node* data_cast(const Node* p_node) + static const Data_Node* data_cast(const Node* p_node) { return static_cast(p_node); } @@ -968,7 +997,7 @@ namespace etl //************************************************************************* /// Downcast a const Node& to a const Data_Node& //************************************************************************* - inline static const Data_Node& data_cast(const Node& node) + static const Data_Node& data_cast(const Node& node) { return static_cast(node); }