StatGenStatus.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "StatGenStatus.h"
00019
00020 const char* StatGenStatus::enumStatusString[] = {
00021 "SUCCESS",
00022 "UNKNOWN",
00023 "NO_MORE_RECS",
00024 "FAIL_IO",
00025 "FAIL_ORDER",
00026 "FAIL_PARSE",
00027 "INVALID_SORT",
00028 "INVALID",
00029 "FAIL_MEM"
00030 };
00031
00032
00033 const char* StatGenStatus::getStatusString(StatGenStatus::Status statusEnum)
00034 {
00035 return(enumStatusString[statusEnum]);
00036 }
00037
00038
00039
00040
00041 bool StatGenStatus::isContinuableStatus(StatGenStatus::Status status)
00042 {
00043 if(status == StatGenStatus::SUCCESS || status == StatGenStatus::FAIL_PARSE ||
00044 status == StatGenStatus::INVALID_SORT || status == StatGenStatus::INVALID)
00045 {
00046
00047 return(true);
00048 }
00049
00050 return(false);
00051 }
00052
00053
00054
00055 StatGenStatus::StatGenStatus(ErrorHandler::HandlingType handleType)
00056 : myHandlingType(handleType)
00057 {
00058 reset();
00059 }
00060
00061
00062
00063 StatGenStatus::~StatGenStatus()
00064 {
00065 }
00066
00067
00068
00069 void StatGenStatus::reset()
00070 {
00071 myType = UNKNOWN;
00072 myMessage.clear();
00073 }
00074
00075
00076 void StatGenStatus::setHandlingType(ErrorHandler::HandlingType handleType)
00077 {
00078 myHandlingType = handleType;
00079 }
00080
00081
00082
00083 void StatGenStatus::setStatus(Status newStatus, const char* newMessage)
00084 {
00085 myType = newStatus;
00086 myMessage = getStatusString(newStatus);
00087 myMessage += ": ";
00088 myMessage += newMessage;
00089
00090 if(newStatus != SUCCESS)
00091 {
00092 handleError(newStatus, newMessage);
00093 }
00094 }
00095
00096
00097
00098
00099 void StatGenStatus::addError(Status newStatus, const char* newMessage)
00100 {
00101 if(myType == StatGenStatus::SUCCESS)
00102 {
00103 myType = newStatus;
00104 }
00105 else
00106 {
00107 myMessage += "\n";
00108 }
00109 myMessage += getStatusString(newStatus);
00110 myMessage += ": ";
00111 myMessage += newMessage;
00112
00113 if(newStatus != SUCCESS)
00114 {
00115 handleError(newStatus, newMessage);
00116 }
00117 }
00118
00119
00120
00121
00122 void StatGenStatus::addError(StatGenStatus newStatus)
00123 {
00124 if(myType == StatGenStatus::SUCCESS)
00125 {
00126 myType = newStatus.myType;
00127 }
00128 else
00129 {
00130 myMessage += "\n";
00131 }
00132 myMessage += newStatus.myMessage;
00133
00134 if(newStatus != SUCCESS)
00135 {
00136 handleError(newStatus.myType, newStatus.myMessage.c_str());
00137 }
00138 }
00139
00140
00141
00142 StatGenStatus::Status StatGenStatus::getStatus() const
00143 {
00144 return(myType);
00145 }
00146
00147
00148
00149 const char* StatGenStatus::getStatusMessage() const
00150 {
00151 return(myMessage.c_str());
00152 }
00153
00154
00155
00156
00157 StatGenStatus & StatGenStatus::operator = (StatGenStatus::Status newStatus)
00158 {
00159 myType = newStatus;
00160 myMessage.clear();
00161
00162 if(newStatus != SUCCESS)
00163 {
00164 handleError(newStatus, "");
00165 }
00166 return(*this);
00167 }
00168
00169
00170
00171 StatGenStatus & StatGenStatus::operator = (StatGenStatus newStatus)
00172 {
00173 myType = newStatus.myType;
00174 myMessage = newStatus.myMessage;
00175 myHandlingType = newStatus.myHandlingType;
00176 return(*this);
00177 }
00178
00179
00180
00181
00182 bool StatGenStatus::operator != (const StatGenStatus::Status& compStatus) const
00183 {
00184 return(compStatus != myType);
00185 }
00186
00187
00188
00189
00190 bool StatGenStatus::operator == (const StatGenStatus::Status& compStatus) const
00191 {
00192 return(compStatus == myType);
00193 }
00194
00195
00196 void StatGenStatus::handleError(Status newStatus, const char* newMessage)
00197 {
00198
00199
00200 if((newStatus != SUCCESS) && (newStatus != NO_MORE_RECS))
00201 {
00202 std::string message = getStatusString(newStatus);
00203 message += ": ";
00204 message += newMessage;
00205
00206 ErrorHandler::handleError(message.c_str(), myHandlingType);
00207 }
00208 }