#ifndef _INCREMENTALLINE_H
#define _INCREMENTALLINE_H

#include <mbari/types.h>
#include <mbari/const.h>

class IncrementalLine {

 public:

  ///////////////////////////////////////////////////////////////////
  // Following are exception structures, but we don't have
  // exception handling yet! Need gcc 2.8.*
  struct OutOfMemory {

    OutOfMemory(int nc) {
      nChars = nc;
    }

    int nChars;
  };

  struct Complete {

    Complete(int nc) {
      nChars = nc;
    }

    int nChars;
  };


  IncrementalLine();
  
  ~IncrementalLine();

  ///////////////////////////////////////////////////////////////////
  // Add a character to the line. Return -1 if line is already complete,
  // else return 0.
  int addChar(char c); 

  ///////////////////////////////////////////////////////////////////
  // Get ready to start new line
  void reset();

  ///////////////////////////////////////////////////////////////////
  // Return number of characters currently in line buffer
  int nChars() {
    return _nChars;
  }

  ///////////////////////////////////////////////////////////////////
  // Return True if line is complete, else False
  MBool complete() {
    return _complete;
  }

  ///////////////////////////////////////////////////////////////////
  // Return buffer contents
  const char *buf();

 protected:

  char *_buf;
  int _nChars;
  MBool _complete;
  char _endToken;
  int _allocIncr;
  int _nAllocd;
};


#endif
