Fawkes API Fawkes Development Version
qa_dynamic_buffer.cpp
1
2/***************************************************************************
3 * qa_dynamic_buffer.cpp - Fawkes QA DynamicBuffer
4 *
5 * Created: Fri Jun 1 16:03:26 2007
6 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24/// @cond QA
25
26#include <netcomm/utils/dynamic_buffer.h>
27
28#include <cstdio>
29#include <cstring>
30#include <iostream>
31
32using namespace std;
33using namespace fawkes;
34
35int
36main(int argc, char **argv)
37{
39 DynamicBuffer *dw = new DynamicBuffer(&dl);
40
41 for (unsigned int i = 0; i < 1000; ++i) {
42 dw->append("test", strlen("test"));
43 }
44
45 cout << "Added elements, num_elements: " << dw->num_elements()
46 << ", buffer_size: " << dw->buffer_size() << ", real_buffer_size: " << dw->real_buffer_size()
47 << endl;
48
49 DynamicBuffer *dr = new DynamicBuffer(&dl, dw->buffer(), dw->buffer_size());
50
51 cout << "Read buffer opened, num_elements: " << dr->num_elements()
52 << ", buffer_size: " << dr->buffer_size() << ", real_buffer_size: " << dr->real_buffer_size()
53 << endl;
54
55 while (dr->has_next()) {
56 char tmp[1024];
57 memset(tmp, 0, sizeof(tmp));
58 size_t size;
59 void * buf = dr->next(&size);
60 strncpy(tmp, (const char *)buf, size);
61 printf("Read string (%lu bytes): '%s'\n", (unsigned long int)size, tmp);
62 }
63
64 delete dw;
65 delete dr;
66}
67
68/// @endcond
Dynamically growing buffer.
size_t buffer_size()
Get buffer size.
void append(const void *data, size_t data_size)
Append data.
bool has_next()
Check if another element is available.
unsigned int num_elements()
Get number of elements.
void * next(size_t *size)
Get next buffer.
size_t real_buffer_size()
Get real buffer size.
void * buffer()
Get pointer to buffer.
Fawkes library namespace.
Dynamic list type.