mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added back() & #error for base class
This commit is contained in:
parent
7e00a9b5cd
commit
dc5ab85e28
49
iqueue.h
49
iqueue.h
@ -28,6 +28,7 @@ SOFTWARE.
|
||||
|
||||
#ifndef __etl_iqueue__
|
||||
#define __etl_iqueue__
|
||||
#define __etl_in_iqueue_h__
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@ -51,7 +52,7 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
typedef queue_base::size_type size_type; ///< The type used for determining the size of queue.
|
||||
typedef queue_base::size_type size_type; ///< The type used for determining the size of the queue.
|
||||
typedef T value_type; ///< The type stored in the queue.
|
||||
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.
|
||||
@ -68,9 +69,9 @@ namespace etl
|
||||
{
|
||||
if (!full())
|
||||
{
|
||||
buffer[in++] = item;
|
||||
buffer[in] = item;
|
||||
in = (in == (MAX_SIZE - 1)) ? 0 : ++in;
|
||||
++size;
|
||||
++current_size;
|
||||
}
|
||||
#ifdef ETL_USE_EXCEPTIONS
|
||||
else
|
||||
@ -95,7 +96,7 @@ namespace etl
|
||||
if (!full())
|
||||
{
|
||||
in = (in == (MAX_SIZE - 1)) ? 0 : ++in;
|
||||
++size;
|
||||
++current_size;
|
||||
}
|
||||
#ifdef ETL_USE_EXCEPTIONS
|
||||
else
|
||||
@ -143,12 +144,48 @@ namespace etl
|
||||
return buffer[out];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets a reference to the item at the back of the queue.<br>
|
||||
/// If ETL_USE_EXCEPTIONS is defined, throws an etl::queue_empty_exception if the queue is empty.<br>
|
||||
/// If ETL_USE_EXCEPTIONS is not defined and the queue is empty, the return value is undefined.
|
||||
/// \return A reference to the item at the back of the queue.
|
||||
//*************************************************************************
|
||||
reference back()
|
||||
{
|
||||
#ifdef ETL_USE_EXCEPTIONS
|
||||
if (empty())
|
||||
{
|
||||
throw queue_empty_exception();
|
||||
}
|
||||
#endif
|
||||
|
||||
return buffer[in == 0 ? MAX_SIZE - 1 : in - 1];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets a const reference to the item at the back of the queue.<br>
|
||||
/// If ETL_USE_EXCEPTIONS is defined, throws an etl::queue_empty_exception if the queue is empty.<br>
|
||||
/// If ETL_USE_EXCEPTIONS is not defined and the queue is empty, the return value is undefined.
|
||||
/// \return A const reference to the item at the back of the queue.
|
||||
//*************************************************************************
|
||||
const_reference back() const
|
||||
{
|
||||
#ifdef ETL_USE_EXCEPTIONS
|
||||
if (empty())
|
||||
{
|
||||
throw queue_empty_exception();
|
||||
}
|
||||
#endif
|
||||
|
||||
return buffer[in == 0 ? MAX_SIZE - 1 : in - 1];
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//*************************************************************************
|
||||
/// The constructor that is called from derived classes.
|
||||
//*************************************************************************
|
||||
queue(T* buffer, size_type max_size)
|
||||
iqueue(T* buffer, size_type max_size)
|
||||
: queue_base(max_size),
|
||||
buffer(buffer)
|
||||
{
|
||||
@ -160,3 +197,5 @@ namespace etl
|
||||
};
|
||||
}
|
||||
|
||||
#undef __etl_in_iqueue_h__
|
||||
#endif
|
||||
|
||||
2
queue.h
2
queue.h
@ -31,7 +31,7 @@ SOFTWARE.
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "IQueue.h"
|
||||
#include "iqueue.h"
|
||||
|
||||
//*****************************************************************************
|
||||
///\defgroup queue queue
|
||||
|
||||
24
queue_base.h
24
queue_base.h
@ -26,6 +26,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __etl_in_iqueue_h__
|
||||
#error This header is a private element of etl::queue & etl::iqueue
|
||||
#endif
|
||||
|
||||
#ifndef __etl_queue_base__
|
||||
#define __etl_queue_base__
|
||||
|
||||
@ -33,9 +37,6 @@ SOFTWARE.
|
||||
|
||||
#include "exception.h"
|
||||
|
||||
///\defgroup queue Queue
|
||||
///\ingroup containers
|
||||
|
||||
namespace etl
|
||||
{
|
||||
#ifdef ETL_USE_EXCEPTIONS
|
||||
@ -98,7 +99,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
size_type size() const
|
||||
{
|
||||
return size;
|
||||
return current_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -122,9 +123,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void clear()
|
||||
{
|
||||
in = 0;
|
||||
out = 0;
|
||||
size = 0;
|
||||
in = 0;
|
||||
out = 0;
|
||||
current_size = 0;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -133,7 +134,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
return size == 0;
|
||||
return current_size == 0;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -142,7 +143,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
bool full() const
|
||||
{
|
||||
return size == MAX_SIZE;
|
||||
return current_size == MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -154,7 +155,7 @@ namespace etl
|
||||
if (!empty())
|
||||
{
|
||||
out = (out == (MAX_SIZE - 1)) ? 0 : ++out;
|
||||
--size;
|
||||
--current_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,8 +172,9 @@ namespace etl
|
||||
|
||||
size_type in; ///< Where to input new data.
|
||||
size_type out; ///< Where to get the oldest data.
|
||||
size_type size; ///< The number of items in the queue.
|
||||
size_type current_size; ///< The number of items in the queue.
|
||||
const size_type MAX_SIZE; ///< The maximum number of items in the queue.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user