/*************************************************************************
File: status.h
Description: This file contains the header defintiopn for the Status class.
   The Status class is used to pass, not only an integer return, but a
   possible text string back as well. This is done so that lower level
   functions can build error messages to be augmented/reported by their
   caller. Its design is based on that fact that the String being passed
   should actually be a copy-on-write string where only a pointer is passed
   between temporary instances.
Usage:    Status fn() {
	     Status status=-1;
	     if (error) status = Status(-2,"error message");
	     else status=0;
	     if (!status.isValid()) cerr << status.message() << endl;
	     return status;
	  }
Source(s):
Course Section: Advanced C++ Errors and Exceptions
Author: j. stafford
Date: 970127
*************************************************************************/
#ifndef Status_H
#define Status_H
#include "Common/string.h"

class Status {
private:
   int status_;
   String message_;
public:
   Status(int value=0, const String& message="")
      : status_(value), message_(message) {}
   Status(const Status& s)
      : status_(s.status_), message_(s.message_) {}
   Status& operator=(const Status& s) {
      status_ = s.status_;  message_ = s.message_; return *this;
   }
   int isValid()                 { return status_ >= 0; }
   int status() const            { return status_; }
   void status(int value)        { status_ = value; }
   String message() const        { return message_; }
   void message(const String& m) { message_ = m; }
   operator int() const          { return status(); }
   Status& operator=(int value)  { status(value); return *this; }
};

#endif
//end of file

