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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [include/] [ustl/] [uqueue.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#ifndef UQUEUE_H_27F01FDB0D59B75277E0E5C41ABC6B5B
7
#define UQUEUE_H_27F01FDB0D59B75277E0E5C41ABC6B5B
8
 
9
namespace ustl {
10
 
11
/// \class queue uqueue.h ustl.h
12
/// \ingroup Sequences
13
///
14
/// \brief Queue adapter to uSTL containers.
15
///
16
/// The most efficient way to use this implementation is to fill the queue
17
/// and the completely empty it before filling again.
18
///
19
template <typename T>
20
class queue {
21
public:
22
    typedef T                   value_type;
23
    typedef size_t              size_type;
24
    typedef ptrdiff_t           difference_type;
25
    typedef T&                  reference;
26
    typedef const T&            const_reference;
27
    typedef T*                  pointer;
28
    typedef const T*            const_pointer;
29
public:
30
    inline                      queue (void)                    : m_Storage (), m_Front (0) { }
31
    explicit inline             queue (const vector<T>& s)      : m_Storage (s), m_Front (0) { }
32
    explicit inline             queue (const queue& s)          : m_Storage (s.m_Storage), m_Front (0) { }
33
    inline size_type            size (void) const               { return (m_Storage.size() - m_Front); }
34
    inline bool                 empty (void) const              { return (!size()); }
35
    inline reference            front (void)                    { return (m_Storage [m_Front]); }
36
    inline const_reference      front (void) const              { return (m_Storage [m_Front]); }
37
    inline reference            back (void)                     { return (m_Storage.back()); }
38
    inline const_reference      back (void) const               { return (m_Storage.back()); }
39
    inline void                 push (const value_type& v);
40
    inline void                 pop (void);
41
    inline bool                 operator== (const queue& s) const       { return (m_Storage == s.m_Storage && m_Front == s.m_Front); }
42
    inline bool                 operator< (const queue& s) const        { return (size() < s.size()); }
43
private:
44
    vector<T>                   m_Storage;      ///< Where the data actually is.
45
    size_type                   m_Front;        ///< Index of the element returned by next pop.
46
};
47
 
48
/// Pushes \p v on the queue.
49
template <typename T>
50
inline void queue<T>::push (const value_type& v)
51
{
52
    if (m_Front) {
53
        m_Storage.erase (m_Storage.begin(), m_Front);
54
        m_Front = 0;
55
    }
56
    m_Storage.push_back (v);
57
}
58
 
59
/// Pops the topmost element from the queue.
60
template <typename T>
61
inline void queue<T>::pop (void)
62
{
63
    if (++m_Front >= m_Storage.size())
64
        m_Storage.resize (m_Front = 0);
65
}
66
 
67
} // namespace ustl
68
 
69
#endif

powered by: WebSVN 2.1.0

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