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>

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. More...
 
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. More...
 
void addError (GlfStatus newStatus)
 Adds the specified status to the status message, setting the status to newStatus if the current status is SUCCESS. More...
 
Status getStatus () const
 Return the enum for this status. More...
 
const char * getStatusMessage () const
 Return the status message. More...
 
GlfStatusoperator= (Status newStatus)
 Overload operator = to set the glf status type to the passed in status and to clear the message string. More...
 
bool operator!= (const GlfStatus::Status &compStatus) const
 Overload operator != to determine if the passed in type is not equal to this status's type. More...
 
bool operator== (const GlfStatus::Status &compStatus) const
 Overload operator != to determine if the passed in type is equal to this status's type. More...
 

Static Public Member Functions

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

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

◆ Status

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.

31  {
32  SUCCESS = 0, ///< method completed successfully.
33  UNKNOWN, ///< unknown result (default value should never be used)
34  FAIL_IO, ///< method failed due to an I/O issue.
35  FAIL_ORDER, ///< method failed because it was called out of order,
36  ///< like trying to read a file without opening it for
37  ///< read or trying to read a record before the header.
38  FAIL_PARSE, ///< failed to parse a record/header - invalid format.
39  INVALID, ///< invalid.
40  FAIL_MEM ///< fail a memory allocation.
41  };
failed to parse a record/header - invalid format.
Definition: GlfStatus.h:38
unknown result (default value should never be used)
Definition: GlfStatus.h:33
method completed successfully.
Definition: GlfStatus.h:32
method failed due to an I/O issue.
Definition: GlfStatus.h:34
method failed because it was called out of order, like trying to read a file without opening it for r...
Definition: GlfStatus.h:35
fail a memory allocation.
Definition: GlfStatus.h:40

Member Function Documentation

◆ addError() [1/2]

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().

86 {
87  if(myType == GlfStatus::SUCCESS)
88  {
89  myType = newStatus;
90  }
91  else
92  {
93  myMessage += "\n";
94  }
95  myMessage += getStatusString(newStatus);
96  myMessage += ": ";
97  myMessage += newMessage;
98 }
method completed successfully.
Definition: GlfStatus.h:32
static const char * getStatusString(GlfStatus::Status statusEnum)
Returns the string representation of the specified enum.
Definition: GlfStatus.cpp:31

◆ addError() [2/2]

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.

104 {
105  if(myType == GlfStatus::SUCCESS)
106  {
107  myType = newStatus.myType;
108  }
109  else
110  {
111  myMessage += "\n";
112  }
113  myMessage += newStatus.myMessage;
114 }
method completed successfully.
Definition: GlfStatus.h:32

◆ getStatus()

GlfStatus::Status GlfStatus::getStatus ( ) const

Return the enum for this status.

Returns
enum for this status object.

Definition at line 118 of file GlfStatus.cpp.

Referenced by GlfFile::getStatus().

119 {
120  return(myType);
121 }

◆ getStatusMessage()

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().

126 {
127  return(myMessage.c_str());
128 }

◆ getStatusString()

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().

32 {
33  return(enumStatusString[statusEnum]);
34 }

◆ isContinuableStatus()

bool GlfStatus::isContinuableStatus ( GlfStatus::Status  status)
static

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.

40 {
41  if(status == GlfStatus::SUCCESS || status == GlfStatus::FAIL_PARSE ||
42  status == GlfStatus::INVALID)
43  {
44  // The status is such that file processing can continue.
45  return(true);
46  }
47  // UNKNOWN, FAIL_IO, FAIL_ORDER, FAIL_MEM
48  return(false);
49 }
failed to parse a record/header - invalid format.
Definition: GlfStatus.h:38
method completed successfully.
Definition: GlfStatus.h:32

◆ operator!=()

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.

143 {
144  return(compStatus != myType);
145 }

◆ operator=()

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().

134 {
135  reset();
136  myType = newStatus;
137  return(*this);
138 }
void reset()
Resets this status.
Definition: GlfStatus.cpp:66

◆ operator==()

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.

149 {
150  return(compStatus == myType);
151 }

◆ setStatus()

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::getCurrentRecordCount(), GlfFile::getNextRecord(), GlfFile::getNextRefSection(), GlfException::GlfException(), GlfFile::openForRead(), GlfFile::openForWrite(), GlfFile::readHeader(), GlfFile::writeHeader(), GlfFile::writeRecord(), and GlfFile::writeRefSection().

75 {
76  myType = newStatus;
77  myMessage = getStatusString(newStatus);
78  myMessage += ": ";
79  myMessage += newMessage;
80 }
static const char * getStatusString(GlfStatus::Status statusEnum)
Returns the string representation of the specified enum.
Definition: GlfStatus.cpp:31

The documentation for this class was generated from the following files: