Fawkes API Fawkes Development Version
dynamic_buffer.h
1
2/***************************************************************************
3 * dynamic_buffer.h - A dynamic buffer
4 *
5 * Created: Fri Jun 01 13:28:02 2007
6 * Copyright 2007-2008 Tim Niemueller [www.niemueller.de]
7 * 2007 Daniel Beck
8 *
9 ****************************************************************************/
10
11/* This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. A runtime exception applies to
15 * this software (see LICENSE.GPL_WRE file mentioned below for details).
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 Library General Public License for more details.
21 *
22 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23 */
24
25#ifndef _NETCOMM_UTILS_DYNAMIC_BUFFER_H_
26#define _NETCOMM_UTILS_DYNAMIC_BUFFER_H_
27
28#include <sys/types.h>
29
30#include <stdint.h>
31
32namespace fawkes {
33
34#pragma pack(push, 4)
35
36/** Dynamic list type.
37 * Use this element in your message struct if you want to add a dynamic list.
38 * This is meant to be used in conjunction with DynamicBuffer.
39 */
40typedef struct
41{
42 uint32_t size; /**< total size of list buffer */
43 uint32_t num_elements; /**< number of elements in list */
45
46#pragma pack(pop)
47
49{
50public:
51 DynamicBuffer(dynamic_list_t *db, size_t initial_buffer_size = 1024);
52 DynamicBuffer(dynamic_list_t *db, void *buf, size_t size);
53 virtual ~DynamicBuffer();
54
55 void append(const void *data, size_t data_size);
56 void * buffer();
57 size_t buffer_size();
58 unsigned int num_elements();
59
60 size_t real_buffer_size();
61
62 bool has_next();
63 void *next(size_t *size);
64 void reset_iterator();
65
66private:
67 typedef uint16_t element_header_t;
68
69 void increase();
70
71 bool _read_only;
72
73 dynamic_list_t * _db;
74 void * _buffer;
75 size_t _buffer_size;
76 element_header_t *_curhead;
77 void * _curdata;
78
79 uint16_t _it_curel;
80 element_header_t *_it_curhead;
81 void * _it_curdata;
82};
83
84} // end namespace fawkes
85
86#endif
Dynamically growing buffer.
size_t buffer_size()
Get buffer size.
void append(const void *data, size_t data_size)
Append data.
void reset_iterator()
Reset iterator.
bool has_next()
Check if another element is available.
unsigned int num_elements()
Get number of elements.
virtual ~DynamicBuffer()
Destructor.
void * next(size_t *size)
Get next buffer.
size_t real_buffer_size()
Get real buffer size.
DynamicBuffer(dynamic_list_t *db, size_t initial_buffer_size=1024)
Write constructor.
void * buffer()
Get pointer to buffer.
Fawkes library namespace.
Dynamic list type.
uint32_t num_elements
number of elements in list
uint32_t size
total size of list buffer