orca-sim
Public Member Functions | Private Attributes | List of all members
orcasim::modeling::Buffer< T > Class Template Reference

#include <Buffer.hpp>

Inheritance diagram for orcasim::modeling::Buffer< T >:
orcasim::base::UntimedModel orcasim::base::Model

Public Member Functions

 Buffer (std::string name, uint32_t capacity)
 Constructor. More...
 
 ~Buffer ()
 Destructor. More...
 
top ()
 Peeks at the top of the buffer. More...
 
void pop ()
 Removes the object at the front of the buffer. More...
 
uint32_t full ()
 Returns TRUE when the buffer is full. More...
 
void push (T)
 Pushes an object to the back of the buffer. More...
 
uint32_t capacity ()
 Returns max size of the buffer. More...
 
uint32_t size ()
 Counts elements from the buffer. More...
 
a name that identifies the model, advisably not empty.

Default ctor.

std::string GetName ()
 Getter method for the <_name> field. More...
 
void SetName (std::string s)
 Setter method for the <_name> field. More...
 

Private Attributes

std::string _name
 
std::queue< T > * _queue
 
uint32_t _size
 
uint32_t _capacity
 

Detailed Description

template<typename T>
class orcasim::modeling::Buffer< T >

Author
Anderson Domingues
Date
07/31/18

Definition at line 53 of file Buffer.hpp.

Constructor & Destructor Documentation

§ Buffer()

template<typename T >
Buffer::Buffer ( std::string  name,
uint32_t  capacity 
)

Constructor.

Instantiate a new buffer.

Parameters
name(optional) An arbitrary name for the instance of Buffer.
nameA unique name for the buffer (optional)

Definition at line 35 of file Buffer.cpp.

35  : UntimedModel(name) {
36  _name = name;
37  _size = 0;
38  _queue = new std::queue<T>();
40 }
UntimedModel(std::string name)
Default Ctor.
uint32_t capacity()
Returns max size of the buffer.
Definition: Buffer.cpp:91
std::queue< T > * _queue
Definition: Buffer.hpp:56

§ ~Buffer()

template<typename T >
Buffer::~Buffer ( )

Destructor.

Dtor.

Cleans dynamic allocated memory before disposing the object.

Definition at line 46 of file Buffer.cpp.

46  {
47  // the underlying queue is the only object
48  // with dynamic allocation
49  delete(_queue);
50 }
std::queue< T > * _queue
Definition: Buffer.hpp:56

Member Function Documentation

§ capacity()

template<typename T >
uint32_t Buffer::capacity ( )

Returns max size of the buffer.

Return the next element to be popped from the buffer.

Returns
the element

Definition at line 91 of file Buffer.cpp.

91  {
92  return _capacity;
93 }

§ full()

template<typename T >
uint32_t Buffer::full ( )

Returns TRUE when the buffer is full.

Return the number of elements store into underlying container.

Returns
Number of elements

Definition at line 118 of file Buffer.cpp.

118  {
119  return _size == _capacity;
120 }

§ GetName()

std::string Model::GetName ( )
inherited

Getter method for the <_name> field.

Definition at line 34 of file Model.cpp.

34  {
35  return _name;
36 }
std::string _name
A name for the model.
Definition: Model.hpp:47

§ pop()

template<typename T >
void Buffer::pop ( )

Removes the object at the front of the buffer.

Remove the element at the top of the buffer.

Definition at line 56 of file Buffer.cpp.

56  {
57  // prevents underflow
58  #ifdef BUFFER_UNDERFLOW_CHECKING
59  if (_size == 0) {
60  throw std::runtime_error(this->GetName() +
61  ": unable to pop from an empty queue");
62  }
63  #endif
64 
65  _size--;
66  _queue->pop();
67 }
std::string GetName()
Getter method for the <_name> field.
Definition: Model.cpp:34
std::queue< T > * _queue
Definition: Buffer.hpp:56

§ push()

template<typename T>
void Buffer::push ( e)

Pushes an object to the back of the buffer.

Push an element to the bottom of the buffer.

Parameters
e

Definition at line 74 of file Buffer.cpp.

74  {
75  #ifdef BUFFER_OVERFLOW_CHECKING
76  // prevents overflow
77  if (_size == _capacity)
78  throw std::runtime_error(this->GetName() +
79  ": unable to push to a full queue.");
80  #endif
81 
82  _size++;
83  _queue->push(e);
84 }
std::string GetName()
Getter method for the <_name> field.
Definition: Model.cpp:34
std::queue< T > * _queue
Definition: Buffer.hpp:56

§ SetName()

void Model::SetName ( std::string  s)
inherited

Setter method for the <_name> field.

Parameters
sValue to be set

Definition at line 38 of file Model.cpp.

38  {
39  _name = name;
40 }
std::string _name
A name for the model.
Definition: Model.hpp:47

§ size()

template<typename T >
uint32_t Buffer::size ( )

Counts elements from the buffer.

Return the number of elements store into underlying container.

Returns
The number of elements.
Number of elements

Definition at line 109 of file Buffer.cpp.

109  {
110  return _size;
111 }

§ top()

template<typename T >
T Buffer::top ( )

Peeks at the top of the buffer.

Return the next element to be popped from the buffer.

Returns
The object at the top of the buffer.
the element

Definition at line 100 of file Buffer.cpp.

100  {
101  return _queue->front();
102 }
std::queue< T > * _queue
Definition: Buffer.hpp:56

Member Data Documentation

§ _capacity

template<typename T>
uint32_t orcasim::modeling::Buffer< T >::_capacity
private

Definition at line 58 of file Buffer.hpp.

§ _name

template<typename T>
std::string orcasim::modeling::Buffer< T >::_name
private

Definition at line 55 of file Buffer.hpp.

§ _queue

template<typename T>
std::queue<T>* orcasim::modeling::Buffer< T >::_queue
private

Definition at line 56 of file Buffer.hpp.

§ _size

template<typename T>
uint32_t orcasim::modeling::Buffer< T >::_size
private

Definition at line 57 of file Buffer.hpp.


The documentation for this class was generated from the following files: