#ifndef __DATABUFFER_H__
#define __DATABUFFER_H__

#include <vector>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/// buffers data into memory
/**
 * Allows for random access and incremental appending
 */
class databuffer
{
 public:
  databuffer();
  ~databuffer();
  int append(char *d, int size);
  int append( databuffer &b );
  int size();
  int consolidate();
  char *getptr();

  char &operator[] (int off);
  const char &operator[] (int off) const;

  int clear();
 private:
  struct dataseg
  {
    char *data;
    int size;
  };
  std::vector< dataseg > data;
  int totalsize;
};

#endif
