libStatGen Software 1
Loading...
Searching...
No Matches
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{
28public:
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.
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
100private:
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
HandlingType
This specifies how this class should respond to errors.
@ EXCEPTION
throw an exception for the error
This class is used to track the status results of some methods in the BAM classes.
StatGenStatus & operator=(Status newStatus)
Overload operator = to set the StatGen status type to the passed in status and to clear the message s...
~StatGenStatus()
Destructor.
bool operator!=(const StatGenStatus::Status &compStatus) const
Overload operator != to determine if the passed in type is not equal to this status's type.
bool operator==(const StatGenStatus::Status &compStatus) const
Overload operator == to determine if the passed in type is equal to this status's type.
void reset()
Reset this status to a default state.
const char * getStatusMessage() const
Return the status message for this object.
Status
Return value enum for StatGenFile methods.
@ UNKNOWN
unknown result (default value should never be used)
@ FAIL_MEM
fail a memory allocation.
@ 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...
@ SUCCESS
method completed successfully.
@ FAIL_IO
method failed due to an I/O issue.
@ INVALID
invalid other than for sorting.
@ INVALID_SORT
record is invalid due to it not being sorted.
@ FAIL_PARSE
failed to parse a record/header - invalid format.
@ FAIL_ORDER
FAIL_ORDER: method failed because it was called out of order, like trying to read a file without open...
void setStatus(Status newStatus, const char *newMessage)
Set the status with the specified status enum and message.
static bool isContinuableStatus(StatGenStatus::Status status)
Returns whether or not it is "safe" to keep processing the file after the specified status return.
Status getStatus() const
Return the enum for this status object.
void addError(Status newStatus, const char *newMessage)
Add the specified error message to the status message, setting the status to newStatus if the current...
void setHandlingType(ErrorHandler::HandlingType handleType)
Set how to handle the errors when they are set.
static const char * getStatusString(StatGenStatus::Status statusEnum)
Return a string representation of the passed in status enum.