orca-sim
Buffer.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of project ORCA. More information on the project
3  * can be found at the following repositories at GitHub's website.
4  *
5  * http://https://github.com/andersondomingues/orca-sim
6  * http://https://github.com/andersondomingues/orca-software
7  * http://https://github.com/andersondomingues/orca-mpsoc
8  * http://https://github.com/andersondomingues/orca-tools
9  *
10  * Copyright (C) 2018-2020 Anderson Domingues, <ti.andersondomingues@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 ******************************************************************************/
26 #ifndef ORCASIM_MODELING_INCLUDE_BUFFER_HPP_
27 #define ORCASIM_MODELING_INCLUDE_BUFFER_HPP_
28 
29 #include <stdint.h>
30 
31 // lib dependent includes
32 #include <iostream>
33 #include <queue>
34 #include <string>
35 
36 // api includes
37 #include "UntimedModel.hpp"
38 
40 
41 namespace orcasim::modeling {
42 
52 template <typename T>
53 class Buffer : public UntimedModel{
54  private:
55  std::string _name;
56  std::queue<T>* _queue;
57  uint32_t _size;
58  uint32_t _capacity;
59 
60  public:
64  Buffer(std::string name, uint32_t capacity);
65 
68  ~Buffer();
69 
73  T top();
74 
77  void pop();
78 
81  uint32_t full();
82 
85  void push(T);
86 
89  uint32_t capacity();
90 
94  uint32_t size();
95 };
96 
97 // Some of the most used instances. More can be added later.
98 template class Buffer<uint8_t>; // mem word
99 template class Buffer<uint16_t>; // dmni/noc word
100 template class Buffer<uint32_t>; // proc word
101 
102 } // namespace orcasim::modeling
103 #endif // ORCASIM_MODELING_INCLUDE_BUFFER_HPP_
void push(T)
Pushes an object to the back of the buffer.
Definition: Buffer.cpp:74
~Buffer()
Destructor.
Definition: Buffer.cpp:46
Buffer(std::string name, uint32_t capacity)
Constructor.
Definition: Buffer.cpp:35
T top()
Peeks at the top of the buffer.
Definition: Buffer.cpp:100
uint32_t full()
Returns TRUE when the buffer is full.
Definition: Buffer.cpp:118
Untimed models represent hardware models whose clock period is irrelevant for the simulation...
uint32_t capacity()
Returns max size of the buffer.
Definition: Buffer.cpp:91
std::queue< T > * _queue
Definition: Buffer.hpp:56
uint32_t size()
Counts elements from the buffer.
Definition: Buffer.cpp:109
void pop()
Removes the object at the front of the buffer.
Definition: Buffer.cpp:56