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 /// 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 SamStatus 00027 { 00028 public: 00029 00030 /// Return value enum for the SamFile class 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, ///< record is 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(SamStatus::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(SamStatus::Status status); 00054 00055 /// Constructor that takes in the handling type, defaulting it to exception. 00056 SamStatus(ErrorHandler::HandlingType handleType = ErrorHandler::EXCEPTION); 00057 00058 /// Destructor 00059 ~SamStatus(); 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(SamStatus 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 sam status type to the 00086 /// passed in status and to clear the message string. 00087 SamStatus & operator = (Status newStatus); 00088 00089 /// Overload operator != to determine if the passed in type is not equal 00090 /// to this status's type. 00091 bool operator != (const SamStatus::Status& compStatus) const; 00092 00093 /// Overload operator == to determine if the passed in type is equal 00094 /// to this status's type. 00095 bool operator == (const SamStatus::Status& compStatus) const; 00096 00097 private: 00098 // Handle an error based on the error handling type. 00099 void handleError(Status newType, const char* newMessage); 00100 00101 00102 static const char* enumStatusString[]; 00103 00104 Status myType; 00105 std::string myMessage; 00106 ErrorHandler::HandlingType myHandlingType; 00107 }; 00108 00109 00110 #endif