00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef __GLF_STATUS_H__ 00019 #define __GLF_STATUS_H__ 00020 00021 #include <iostream> 00022 00023 class GlfStatus 00024 { 00025 public: 00026 00027 // Return value enum for the GlfFile class methods. 00028 // SUCCESS : method completed successfully. 00029 // UNKNOWN : unknown result (default value should never be used) 00030 // FAIL_IO : method failed due to an I/O issue. 00031 // FAIL_ORDER : method failed because it was called out of order, 00032 // like trying to read a file without opening it for 00033 // read or trying to read a record before the header. 00034 // FAIL_PARSE : failed to parse a record/header - invalid format. 00035 // INVALID : invalid. 00036 // FAIL_MEM : fail a memory allocation. 00037 enum Status {SUCCESS = 0, UNKNOWN, FAIL_IO, FAIL_ORDER, 00038 FAIL_PARSE, INVALID, FAIL_MEM}; 00039 00040 static const char* getStatusString(GlfStatus::Status statusEnum); 00041 00042 // Returns whether or not it is "safe" to keep processing the file 00043 // after the specified status return. 00044 static bool isContinuableStatus(GlfStatus::Status status); 00045 00046 // Constructor 00047 GlfStatus(); 00048 00049 // Destructor 00050 ~GlfStatus(); 00051 00052 // Resets this status. 00053 void reset(); 00054 00055 // Set the status with the specified values. 00056 void setStatus(Status newStatus, const char* newMessage); 00057 00058 // Adds the specified error message to the status message. 00059 // Sets the status to newStatus if the current status is SUCCESS. 00060 void addError(Status newStatus, const char* newMessage); 00061 00062 00063 // Adds the specified status to the status message. 00064 // Sets the status to newStatus if the current status is SUCCESS. 00065 void addError(GlfStatus newStatus); 00066 00067 // Return the enum for this status. 00068 Status getStatus() const; 00069 00070 // Return the status message. 00071 const char* getStatusMessage() const; 00072 00073 // Overload operator = to set the glf status type to the 00074 // passed in status and to clear the message string. 00075 GlfStatus & operator = (Status newStatus); 00076 00077 // // Overload operator = to set the glf status. 00078 // GlfStatus & operator = (GlfStatus newStatus); 00079 00080 // Overload operator != to determine if the passed in type is not equal 00081 // to this status's type. 00082 bool operator != (const GlfStatus::Status& compStatus) const; 00083 00084 // Overload operator != to determine if the passed in type is equal 00085 // to this status's type. 00086 bool operator == (const GlfStatus::Status& compStatus) const; 00087 00088 private: 00089 static const char* enumStatusString[]; 00090 00091 Status myType; 00092 std::string myMessage; 00093 }; 00094 00095 #endif