libStatGen Software  1
GlfStatus.h
00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef __GLF_STATUS_H__
00019 #define __GLF_STATUS_H__
00020 
00021 #include <iostream>
00022 
00023 /// This class is used to track the status results of some methods in the
00024 /// GLF classes using the status enum that is defined in this class to 
00025 /// describe the return value of a method. 
00026 class GlfStatus
00027 {
00028 public:
00029 
00030     /// Return value enum for the GlfFile class methods.
00031     enum Status {
00032         SUCCESS = 0, ///< method completed successfully.
00033         UNKNOWN,     ///< unknown result (default value should never be used)
00034         FAIL_IO,     ///< method failed due to an I/O issue.
00035         FAIL_ORDER,  ///< method failed because it was called out of order,
00036                      ///< like trying to read a file without opening it for
00037                      ///< read or trying to read a record before the header.
00038         FAIL_PARSE,  ///< failed to parse a record/header - invalid format.
00039         INVALID,     ///< invalid.
00040         FAIL_MEM     ///< fail a memory allocation.
00041     };
00042 
00043     /// Returns the string representation of the specified enum.
00044     /// \param statusEnum enum to convert to a string
00045     /// \return string representation of the enum
00046     static const char* getStatusString(GlfStatus::Status statusEnum);
00047 
00048     /// Returns whether or not it is "safe" to keep processing the file
00049     /// after the specified status return.
00050     /// \param status enum to check if it is "safe" to continue processing.
00051     /// \return whether or not it is "safe" to keep processing the file
00052     ///         after receiving the specified enum.
00053     static bool isContinuableStatus(GlfStatus::Status status);
00054 
00055     /// Constructor
00056     GlfStatus();
00057    
00058     /// Destructor
00059     ~GlfStatus();
00060 
00061     /// Resets this status.
00062     void reset();
00063 
00064     /// Set the status with the specified values.
00065     /// \param newStatus new status to set this object to.
00066     /// \param newMessage message associated with the new status
00067     void setStatus(Status newStatus, const char* newMessage);
00068 
00069     /// Adds the specified error message to the status message, setting
00070     /// the status to newStatus if the current status is SUCCESS.
00071     /// \param newStatus status to add to this object.
00072     /// \param newMessage message to add to this object
00073     void addError(Status newStatus, const char* newMessage);
00074 
00075 
00076     /// Adds the specified status to the status message, setting
00077     /// the status to newStatus if the current status is SUCCESS.
00078     /// \param newStatus status to add to this object.
00079     void addError(GlfStatus newStatus);
00080 
00081     /// Return the enum for this status.
00082     /// \return enum for this status object.
00083     Status getStatus() const;
00084 
00085     /// Return the status message.
00086     /// \return status message associate with this status object.
00087     const char* getStatusMessage() const;
00088 
00089     /// Overload operator = to set the glf status type to the
00090     /// passed in status and to clear the message string.
00091     /// \param newStatus new status to set this object to.
00092     /// \return this object.
00093     GlfStatus & operator = (Status newStatus);
00094    
00095     // Overload operator = to set the glf status.
00096     //    GlfStatus & operator = (GlfStatus newStatus);
00097    
00098     /// Overload operator != to determine if the passed in type is not equal
00099     /// to this status's type.
00100     /// \param compStatus status enum to compare this status object to.
00101     /// \return true if they are not equal, false if they are.
00102     bool operator != (const GlfStatus::Status& compStatus) const;
00103 
00104     /// Overload operator != to determine if the passed in type is equal
00105     /// to this status's type.
00106     /// \param compStatus status enum to compare this status object to.
00107     /// \return true if they are equal, false if they are not.
00108     bool operator == (const GlfStatus::Status& compStatus) const;
00109       
00110 private:
00111     static const char* enumStatusString[];
00112 
00113     Status myType;
00114     std::string myMessage;
00115 };
00116 
00117 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends