libStatGen Software  1
GlfStatus Class Reference

This class is used to track the status results of some methods in the GLF classes using the status enum that is defined in this class to describe the return value of a method. More...

#include <GlfStatus.h>

List of all members.

Public Types

enum  Status {
  SUCCESS = 0, UNKNOWN, FAIL_IO, FAIL_ORDER,
  FAIL_PARSE, INVALID, FAIL_MEM
}
 Return value enum for the GlfFile class methods. More...

Public Member Functions

 GlfStatus ()
 Constructor.
 ~GlfStatus ()
 Destructor.
void reset ()
 Resets this status.
void setStatus (Status newStatus, const char *newMessage)
 Set the status with the specified values.
void addError (Status newStatus, const char *newMessage)
 Adds the specified error message to the status message, setting the status to newStatus if the current status is SUCCESS.
void addError (GlfStatus newStatus)
 Adds the specified status to the status message, setting the status to newStatus if the current status is SUCCESS.
Status getStatus () const
 Return the enum for this status.
const char * getStatusMessage () const
 Return the status message.
GlfStatusoperator= (Status newStatus)
 Overload operator = to set the glf status type to the passed in status and to clear the message string.
bool operator!= (const GlfStatus::Status &compStatus) const
 Overload operator != to determine if the passed in type is not equal to this status's type.
bool operator== (const GlfStatus::Status &compStatus) const
 Overload operator != to determine if the passed in type is equal to this status's type.

Static Public Member Functions

static const char * getStatusString (GlfStatus::Status statusEnum)
 Returns the string representation of the specified enum.
static bool isContinuableStatus (GlfStatus::Status status)
 Returns whether or not it is "safe" to keep processing the file after the specified status return.

Detailed Description

This class is used to track the status results of some methods in the GLF classes using the status enum that is defined in this class to describe the return value of a method.

Definition at line 26 of file GlfStatus.h.


Member Enumeration Documentation

Return value enum for the GlfFile class methods.

Enumerator:
SUCCESS 

method completed successfully.

UNKNOWN 

unknown result (default value should never be used)

FAIL_IO 

method failed due to an I/O issue.

FAIL_ORDER 

method failed because it was called out of order, like trying to read a file without opening it for read or trying to read a record before the header.

FAIL_PARSE 

failed to parse a record/header - invalid format.

INVALID 

invalid.

FAIL_MEM 

fail a memory allocation.

Definition at line 31 of file GlfStatus.h.

                {
        SUCCESS = 0, ///< method completed successfully.
        UNKNOWN,     ///< unknown result (default value should never be used)
        FAIL_IO,     ///< method failed due to an I/O issue.
        FAIL_ORDER,  ///< method failed because it was called out of order,
                     ///< like trying to read a file without opening it for
                     ///< read or trying to read a record before the header.
        FAIL_PARSE,  ///< failed to parse a record/header - invalid format.
        INVALID,     ///< invalid.
        FAIL_MEM     ///< fail a memory allocation.
    };

Member Function Documentation

void GlfStatus::addError ( Status  newStatus,
const char *  newMessage 
)

Adds the specified error message to the status message, setting the status to newStatus if the current status is SUCCESS.

Parameters:
newStatusstatus to add to this object.
newMessagemessage to add to this object

Definition at line 85 of file GlfStatus.cpp.

References getStatusString(), and SUCCESS.

Referenced by GlfException::GlfException().

{
    if(myType == GlfStatus::SUCCESS)
    {
        myType = newStatus;
    }
    else
    {
        myMessage += "\n";
    }
    myMessage += getStatusString(newStatus);
    myMessage += ": ";
    myMessage += newMessage;
}
void GlfStatus::addError ( GlfStatus  newStatus)

Adds the specified status to the status message, setting the status to newStatus if the current status is SUCCESS.

Parameters:
newStatusstatus to add to this object.

Definition at line 103 of file GlfStatus.cpp.

References SUCCESS.

{
    if(myType == GlfStatus::SUCCESS)
    {
        myType = newStatus.myType;
    }
    else
    {
        myMessage += "\n";
    }
    myMessage += newStatus.myMessage;
}

Return the enum for this status.

Returns:
enum for this status object.

Definition at line 118 of file GlfStatus.cpp.

Referenced by GlfFile::getStatus().

{
    return(myType);
}
const char * GlfStatus::getStatusMessage ( ) const

Return the status message.

Returns:
status message associate with this status object.

Definition at line 125 of file GlfStatus.cpp.

Referenced by GlfFile::getStatusMessage(), and GlfException::what().

{
    return(myMessage.c_str());
}
const char * GlfStatus::getStatusString ( GlfStatus::Status  statusEnum) [static]

Returns the string representation of the specified enum.

Parameters:
statusEnumenum to convert to a string
Returns:
string representation of the enum

Definition at line 31 of file GlfStatus.cpp.

Referenced by addError(), and setStatus().

{
    return(enumStatusString[statusEnum]);
}

Returns whether or not it is "safe" to keep processing the file after the specified status return.

Parameters:
statusenum to check if it is "safe" to continue processing.
Returns:
whether or not it is "safe" to keep processing the file after receiving the specified enum.

Definition at line 39 of file GlfStatus.cpp.

References FAIL_PARSE, INVALID, and SUCCESS.

{
    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);
}
bool GlfStatus::operator!= ( const GlfStatus::Status compStatus) const

Overload operator != to determine if the passed in type is not equal to this status's type.

Parameters:
compStatusstatus enum to compare this status object to.
Returns:
true if they are not equal, false if they are.

Definition at line 142 of file GlfStatus.cpp.

{
    return(compStatus != myType);
}
GlfStatus & GlfStatus::operator= ( GlfStatus::Status  newStatus)

Overload operator = to set the glf status type to the passed in status and to clear the message string.

Parameters:
newStatusnew status to set this object to.
Returns:
this object.

Definition at line 133 of file GlfStatus.cpp.

References reset().

{
    reset();
    myType = newStatus;
    return(*this);
}
bool GlfStatus::operator== ( const GlfStatus::Status compStatus) const

Overload operator != to determine if the passed in type is equal to this status's type.

Parameters:
compStatusstatus enum to compare this status object to.
Returns:
true if they are equal, false if they are not.

Definition at line 148 of file GlfStatus.cpp.

{
    return(compStatus == myType);
}
void GlfStatus::setStatus ( Status  newStatus,
const char *  newMessage 
)

Set the status with the specified values.

Parameters:
newStatusnew status to set this object to.
newMessagemessage associated with the new status

Definition at line 74 of file GlfStatus.cpp.

References getStatusString().

Referenced by GlfFile::getNextRecord(), GlfFile::getNextRefSection(), GlfException::GlfException(), GlfFile::openForRead(), GlfFile::openForWrite(), GlfFile::readHeader(), GlfFile::writeHeader(), GlfFile::writeRecord(), and GlfFile::writeRefSection().

{
    myType = newStatus;
    myMessage = getStatusString(newStatus);
    myMessage += ": ";
    myMessage += newMessage;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends