GlfStatus.cpp
/*
* Copyright (C) 2010 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 "GlfStatus.h"
const char* GlfStatus::enumStatusString[] = {
"SUCCESS",
"UNKNOWN",
"FAIL_IO",
"FAIL_ORDER",
"FAIL_PARSE",
"INVALID",
"FAIL_MEM"
};
const char* GlfStatus::getStatusString(GlfStatus::Status statusEnum)
{
return(enumStatusString[statusEnum]);
}
// Returns whether or not it is "safe" to keep processing the file
// after the specified status return.
bool GlfStatus::isContinuableStatus(GlfStatus::Status status)
{
if(status == GlfStatus::SUCCESS || status == GlfStatus::FAIL_PARSE ||
status == GlfStatus::INVALID)
{
// The status is such that file processing can continue.
return(true);
}
// UNKNOWN, FAIL_IO, FAIL_ORDER, FAIL_MEM
return(false);
}
// Constructor
GlfStatus::GlfStatus()
{
reset();
}
// Destructor
GlfStatus::~GlfStatus()
{
}
// Resets this status.
void GlfStatus::reset()
{
myType = UNKNOWN;
myMessage = "";
}
// Set the status with the specified values.
void GlfStatus::setStatus(Status newStatus, const char* newMessage)
{
myType = newStatus;
myMessage = getStatusString(newStatus);
myMessage += ": ";
myMessage += newMessage;
}
// Adds the specified error message to the status message.
// Sets the status to newStatus if the current status is SUCCESS.
void GlfStatus::addError(Status newStatus, const char* newMessage)
{
if(myType == GlfStatus::SUCCESS)
{
myType = newStatus;
}
else
{
myMessage += "\n";
}
myMessage += getStatusString(newStatus);
myMessage += ": ";
myMessage += newMessage;
}
// Adds the specified status to the status message.
// Sets the status to newStatus if the current status is SUCCESS.
void GlfStatus::addError(GlfStatus newStatus)
{
if(myType == GlfStatus::SUCCESS)
{
myType = newStatus.myType;
}
else
{
myMessage += "\n";
}
myMessage += newStatus.myMessage;
}
// Return the enum for this status.
GlfStatus::Status GlfStatus::getStatus() const
{
return(myType);
}
// Return the status message.
const char* GlfStatus::getStatusMessage() const
{
return(myMessage.c_str());
}
// Overload operator = to set the glf status type to the
// passed in status and to clear the message string.
GlfStatus & GlfStatus::operator = (GlfStatus::Status newStatus)
{
reset();
myType = newStatus;
return(*this);
}
// Overload operator != to determine if the passed in type is not equal
// to this status's type.
bool GlfStatus::operator != (const GlfStatus::Status& compStatus) const
{
return(compStatus != myType);
}
// Overload operator != to determine if the passed in type is equal
// to this status's type.
bool GlfStatus::operator == (const GlfStatus::Status& compStatus) const
{
return(compStatus == myType);
}
GlfStatus
This class is used to track the status results of some methods in the GLF classes using the status en...
Definition: GlfStatus.h:27
GlfStatus::isContinuableStatus
static bool isContinuableStatus(GlfStatus::Status status)
Returns whether or not it is "safe" to keep processing the file after the specified status return.
Definition: GlfStatus.cpp:39
GlfStatus::~GlfStatus
~GlfStatus()
Destructor.
Definition: GlfStatus.cpp:60
GlfStatus::getStatusString
static const char * getStatusString(GlfStatus::Status statusEnum)
Returns the string representation of the specified enum.
Definition: GlfStatus.cpp:31
GlfStatus::getStatusMessage
const char * getStatusMessage() const
Return the status message.
Definition: GlfStatus.cpp:125
GlfStatus::operator=
GlfStatus & operator=(Status newStatus)
Overload operator = to set the glf status type to the passed in status and to clear the message strin...
Definition: GlfStatus.cpp:133
GlfStatus::setStatus
void setStatus(Status newStatus, const char *newMessage)
Set the status with the specified values.
Definition: GlfStatus.cpp:74
GlfStatus::operator==
bool operator==(const GlfStatus::Status &compStatus) const
Overload operator != to determine if the passed in type is equal to this status's type.
Definition: GlfStatus.cpp:148
GlfStatus::getStatus
Status getStatus() const
Return the enum for this status.
Definition: GlfStatus.cpp:118
GlfStatus::addError
void addError(Status newStatus, const char *newMessage)
Adds the specified error message to the status message, setting the status to newStatus if the curren...
Definition: GlfStatus.cpp:85
GlfStatus::operator!=
bool operator!=(const GlfStatus::Status &compStatus) const
Overload operator != to determine if the passed in type is not equal to this status's type.
Definition: GlfStatus.cpp:142
GlfStatus::GlfStatus
GlfStatus()
Constructor.
Definition: GlfStatus.cpp:53
GlfStatus::Status
Status
Return value enum for the GlfFile class methods.
Definition: GlfStatus.h:31
GlfStatus::UNKNOWN
@ UNKNOWN
unknown result (default value should never be used)
Definition: GlfStatus.h:33
GlfStatus::SUCCESS
@ SUCCESS
method completed successfully.
Definition: GlfStatus.h:32
GlfStatus::INVALID
@ INVALID
invalid.
Definition: GlfStatus.h:39
GlfStatus::FAIL_PARSE
@ FAIL_PARSE
failed to parse a record/header - invalid format.
Definition: GlfStatus.h:38
GlfStatus::reset
void reset()
Resets this status.
Definition: GlfStatus.cpp:66