summaryrefslogtreecommitdiffstats
path: root/tderadio3/src/include/ringbuffer.h
blob: 1f545ca7d97e2b4514244b7c93635f58429ead8a (plain)
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
/***************************************************************************
                          ringbuffer.h  -  description
                             -------------------
    begin                : Sun March 21 2004
    copyright            : (C) 2004 by Martin Witte
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _KRADIO_RING_BUFFER_H
#define _KRADIO_RING_BUFFER_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <sys/types.h>

class RingBuffer
{
public:
    RingBuffer(size_t size);
    ~RingBuffer();

    bool       resize(size_t new_size);

    size_t   addData (const char *src, size_t size);
    size_t   takeData(char *dst, size_t size);

    char      *getFreeSpace(size_t &size);
    size_t     removeFreeSpace(size_t size);

    char      *getData(size_t &size);
    size_t     removeData(size_t size);

    size_t    getSize()     const { return m_Size; }
    size_t    getFillSize() const { return m_FillSize; }
    size_t    getFreeSize() const { return m_Size - m_FillSize; }

    void       clear();

protected:

    char     *m_Buffer;
    size_t    m_Start;
    size_t    m_Size,
              m_FillSize;
};

#endif