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 __SAM_STATUS_H__ 00019 #define __SAM_STATUS_H__ 00020 00021 #include <iostream> 00022 #include "ErrorHandler.h" 00023 00024 class SamStatus 00025 { 00026 public: 00027 00028 // Return value enum for the SamFile class methods. 00029 // SUCCESS : method completed successfully. 00030 // UNKNOWN : unknown result (default value should never be used) 00031 // NO_MORE_RECS : failed to read a record since there are no more to read 00032 // either in the file or section if section based reading. 00033 // FAIL_IO : method failed due to an I/O issue. 00034 // FAIL_ORDER : method failed because it was called out of order, 00035 // like trying to read a file without opening it for 00036 // read or trying to read a record before the header. 00037 // FAIL_PARSE : failed to parse a record/header - invalid format. 00038 // INVALID_SORT : record is invalid due to it not being sorted. 00039 // INVALID : record is invalid other than for sorting. 00040 // FAIL_MEM : fail a memory allocation. 00041 enum Status {SUCCESS = 0, UNKNOWN, NO_MORE_RECS, FAIL_IO, FAIL_ORDER, 00042 FAIL_PARSE, INVALID_SORT, INVALID, FAIL_MEM}; 00043 00044 static const char* getStatusString(SamStatus::Status statusEnum); 00045 00046 // Returns whether or not it is "safe" to keep processing the file 00047 // after the specified status return. 00048 static bool isContinuableStatus(SamStatus::Status status); 00049 00050 // Constructor 00051 SamStatus(ErrorHandler::HandlingType handleType = ErrorHandler::EXCEPTION); 00052 00053 // Destructor 00054 ~SamStatus(); 00055 00056 // Resets this status. 00057 void reset(); 00058 00059 void setHandlingType(ErrorHandler::HandlingType handleType); 00060 00061 // Set the status with the specified values. 00062 void setStatus(Status newStatus, const char* newMessage); 00063 00064 // Adds the specified error message to the status message. 00065 // Sets the status to newStatus if the current status is SUCCESS. 00066 void addError(Status newStatus, const char* newMessage); 00067 00068 00069 // Adds the specified status to the status message. 00070 // Sets the status to newStatus if the current status is SUCCESS. 00071 void addError(SamStatus newStatus); 00072 00073 // Return the enum for this status. 00074 Status getStatus() const; 00075 00076 // Return the status message. 00077 const char* getStatusMessage() const; 00078 00079 // Overload operator = to set the sam status type to the 00080 // passed in status and to clear the message string. 00081 SamStatus & operator = (Status newStatus); 00082 00083 // // Overload operator = to set the sam status. 00084 // SamStatus & operator = (SamStatus newStatus); 00085 00086 // Overload operator != to determine if the passed in type is not equal 00087 // to this status's type. 00088 bool operator != (const SamStatus::Status& compStatus) const; 00089 00090 // Overload operator == to determine if the passed in type is equal 00091 // to this status's type. 00092 bool operator == (const SamStatus::Status& compStatus) const; 00093 00094 private: 00095 // Handle an error based on the error handling type. 00096 void handleError(Status newType, const char* newMessage); 00097 00098 00099 static const char* enumStatusString[]; 00100 00101 Status myType; 00102 std::string myMessage; 00103 ErrorHandler::HandlingType myHandlingType; 00104 }; 00105 00106 00107 #endif