libStatGen Software  1
GlfStatus.h
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 #ifndef __GLF_STATUS_H__
19 #define __GLF_STATUS_H__
20 
21 #include <iostream>
22 
23 /// This class is used to track the status results of some methods in the
24 /// GLF classes using the status enum that is defined in this class to
25 /// describe the return value of a method.
26 class GlfStatus
27 {
28 public:
29 
30  /// Return value enum for the GlfFile class methods.
31  enum Status {
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  };
42 
43  /// Returns the string representation of the specified enum.
44  /// \param statusEnum enum to convert to a string
45  /// \return string representation of the enum
46  static const char* getStatusString(GlfStatus::Status statusEnum);
47 
48  /// Returns whether or not it is "safe" to keep processing the file
49  /// after the specified status return.
50  /// \param status enum to check if it is "safe" to continue processing.
51  /// \return whether or not it is "safe" to keep processing the file
52  /// after receiving the specified enum.
53  static bool isContinuableStatus(GlfStatus::Status status);
54 
55  /// Constructor
56  GlfStatus();
57 
58  /// Destructor
59  ~GlfStatus();
60 
61  /// Resets this status.
62  void reset();
63 
64  /// Set the status with the specified values.
65  /// \param newStatus new status to set this object to.
66  /// \param newMessage message associated with the new status
67  void setStatus(Status newStatus, const char* newMessage);
68 
69  /// Adds the specified error message to the status message, setting
70  /// the status to newStatus if the current status is SUCCESS.
71  /// \param newStatus status to add to this object.
72  /// \param newMessage message to add to this object
73  void addError(Status newStatus, const char* newMessage);
74 
75 
76  /// Adds the specified status to the status message, setting
77  /// the status to newStatus if the current status is SUCCESS.
78  /// \param newStatus status to add to this object.
79  void addError(GlfStatus newStatus);
80 
81  /// Return the enum for this status.
82  /// \return enum for this status object.
83  Status getStatus() const;
84 
85  /// Return the status message.
86  /// \return status message associate with this status object.
87  const char* getStatusMessage() const;
88 
89  /// Overload operator = to set the glf status type to the
90  /// passed in status and to clear the message string.
91  /// \param newStatus new status to set this object to.
92  /// \return this object.
93  GlfStatus & operator = (Status newStatus);
94 
95  // Overload operator = to set the glf status.
96  // GlfStatus & operator = (GlfStatus newStatus);
97 
98  /// Overload operator != to determine if the passed in type is not equal
99  /// to this status's type.
100  /// \param compStatus status enum to compare this status object to.
101  /// \return true if they are not equal, false if they are.
102  bool operator != (const GlfStatus::Status& compStatus) const;
103 
104  /// Overload operator != to determine if the passed in type is equal
105  /// to this status's type.
106  /// \param compStatus status enum to compare this status object to.
107  /// \return true if they are equal, false if they are not.
108  bool operator == (const GlfStatus::Status& compStatus) const;
109 
110 private:
111  static const char* enumStatusString[];
112 
113  Status myType;
114  std::string myMessage;
115 };
116 
117 #endif
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::FAIL_MEM
@ FAIL_MEM
fail a memory allocation.
Definition: GlfStatus.h:40
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::FAIL_ORDER
@ FAIL_ORDER
method failed because it was called out of order, like trying to read a file without opening it for r...
Definition: GlfStatus.h:35
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
GlfStatus::FAIL_IO
@ FAIL_IO
method failed due to an I/O issue.
Definition: GlfStatus.h:34