#include <iostream>
#include <sstream>
#include <string>

// ----- Definitions from the general purpose library -----
// This is the C-based XML parser object
struct XmlParser
{
int dummy;
};

// The read function our parser uses to get more data
typedef int (*xmlReadFn)(void* user_data, char* s, int len);

#define BUF_SIZE 5

// The parse function for our parser
void xmlParse(XmlParser* parser, xmlReadFn read_fn, void* user_data)
{
   char buf[BUF_SIZE];
   int read_len;
   do
   {
      read_len = read_fn(user_data, buf, BUF_SIZE);
      // Here I'm just printing out what we read, one chunk per line
      std::string str(buf, read_len);
      std::cout << str << std::endl;
   }
   while (read_len == BUF_SIZE);
}

// ----- Our implementation -----

// This is our implementation of the xmlReadFn function
int readFromStream(void* user_data, char* s, int len)
{
   std::istream* str = (std::istream*)user_data;
   return str->readsome(s, len);
}

int main()
{
   // Allocate the parser
   XmlParser parser;

   // Construct the stream we want to read from. Normally, this would come from a file
   std::stringstream str("The quick brown fox ran over the lazy dog.");

   xmlParse(&parser, readFromStream, &str);

   return 0;
}