#ifndef _ERRORHANDLER_H
#define _ERRORHANDLER_H
static char ErrorHandler_h_id[] = "$Header: /usr/tiburon/xPlatform/utils/RCS/ErrorHandler.h,v 1.3 1997/08/06 09:24:45 oreilly Exp pean $";

/*
$Log: ErrorHandler.h,v $
Revision 1.3  1997/08/06 09:24:45  oreilly
Added documentation

 * Revision 1.2  97/03/20  12:26:57  12:26:57  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
 * Revision 1.1  96/07/22  11:27:47  11:27:47  oreilly (Thomas C. O'Reilly)
 * Initial revision
 * 
*/

#include <stdio.h>
#include <string.h>
#include <mbariTypes.h>
#include <mbariConst.h>

const int errorMsgSize = 512;

/*
CLASS 
ErrorHandler

DESCRIPTION
ErrorHandler keeps track of error state (True or False) and an error message
string. Typically a class will be subclassed from ErrorHandler and at least 
one other class. It's especially useful in environments where C++ exceptions 
are not implemented. 

AUTHOR
Tom O'Reilly
*/
class ErrorHandler
{  
  protected:
  
  MBool _error;
  char _error_buf[errorMsgSize];

  public:
  
  ///////////////////////////////////////////////////////////////////
  // Set error state to True, and set error message string
  void setError(char *msg)
  {
    _error = TRUE;
    strcpy(_error_buf, msg);
  }
  

  ///////////////////////////////////////////////////////////////////
  // Set error state to False
  void clearError() 
  {
    _error = FALSE;
  }

  ///////////////////////////////////////////////////////////////////
  // Return error state
  MBool error()
  {
    return _error;
  }
  
  ///////////////////////////////////////////////////////////////////
  // Retrieve error message string
  void errorMsg(char *buf)
  {
    strcpy(buf, _error_buf);
  }

  ///////////////////////////////////////////////////////////////////
  // Print error message string to stderr
  void prtErrorMsg()
  {
    fprintf(stderr, "%s\n", _error_buf);
  }

  ErrorHandler() 
  {
    _error = FALSE;
  }
  
};


#endif
