00001 // Dear emacs, this is -*- c++ -*- 00002 // $Id: CorrectionCode.h 719663 2016-01-25 20:27:50Z krumnack $ 00003 #ifndef PATINTERFACES_CORRECTIONCODE_H 00004 #define PATINTERFACES_CORRECTIONCODE_H 00005 00006 // Copyright Nils Krumnack 2012. 00007 // Distributed under the Boost Software License, Version 1.0. 00008 // (See accompanying file LICENSE_1_0.txt or copy at 00009 // http://www.boost.org/LICENSE_1_0.txt) 00010 00011 // Please feel free to contact me (krumnack@iastate.edu) for bug 00012 // reports, feature suggestions, praise and complaints. 00013 00014 namespace CP { 00015 00035 class CorrectionCode { 00036 00037 public: 00039 enum ErrorCode { 00040 Error = 0, 00041 OutOfValidityRange = 1, 00042 Ok = 2 00043 }; 00044 00046 CorrectionCode( ErrorCode code = Ok ); 00048 CorrectionCode( const CorrectionCode& parent ); 00050 ~CorrectionCode(); 00051 00053 CorrectionCode& operator= ( const CorrectionCode& rhs ); 00054 00056 ErrorCode code() const; 00057 00059 operator ErrorCode() const { return code(); } 00060 00063 bool operator < ( const CorrectionCode& rhs ) const { 00064 return m_code < rhs.m_code; 00065 } 00066 00068 void setChecked() const { m_checked = true; } 00070 void ignore() const { setChecked(); } 00071 00073 static void enableFailure(); 00075 static void disableFailure(); 00076 00077 private: 00078 ErrorCode m_code; 00079 mutable bool m_checked; 00080 00081 }; // class CorrectionCode 00082 00083 } // namespace CP 00084 00085 namespace asg 00086 { 00089 template<typename T> struct CheckHelper; 00090 00091 template<> struct CheckHelper<CP::CorrectionCode> 00092 { 00094 static inline bool isSuccess (const CP::CorrectionCode& sc) { 00095 return sc == CP::CorrectionCode::Ok; } 00096 00098 static inline bool isOutOfValidityRange (const CP::CorrectionCode& sc) { 00099 return sc == CP::CorrectionCode::OutOfValidityRange; } 00100 00102 static inline CP::CorrectionCode successCode () { 00103 return CP::CorrectionCode::Ok;} 00104 00106 static inline CP::CorrectionCode failureCode () { 00107 return CP::CorrectionCode::Error;} 00108 }; 00109 } 00110 00111 #endif // not PATINTERFACES_CORRECTIONCODE_H