libStatGen Software  1
GlfStatus.cpp
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 #include "GlfStatus.h"
00019 
00020 const char* GlfStatus::enumStatusString[] = {
00021     "SUCCESS",
00022     "UNKNOWN",
00023     "FAIL_IO",
00024     "FAIL_ORDER",
00025     "FAIL_PARSE",
00026     "INVALID", 
00027     "FAIL_MEM"
00028 };
00029 
00030 
00031 const char* GlfStatus::getStatusString(GlfStatus::Status statusEnum)
00032 {
00033     return(enumStatusString[statusEnum]);
00034 }
00035 
00036 
00037 // Returns whether or not it is "safe" to keep processing the file
00038 // after the specified status return.
00039 bool GlfStatus::isContinuableStatus(GlfStatus::Status status)
00040 {
00041     if(status == GlfStatus::SUCCESS || status == GlfStatus::FAIL_PARSE || 
00042        status == GlfStatus::INVALID)
00043     {
00044         // The status is such that file processing can continue.
00045         return(true);
00046     }
00047     // UNKNOWN, FAIL_IO, FAIL_ORDER, FAIL_MEM
00048     return(false);
00049 }
00050 
00051 
00052 // Constructor
00053 GlfStatus::GlfStatus()
00054 {
00055     reset();
00056 }
00057 
00058    
00059 // Destructor
00060 GlfStatus::~GlfStatus()
00061 {
00062 }
00063 
00064 
00065 // Resets this status.
00066 void GlfStatus::reset()
00067 {
00068     myType = UNKNOWN;
00069     myMessage = "";
00070 }
00071 
00072 
00073 // Set the status with the specified values.
00074 void GlfStatus::setStatus(Status newStatus, const char* newMessage)
00075 {
00076     myType = newStatus;
00077     myMessage = getStatusString(newStatus);
00078     myMessage += ": ";
00079     myMessage += newMessage;
00080 }
00081 
00082 
00083 // Adds the specified error message to the status message.
00084 // Sets the status to newStatus if the current status is SUCCESS.
00085 void GlfStatus::addError(Status newStatus, const char* newMessage)
00086 {
00087     if(myType == GlfStatus::SUCCESS)
00088     {
00089         myType = newStatus;
00090     }
00091     else
00092     {
00093         myMessage += "\n";
00094     }
00095     myMessage += getStatusString(newStatus);
00096     myMessage += ": ";
00097     myMessage += newMessage;
00098 }
00099 
00100 
00101 // Adds the specified status to the status message.
00102 // Sets the status to newStatus if the current status is SUCCESS.
00103 void GlfStatus::addError(GlfStatus newStatus)
00104 {
00105     if(myType == GlfStatus::SUCCESS)
00106     {
00107         myType = newStatus.myType;
00108     }
00109     else
00110     {
00111         myMessage += "\n";
00112     }
00113     myMessage += newStatus.myMessage;
00114 }
00115 
00116 
00117 // Return the enum for this status.
00118 GlfStatus::Status GlfStatus::getStatus() const
00119 {
00120     return(myType);
00121 }
00122 
00123 
00124 // Return the status message.
00125 const char* GlfStatus::getStatusMessage() const
00126 {
00127     return(myMessage.c_str());
00128 }
00129 
00130 
00131 // Overload operator = to set the glf status type to the
00132 // passed in status and to clear the message string.
00133 GlfStatus & GlfStatus::operator = (GlfStatus::Status newStatus)
00134 {
00135     reset();
00136     myType = newStatus;
00137     return(*this);
00138 }
00139 
00140 // Overload operator != to determine if the passed in type is not equal
00141 // to this status's type.
00142 bool GlfStatus::operator != (const GlfStatus::Status& compStatus) const
00143 {
00144     return(compStatus != myType);
00145 }
00146 // Overload operator != to determine if the passed in type is equal
00147 // to this status's type.
00148 bool GlfStatus::operator == (const GlfStatus::Status& compStatus) const
00149 {
00150     return(compStatus == myType);
00151 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends