Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * qa_dynamic_buffer.cpp - Fawkes QA DynamicBuffer 00004 * 00005 * Created: Fri Jun 1 16:03:26 2007 00006 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 /// @cond QA 00025 00026 #include <netcomm/utils/dynamic_buffer.h> 00027 00028 #include <iostream> 00029 #include <cstring> 00030 #include <cstdio> 00031 00032 using namespace std; 00033 using namespace fawkes; 00034 00035 int 00036 main(int argc, char **argv) 00037 { 00038 00039 dynamic_list_t dl; 00040 DynamicBuffer *dw = new DynamicBuffer(&dl); 00041 00042 for ( unsigned int i = 0; i < 1000; ++i ) { 00043 dw->append("test", strlen("test")); 00044 } 00045 00046 cout << "Added elements, num_elements: " << dw->num_elements() 00047 << ", buffer_size: " << dw->buffer_size() 00048 << ", real_buffer_size: " << dw->real_buffer_size() << endl; 00049 00050 DynamicBuffer *dr = new DynamicBuffer(&dl, dw->buffer(), dw->buffer_size()); 00051 00052 cout << "Read buffer opened, num_elements: " << dr->num_elements() 00053 << ", buffer_size: " << dr->buffer_size() 00054 << ", real_buffer_size: " << dr->real_buffer_size() << endl; 00055 00056 while ( dr->has_next() ) { 00057 char tmp[1024]; 00058 memset(tmp, 0, sizeof(tmp)); 00059 size_t size; 00060 void *buf = dr->next(&size); 00061 strncpy(tmp, (const char *)buf, size); 00062 printf("Read string (%lu bytes): '%s'\n", (unsigned long int)size, tmp); 00063 } 00064 00065 delete dw; 00066 delete dr; 00067 } 00068 00069 /// @endcond