From 0c6785e25fc3a36c3c4e13f2d672dc5b944754a5 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 8 Dec 2014 20:29:36 +0000 Subject: [PATCH] Changed to stddef.h --- vector_base.h | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/vector_base.h b/vector_base.h index 629ebda3..c1f2a89e 100644 --- a/vector_base.h +++ b/vector_base.h @@ -33,16 +33,19 @@ SOFTWARE. #ifndef __ETL_VECTOR_BASE__ #define __ETL_VECTOR_BASE__ -#include +#include #include "exception.h" +#ifndef ETL_THROW_EXCEPTIONS +#include "error_handler.h" +#endif + namespace etl { -#ifdef ETL_USE_EXCEPTIONS //*************************************************************************** ///\ingroup vector - /// exception base for vectors + /// exception base for vectors //*************************************************************************** class vector_exception : public exception { @@ -63,21 +66,7 @@ namespace etl public: vector_full() - : vector_exception("vector full") - { - } - }; - - //*************************************************************************** - ///\ingroup vector - /// Vector empty exception. - //*************************************************************************** - class vector_empty : public vector_exception - { - public: - - vector_empty() - : vector_exception("vector empty") + : vector_exception("vector: full") { } }; @@ -91,7 +80,7 @@ namespace etl public: vector_out_of_bounds() - : vector_exception("vector out of bounds") + : vector_exception("vector: out of bounds") { } }; @@ -105,11 +94,10 @@ namespace etl public: vector_iterator() - : vector_exception("vector iterator error") + : vector_exception("vector: iterator error") { } }; -#endif //*************************************************************************** ///\ingroup vector @@ -166,6 +154,15 @@ namespace etl return MAX_SIZE; } + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return max_size() - size(); + } + //************************************************************************* /// Clears the vector. //************************************************************************* @@ -176,15 +173,19 @@ namespace etl //************************************************************************* /// Increases the size of the vector by one, but does not initialise the new element. - /// If ETL_USE_EXCEPTIONS is defined, throws a vector_full if the vector is already full. + /// If ETL_THROW_EXCEPTIONS is defined, throws a vector_full if the vector is already full. //************************************************************************* void push_back() { -#ifdef ETL_USE_EXCEPTIONS +#ifdef ETL_THROW_EXCEPTIONS if (current_size == MAX_SIZE) { throw vector_full(); } +#else + { + error_handler:: + } #endif ++current_size;