libStatGen Software  1
GlfStatus.cpp
1 /*
2  * Copyright (C) 2010 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "GlfStatus.h"
19 
20 const char* GlfStatus::enumStatusString[] = {
21  "SUCCESS",
22  "UNKNOWN",
23  "FAIL_IO",
24  "FAIL_ORDER",
25  "FAIL_PARSE",
26  "INVALID",
27  "FAIL_MEM"
28 };
29 
30 
32 {
33  return(enumStatusString[statusEnum]);
34 }
35 
36 
37 // Returns whether or not it is "safe" to keep processing the file
38 // after the specified status return.
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 }
50 
51 
52 // Constructor
54 {
55  reset();
56 }
57 
58 
59 // Destructor
61 {
62 }
63 
64 
65 // Resets this status.
67 {
68  myType = UNKNOWN;
69  myMessage = "";
70 }
71 
72 
73 // Set the status with the specified values.
74 void GlfStatus::setStatus(Status newStatus, const char* newMessage)
75 {
76  myType = newStatus;
77  myMessage = getStatusString(newStatus);
78  myMessage += ": ";
79  myMessage += newMessage;
80 }
81 
82 
83 // Adds the specified error message to the status message.
84 // Sets the status to newStatus if the current status is SUCCESS.
85 void GlfStatus::addError(Status newStatus, const char* newMessage)
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 }
99 
100 
101 // Adds the specified status to the status message.
102 // Sets the status to newStatus if the current status is 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 }
115 
116 
117 // Return the enum for this status.
119 {
120  return(myType);
121 }
122 
123 
124 // Return the status message.
125 const char* GlfStatus::getStatusMessage() const
126 {
127  return(myMessage.c_str());
128 }
129 
130 
131 // Overload operator = to set the glf status type to the
132 // passed in status and to clear the message string.
134 {
135  reset();
136  myType = newStatus;
137  return(*this);
138 }
139 
140 // Overload operator != to determine if the passed in type is not equal
141 // to this status's type.
142 bool GlfStatus::operator != (const GlfStatus::Status& compStatus) const
143 {
144  return(compStatus != myType);
145 }
146 // Overload operator != to determine if the passed in type is equal
147 // to this status's type.
148 bool GlfStatus::operator == (const GlfStatus::Status& compStatus) const
149 {
150  return(compStatus == myType);
151 }
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::getStatusString
static const char * getStatusString(GlfStatus::Status statusEnum)
Returns the string representation of the specified enum.
Definition: GlfStatus.cpp:31
GlfStatus::reset
void reset()
Resets this status.
Definition: GlfStatus.cpp:66
GlfStatus::UNKNOWN
@ UNKNOWN
unknown result (default value should never be used)
Definition: GlfStatus.h:33
GlfStatus::getStatus
Status getStatus() const
Return the enum for this status.
Definition: GlfStatus.cpp:118
GlfStatus::~GlfStatus
~GlfStatus()
Destructor.
Definition: GlfStatus.cpp:60
GlfStatus::setStatus
void setStatus(Status newStatus, const char *newMessage)
Set the status with the specified values.
Definition: GlfStatus.cpp:74
GlfStatus::GlfStatus
GlfStatus()
Constructor.
Definition: GlfStatus.cpp:53
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::FAIL_PARSE
@ FAIL_PARSE
failed to parse a record/header - invalid format.
Definition: GlfStatus.h:38
GlfStatus::getStatusMessage
const char * getStatusMessage() const
Return the status message.
Definition: GlfStatus.cpp:125
GlfStatus::Status
Status
Return value enum for the GlfFile class methods.
Definition: GlfStatus.h:31
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::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::INVALID
@ INVALID
invalid.
Definition: GlfStatus.h:39
GlfStatus::SUCCESS
@ SUCCESS
method completed successfully.
Definition: GlfStatus.h:32
GlfStatus
This class is used to track the status results of some methods in the GLF classes using the status en...
Definition: GlfStatus.h:26
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