libStatGen Software  1
StatGenStatus.h
1 /*
2  * Copyright (C) 2010-2011 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 __STATGEN_STATUS_H__
19 #define __STATGEN_STATUS_H__
20 
21 #include <iostream>
22 #include "ErrorHandler.h"
23 
24 /// This class is used to track the status results of some methods in the BAM
25 /// classes. It contains a status enum that describing the status.
27 {
28 public:
29 
30  /// Return value enum for StatGenFile methods.
31  enum Status
32  { SUCCESS = 0, ///< method completed successfully.
33  UNKNOWN, ///< unknown result (default value should never be used)
34  /// NO_MORE_RECS: failed to read a record since there are no more to
35  /// read either in the file or section if section based reading.
37  FAIL_IO, ///< method failed due to an I/O issue.
38  /// FAIL_ORDER: method failed because it was called out of order,
39  /// like trying to read a file without opening it for read or trying
40  /// to read a record before the header.
42  FAIL_PARSE, ///< failed to parse a record/header - invalid format.
43  INVALID_SORT, ///< record is invalid due to it not being sorted.
44  INVALID, ///< invalid other than for sorting.
45  FAIL_MEM ///< fail a memory allocation.
46  };
47 
48  /// Return a string representation of the passed in status enum.
49  static const char* getStatusString(StatGenStatus::Status statusEnum);
50 
51  /// Returns whether or not it is "safe" to keep processing the file
52  /// after the specified status return.
53  static bool isContinuableStatus(StatGenStatus::Status status);
54 
55  /// Constructor that takes in the handling type, defaulting it to exception.
57 
58  /// Destructor
60 
61  /// Reset this status to a default state.
62  void reset();
63 
64  /// Set how to handle the errors when they are set.
66 
67  /// Set the status with the specified status enum and message.
68  void setStatus(Status newStatus, const char* newMessage);
69 
70  /// Add the specified error message to the status message, setting
71  /// the status to newStatus if the current status is SUCCESS.
72  void addError(Status newStatus, const char* newMessage);
73 
74 
75  /// Add the specified status to the status message, setting
76  /// the status to newStatus if the current status is SUCCESS.
77  void addError(StatGenStatus newStatus);
78 
79  /// Return the enum for this status object.
80  Status getStatus() const;
81 
82  /// Return the status message for this object.
83  const char* getStatusMessage() const;
84 
85  /// Overload operator = to set the StatGen status type to the
86  /// passed in status and to clear the message string.
87  StatGenStatus & operator = (Status newStatus);
88 
89  /// Overload operator = to copy the specified status object to this one.
91 
92  /// Overload operator != to determine if the passed in type is not equal
93  /// to this status's type.
94  bool operator != (const StatGenStatus::Status& compStatus) const;
95 
96  /// Overload operator == to determine if the passed in type is equal
97  /// to this status's type.
98  bool operator == (const StatGenStatus::Status& compStatus) const;
99 
100 private:
101  // Handle an error based on the error handling type.
102  void handleError(Status newType, const char* newMessage);
103 
104 
105  static const char* enumStatusString[];
106 
107  Status myType;
108  std::string myMessage;
109  ErrorHandler::HandlingType myHandlingType;
110 };
111 
112 
113 #endif
StatGenStatus::operator==
bool operator==(const StatGenStatus::Status &compStatus) const
Overload operator == to determine if the passed in type is equal to this status's type.
Definition: StatGenStatus.cpp:190
StatGenStatus::~StatGenStatus
~StatGenStatus()
Destructor.
Definition: StatGenStatus.cpp:63
StatGenStatus::INVALID
@ INVALID
invalid other than for sorting.
Definition: StatGenStatus.h:44
StatGenStatus::reset
void reset()
Reset this status to a default state.
Definition: StatGenStatus.cpp:69
StatGenStatus::NO_MORE_RECS
@ NO_MORE_RECS
NO_MORE_RECS: failed to read a record since there are no more to read either in the file or section i...
Definition: StatGenStatus.h:36
StatGenStatus::SUCCESS
@ SUCCESS
method completed successfully.
Definition: StatGenStatus.h:32
StatGenStatus::getStatus
Status getStatus() const
Return the enum for this status object.
Definition: StatGenStatus.cpp:142
StatGenStatus::isContinuableStatus
static bool isContinuableStatus(StatGenStatus::Status status)
Returns whether or not it is "safe" to keep processing the file after the specified status return.
Definition: StatGenStatus.cpp:41
ErrorHandler::HandlingType
HandlingType
This specifies how this class should respond to errors.
Definition: ErrorHandler.h:29
StatGenStatus
This class is used to track the status results of some methods in the BAM classes.
Definition: StatGenStatus.h:26
StatGenStatus::StatGenStatus
StatGenStatus(ErrorHandler::HandlingType handleType=ErrorHandler::EXCEPTION)
Constructor that takes in the handling type, defaulting it to exception.
Definition: StatGenStatus.cpp:55
ErrorHandler::EXCEPTION
@ EXCEPTION
throw an exception for the error
Definition: ErrorHandler.h:29
StatGenStatus::FAIL_PARSE
@ FAIL_PARSE
failed to parse a record/header - invalid format.
Definition: StatGenStatus.h:42
StatGenStatus::FAIL_MEM
@ FAIL_MEM
fail a memory allocation.
Definition: StatGenStatus.h:45
StatGenStatus::INVALID_SORT
@ INVALID_SORT
record is invalid due to it not being sorted.
Definition: StatGenStatus.h:43
StatGenStatus::setStatus
void setStatus(Status newStatus, const char *newMessage)
Set the status with the specified status enum and message.
Definition: StatGenStatus.cpp:83
StatGenStatus::Status
Status
Return value enum for StatGenFile methods.
Definition: StatGenStatus.h:31
StatGenStatus::operator!=
bool operator!=(const StatGenStatus::Status &compStatus) const
Overload operator != to determine if the passed in type is not equal to this status's type.
Definition: StatGenStatus.cpp:182
StatGenStatus::addError
void addError(Status newStatus, const char *newMessage)
Add the specified error message to the status message, setting the status to newStatus if the current...
Definition: StatGenStatus.cpp:99
StatGenStatus::getStatusMessage
const char * getStatusMessage() const
Return the status message for this object.
Definition: StatGenStatus.cpp:149
StatGenStatus::FAIL_IO
@ FAIL_IO
method failed due to an I/O issue.
Definition: StatGenStatus.h:37
StatGenStatus::FAIL_ORDER
@ FAIL_ORDER
FAIL_ORDER: method failed because it was called out of order, like trying to read a file without open...
Definition: StatGenStatus.h:41
StatGenStatus::UNKNOWN
@ UNKNOWN
unknown result (default value should never be used)
Definition: StatGenStatus.h:33
StatGenStatus::getStatusString
static const char * getStatusString(StatGenStatus::Status statusEnum)
Return a string representation of the passed in status enum.
Definition: StatGenStatus.cpp:33
StatGenStatus::setHandlingType
void setHandlingType(ErrorHandler::HandlingType handleType)
Set how to handle the errors when they are set.
Definition: StatGenStatus.cpp:76
StatGenStatus::operator=
StatGenStatus & operator=(Status newStatus)
Overload operator = to set the StatGen status type to the passed in status and to clear the message s...
Definition: StatGenStatus.cpp:157