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