qa_dynamic_buffer.cpp

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
00031 using namespace std;
00032 using namespace fawkes;
00033
00034 int
00035 main(int argc, char **argv)
00036 {
00037
00038   dynamic_list_t dl;
00039   DynamicBuffer *dw = new DynamicBuffer(&dl);
00040
00041   for ( unsigned int i = 0; i < 1000; ++i ) {
00042     dw->append("test", strlen("test"));
00043   }
00044
00045   cout << "Added elements, num_elements: " << dw->num_elements()
00046        << ", buffer_size: " << dw->buffer_size()
00047        << ", real_buffer_size: " << dw->real_buffer_size() << endl;
00048
00049   DynamicBuffer *dr = new DynamicBuffer(&dl, dw->buffer(), dw->buffer_size());
00050
00051   cout << "Read buffer opened, num_elements: " << dr->num_elements()
00052        << ", buffer_size: " << dr->buffer_size()
00053        << ", real_buffer_size: " << dr->real_buffer_size() << endl;
00054
00055   while ( dr->has_next() ) {
00056     char tmp[1024];
00057     memset(tmp, 0, sizeof(tmp));
00058     size_t size;
00059     void *buf = dr->next(&size);
00060     strncpy(tmp, (const char *)buf, size);
00061     printf("Read string (%lu bytes): '%s'\n", (unsigned long int)size, tmp);
00062   }
00063
00064   delete dw;
00065   delete dr;
00066 }
00067 
00068 /// @endcond