OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [Fifo.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#pragma once
19
 
20
#include <stdexcept>
21
#include <vector>
22
 
23
template <typename T>
24
class Fifo
25
{
26
public:
27
    explicit Fifo(unsigned int max_depth) : max_depth(max_depth)
28
    {
29
    }
30
 
31
    T pop()
32
    {
33
        if (entries.size() == 0)
34
            throw std::underflow_error("Fifo underflow");
35
 
36
        T e = *entries.begin();
37
        entries.erase(entries.begin());
38
 
39
        return e;
40
    }
41
 
42
    void push(T e)
43
    {
44
        if (is_full())
45
            throw std::overflow_error("Fifo overflow");
46
        entries.push_back(e);
47
    }
48
 
49
    bool is_full() const
50
    {
51
        return entries.size() == max_depth;
52
    }
53
 
54
private:
55
    const unsigned int max_depth;
56
    std::vector<T> entries;
57
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.