aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/queue.h
blob: 211498b289e5345cd97188f553e1db49ec1f85cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <queue>
#include <cstdint>

namespace mbus {

/**
 * A simple generic queue implementation that is not thread-safe. The
 * API is similar to that of std::queue.
 **/
template <class T>
class Queue
{
private:
    std::queue<T> _queue;

public:
    /**
     * Create an empty Queue.
     **/
    Queue() : _queue() {}

    /**
     * Obtain the size of this queue. The size denotes the number of
     * elements currently on the queue.
     *
     * @return size current queue size
     **/
    uint32_t size() const {
        return _queue.size();
    }

    /**
     * Access the element located at the front of the queue. This
     * method yields undefined behavior if the queue is empty.
     *
     * @return element at the front of this queue
     **/
    T &front() {
        return _queue.front();
    }

    /**
     * Push an element to the back of this queue.
     *
     * @param val the element value
     **/
    void push(const T &val) {
        _queue.push(val);
    }

    /**
     * Pop the front element from this queue. This method yields
     * undefined behavior if the queue is empty.
     **/
    void pop() {
        _queue.pop();
    }
};

} // namespace mbus