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 <iostream>
29 #include <cstring>
30 #include <cstdio>
31 
32 using namespace std;
33 using namespace fawkes;
34 
35 int
36 main(int argc, char **argv)
37 {
38 
39  dynamic_list_t dl;
40  DynamicBuffer *dw = new DynamicBuffer(&dl);
41 
42  for ( unsigned int i = 0; i < 1000; ++i ) {
43  dw->append("test", strlen("test"));
44  }
45 
46  cout << "Added elements, num_elements: " << dw->num_elements()
47  << ", buffer_size: " << dw->buffer_size()
48  << ", real_buffer_size: " << dw->real_buffer_size() << endl;
49 
50  DynamicBuffer *dr = new DynamicBuffer(&dl, dw->buffer(), dw->buffer_size());
51 
52  cout << "Read buffer opened, num_elements: " << dr->num_elements()
53  << ", buffer_size: " << dr->buffer_size()
54  << ", real_buffer_size: " << dr->real_buffer_size() << endl;
55 
56  while ( dr->has_next() ) {
57  char tmp[1024];
58  memset(tmp, 0, sizeof(tmp));
59  size_t size;
60  void *buf = dr->next(&size);
61  strncpy(tmp, (const char *)buf, size);
62  printf("Read string (%lu bytes): '%s'\n", (unsigned long int)size, tmp);
63  }
64 
65  delete dw;
66  delete dr;
67 }
68 
69 /// @endcond
unsigned int num_elements()
Get number of elements.
Fawkes library namespace.
void * buffer()
Get pointer to buffer.
STL namespace.
Dynamic list type.
bool has_next()
Check if another element is available.
size_t buffer_size()
Get buffer size.
size_t real_buffer_size()
Get real buffer size.
Dynamically growing buffer.
void append(const void *data, size_t data_size)
Append data.
void * next(size_t *size)
Get next buffer.