Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:44:16

0001 /****************************************************************************
0002 **
0003 ** Copyright (c) 2008-2020 C.B. Barber. All rights reserved.
0004 ** $Id: //main/2019/qhull/src/libqhullcpp/RoadError.h#7 $$Change: 2959 $
0005 ** $DateTime: 2020/05/28 22:25:29 $$Author: bbarber $
0006 **
0007 ****************************************************************************/
0008 
0009 #ifndef ROADERROR_H
0010 #define ROADERROR_H
0011 
0012 #include "libqhull_r/user_r.h"  /* for QHULL_CRTDBG */
0013 #include "libqhullcpp/RoadLogEvent.h"
0014 
0015 #include <iostream>
0016 #include <sstream>
0017 #include <stdexcept>
0018 #include <string>
0019 
0020 using std::endl;
0021 
0022 namespace orgQhull {
0023 
0024 #//!\name Defined here
0025     //! RoadError -- Report and log errors
0026     //!  See discussion in Saylan, G., "Practical C++ error handling in hybrid environments," Dr. Dobb's Journal, p. 50-55, March 2007.
0027     //!   He uses an auto_ptr to track a stringstream.  It constructs a string on the fly.  RoadError uses the copy constructor to transform RoadLogEvent into a string
0028     class RoadError;
0029 
0030 class RoadError : public std::exception {
0031 
0032 private:
0033 #//!\name Fields
0034     int                 error_code;  //! Non-zero code (not logged), maybe returned as program status
0035     RoadLogEvent        log_event;   //! Format string w/ arguments
0036     mutable std::string error_message;  //! Formated error message.  Must be after log_event.
0037 
0038 #//!\name Class fields
0039     static const char  *  ROADtag;
0040     static std::ostringstream  global_log; //!< May be replaced with any ostream object
0041                                     //!< Not reentrant -- only used by RoadError::logErrorLastResort()
0042 
0043 public:
0044 #//!\name Constants
0045 
0046 #//!\name Constructors
0047     RoadError();
0048     RoadError(const RoadError &other);  //! Called on throw, generates error_message
0049     RoadError(int code, const std::string &message);
0050     RoadError(int code, const char *fmt);
0051     RoadError(int code, const char *fmt, int d);
0052     RoadError(int code, const char *fmt, int d, int d2);
0053     RoadError(int code, const char *fmt, int d, int d2, float f);
0054     RoadError(int code, const char *fmt, int d, int d2, float f, const char *s);
0055     RoadError(int code, const char *fmt, int d, int d2, float f, const void *x);
0056     RoadError(int code, const char *fmt, int d, int d2, float f, int i);
0057     RoadError(int code, const char *fmt, int d, int d2, float f, long long i);
0058     RoadError(int code, const char *fmt, int d, int d2, float f, double e);
0059 
0060     RoadError &         operator=(const RoadError &other);
0061                         ~RoadError() throw() {}
0062 
0063 #//!\name Class methods
0064 
0065     static void         clearGlobalLog() { global_log.seekp(0); }
0066     static bool         emptyGlobalLog() { return global_log.tellp()<=0; }
0067     static std::string  stringGlobalLog() { return global_log.str(); }
0068 
0069 #//!\name Virtual
0070     virtual const char *what() const throw();
0071 
0072 #//!\name GetSet
0073     bool                isValid() const { return log_event.isValid(); }
0074     int                 errorCode() const { return error_code; }
0075    // QH11021 FIX: should RoadError provide errorMessage().  Currently what()
0076     RoadLogEvent        roadLogEvent() const { return log_event; }
0077 
0078 #//!\name Update
0079     void                logErrorLastResort() const;
0080 };//class RoadError
0081 
0082 }//namespace orgQhull
0083 
0084 #//!\name Global
0085 
0086 inline std::ostream &   operator<<(std::ostream &os, const orgQhull::RoadError &e) { return os << e.what(); }
0087 
0088 #endif // ROADERROR_H