StatGenStatus.cpp
/*
* Copyright (C) 2010-2011 Regents of the University of Michigan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StatGenStatus.h"
const char* StatGenStatus::enumStatusString[] = {
"SUCCESS",
"UNKNOWN",
"NO_MORE_RECS",
"FAIL_IO",
"FAIL_ORDER",
"FAIL_PARSE",
"INVALID_SORT",
"INVALID",
"FAIL_MEM"
};
const char* StatGenStatus::getStatusString(StatGenStatus::Status statusEnum)
{
return(enumStatusString[statusEnum]);
}
// Returns whether or not it is "safe" to keep processing the file
// after the specified status return.
bool StatGenStatus::isContinuableStatus(StatGenStatus::Status status)
{
if(status == StatGenStatus::SUCCESS || status == StatGenStatus::FAIL_PARSE ||
status == StatGenStatus::INVALID_SORT || status == StatGenStatus::INVALID)
{
// The status is such that file processing can continue.
return(true);
}
// UNKNOWN, NO_MORE_RECS, FAIL_IO, FAIL_ORDER, FAIL_MEM
return(false);
}
// Constructor
StatGenStatus::StatGenStatus(ErrorHandler::HandlingType handleType)
: myHandlingType(handleType)
{
reset();
}
// Destructor
StatGenStatus::~StatGenStatus()
{
}
// Resets this status.
void StatGenStatus::reset()
{
myType = UNKNOWN;
myMessage.clear();
}
void StatGenStatus::setHandlingType(ErrorHandler::HandlingType handleType)
{
myHandlingType = handleType;
}
// Set the status with the specified values.
void StatGenStatus::setStatus(Status newStatus, const char* newMessage)
{
myType = newStatus;
myMessage = getStatusString(newStatus);
myMessage += ": ";
myMessage += newMessage;
if(newStatus != SUCCESS)
{
handleError(newStatus, newMessage);
}
}
// Adds the specified error message to the status message.
// Sets the status to newStatus if the current status is SUCCESS.
void StatGenStatus::addError(Status newStatus, const char* newMessage)
{
if(myType == StatGenStatus::SUCCESS)
{
myType = newStatus;
}
else
{
myMessage += "\n";
}
myMessage += getStatusString(newStatus);
myMessage += ": ";
myMessage += newMessage;
if(newStatus != SUCCESS)
{
handleError(newStatus, newMessage);
}
}
// Adds the specified status to the status message.
// Sets the status to newStatus if the current status is SUCCESS.
void StatGenStatus::addError(StatGenStatus newStatus)
{
if(myType == StatGenStatus::SUCCESS)
{
myType = newStatus.myType;
}
else
{
myMessage += "\n";
}
myMessage += newStatus.myMessage;
if(newStatus != SUCCESS)
{
handleError(newStatus.myType, newStatus.myMessage.c_str());
}
}
// Return the enum for this status.
StatGenStatus::Status StatGenStatus::getStatus() const
{
return(myType);
}
// Return the status message.
const char* StatGenStatus::getStatusMessage() const
{
return(myMessage.c_str());
}
// Overload operator = to set the sam status type to the
// passed in status and to clear the message string.
StatGenStatus & StatGenStatus::operator = (StatGenStatus::Status newStatus)
{
myType = newStatus;
myMessage.clear();
if(newStatus != SUCCESS)
{
handleError(newStatus, "");
}
return(*this);
}
// Overload operator = to copy the specified status object to this one.
StatGenStatus & StatGenStatus::operator = (StatGenStatus newStatus)
{
myType = newStatus.myType;
myMessage = newStatus.myMessage;
myHandlingType = newStatus.myHandlingType;
return(*this);
}
// Overload operator != to determine if the passed in type is not equal
// to this status's type.
bool StatGenStatus::operator != (const StatGenStatus::Status& compStatus) const
{
return(compStatus != myType);
}
// Overload operator != to determine if the passed in type is equal
// to this status's type.
bool StatGenStatus::operator == (const StatGenStatus::Status& compStatus) const
{
return(compStatus == myType);
}
void StatGenStatus::handleError(Status newStatus, const char* newMessage)
{
// If the status is not success and not NO_MORE_RECS, handle
// the error (SUCCESS & NO_MORE_RECS are not real errors.)
if((newStatus != SUCCESS) && (newStatus != NO_MORE_RECS))
{
std::string message = getStatusString(newStatus);
message += ": ";
message += newMessage;
ErrorHandler::handleError(message.c_str(), myHandlingType);
}
}
ErrorHandler::handleError
static void handleError(const char *message, HandlingType handlingType=EXCEPTION)
Handle an error based on the error handling type.
Definition: ErrorHandler.cpp:36
ErrorHandler::HandlingType
HandlingType
This specifies how this class should respond to errors.
Definition: ErrorHandler.h:29
StatGenStatus
This class is used to track the status results of some methods in the BAM classes.
Definition: StatGenStatus.h:27
StatGenStatus::operator=
StatGenStatus & operator=(Status newStatus)
Overload operator = to set the StatGen status type to the passed in status and to clear the message s...
Definition: StatGenStatus.cpp:157
StatGenStatus::~StatGenStatus
~StatGenStatus()
Destructor.
Definition: StatGenStatus.cpp:63
StatGenStatus::operator!=
bool operator!=(const StatGenStatus::Status &compStatus) const
Overload operator != to determine if the passed in type is not equal to this status's type.
Definition: StatGenStatus.cpp:182
StatGenStatus::operator==
bool operator==(const StatGenStatus::Status &compStatus) const
Overload operator == to determine if the passed in type is equal to this status's type.
Definition: StatGenStatus.cpp:190
StatGenStatus::reset
void reset()
Reset this status to a default state.
Definition: StatGenStatus.cpp:69
StatGenStatus::StatGenStatus
StatGenStatus(ErrorHandler::HandlingType handleType=ErrorHandler::EXCEPTION)
Constructor that takes in the handling type, defaulting it to exception.
Definition: StatGenStatus.cpp:55
StatGenStatus::getStatusMessage
const char * getStatusMessage() const
Return the status message for this object.
Definition: StatGenStatus.cpp:149
StatGenStatus::Status
Status
Return value enum for StatGenFile methods.
Definition: StatGenStatus.h:32
StatGenStatus::UNKNOWN
@ UNKNOWN
unknown result (default value should never be used)
Definition: StatGenStatus.h:33
StatGenStatus::NO_MORE_RECS
@ NO_MORE_RECS
NO_MORE_RECS: failed to read a record since there are no more to read either in the file or section i...
Definition: StatGenStatus.h:36
StatGenStatus::SUCCESS
@ SUCCESS
method completed successfully.
Definition: StatGenStatus.h:32
StatGenStatus::INVALID
@ INVALID
invalid other than for sorting.
Definition: StatGenStatus.h:44
StatGenStatus::INVALID_SORT
@ INVALID_SORT
record is invalid due to it not being sorted.
Definition: StatGenStatus.h:43
StatGenStatus::FAIL_PARSE
@ FAIL_PARSE
failed to parse a record/header - invalid format.
Definition: StatGenStatus.h:42
StatGenStatus::setStatus
void setStatus(Status newStatus, const char *newMessage)
Set the status with the specified status enum and message.
Definition: StatGenStatus.cpp:83
StatGenStatus::isContinuableStatus
static bool isContinuableStatus(StatGenStatus::Status status)
Returns whether or not it is "safe" to keep processing the file after the specified status return.
Definition: StatGenStatus.cpp:41
StatGenStatus::getStatus
Status getStatus() const
Return the enum for this status object.
Definition: StatGenStatus.cpp:142
StatGenStatus::addError
void addError(Status newStatus, const char *newMessage)
Add the specified error message to the status message, setting the status to newStatus if the current...
Definition: StatGenStatus.cpp:99
StatGenStatus::setHandlingType
void setHandlingType(ErrorHandler::HandlingType handleType)
Set how to handle the errors when they are set.
Definition: StatGenStatus.cpp:76
StatGenStatus::getStatusString
static const char * getStatusString(StatGenStatus::Status statusEnum)
Return a string representation of the passed in status enum.
Definition: StatGenStatus.cpp:33