⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exception.hpp

📁 一个gps小工具包
💻 HPP
📖 第 1 页 / 共 2 页
字号:
         /// Returns the number of locations stored in the exception         /// location array.      size_t getLocationCount() const         throw();         /**          * If the thrower (that is, whatever creates the exception)          * determines the exception is recoverable, 1 is returned. If          * the thrower determines it is unrecoverable, 0 is returned.          */      bool isRecoverable() const         throw()      { return (severity == recoverable); }         /**          * Sets the severity of the exception.           * @param sever Use the enumeration Severity to specify          * the severity of the exception.          */      Exception& setSeverity(const Severity& sever)          throw()      { severity = sever; return *this; };         /**           * Appends the specified text to the text string on the top          * of the exception text stack.          * @param errorText The text you want to append.           */      Exception& addText(const std::string& errorText)          throw();         /**          * Returns an exception text string from the exception text          * stack.          *          * @param index The default index is 0, which is the          * top of the stack. If you specify an index which is not          * valid, a 0 pointer is returned.          */      std::string getText(const size_t& index=0) const          throw();         /// Returns the number of text strings in the exception text stack.      size_t getTextCount() const         throw();         /// Returns the name of the object's class.      std::string getName() const         throw()      { return "Exception"; };         /**          * Debug output function.          * @param s stream to output debugging information for this class to.          */      void dump(std::ostream& s) const          throw();         /// Dump to a string      std::string what() const throw();         /**          * Output stream operator for ::Exception.          * This is intended just to dump all the data in the ::Exception to          * the indicated stream.  \warning Warning:  It will _not_ preserve          * the state of the stream.          * @param s stream to send ::Exception information to.          * @param e ::Exception to "dump".          * @return a reference to the stream \c s.  */      friend std::ostream& operator<<( std::ostream& s,                                       const Exception& e )         throw();   protected:         /// Error code.      unsigned long errorId;         /// Stack of exception locations (where it was thrown).      std::vector<ExceptionLocation> locations;         /// Severity of exception.      Severity severity;         /// Text stack describing exception condition.      std::vector<std::string> text;         /**          * This is the streambuf function that actually outputs the          * data to the device.  Since all output should be done with          * the standard ostream operators, this function should never          * be called directly.  In the case of this class, the          * characters to be output are stored in a buffer and added          * to the exception text after each newline.          */      int overflow(int c);   private:         /// Buffer for stream output.      std::string streamBuffer;   }; // class Exception}  // namespace gpstk/** * Just a comment for the wary.  These following macros are quite * useful.  They just don't work under gcc 2.96/linux.  If you can fix * them I would be quite greatful but I am not holding my breath.  For * now, I am just manually putting the code where it needs to be.  The * problem seems to be with the __FILE__, __FUNCTION__, LINE__ being * defined in a macro that is in a .hpp file as opposed to the .cpp * file where the code gets used.  When you do it you get a segfault. * See the exceptiontest.cpp code in the base/test directory. */#if defined ( __FUNCTION__ )#define FILE_LOCATION gpstk::ExceptionLocation(__FILE__, __FUNCTION__, __LINE__)#else#define FILE_LOCATION gpstk::ExceptionLocation(__FILE__, "", __LINE__)#endif// For compilers without exceptions, die if you get an exception.#if defined (NO_EXCEPTIONS_SUPPORT)/// A macro for adding location when throwing an gpstk::Exception/// @ingroup exceptiongroup#define GPSTK_THROW(exc) { exc.addLocation(FILE_LOCATION); exc.terminate(); }/// A macro for adding location when rethrowing an gpstk::Exception/// @ingroup exceptiongroup#define GPSTK_RETHROW(exc) { exc.addLocation(FILE_LOCATION); exc.terminate(); }#else/// A macro for adding location when throwing an gpstk::Exception/// @ingroup exceptiongroup#define GPSTK_THROW(exc)   { exc.addLocation(FILE_LOCATION); throw exc; }/// A macro for adding location when rethrowing an gpstk::Exception/// @ingroup exceptiongroup#define GPSTK_RETHROW(exc) { exc.addLocation(FILE_LOCATION); throw; }#endif/** * A macro for quickly defining a new exception class that inherits from * an gpstk::Exception derived class.  Use this to make specific exceptions, * such as the ones defined in this header file.  Make sure that all * exceptions have "\@ingroup exceptiongroup" in their comment block * so doxygen knows what to do with them. * * @ingroup exceptiongroup */#define NEW_EXCEPTION_CLASS(child, parent) \class child : public parent  \{ \public: \      /** Default constructor. */ \   child() throw()                  : parent() {} \      /** Copy constructor. */ \   child(const child& a) throw()   : parent(a) {} \      /** Cast constructor. */ \   child(const gpstk::Exception& a) throw() : parent(a) {}; \      /** \       * Common use constructor. \       * @param a text description of exception condition. \       * @param b error code (default none) \       * @param c severity of exception (default unrecoverable) \       */ \   child(std::string a, unsigned long b = 0,\         gpstk::Exception::Severity c = gpstk::Exception::unrecoverable) \         throw() \         : parent(a, b, c) \   {};\      /** Destructor. */ \   ~child() throw() {} \      /** Returns the name of the exception class. */ \   std::string getName() const throw() {return ( # child);} \      /** assignment operator for derived exceptions */ \   child& operator=(const child& kid) \      { parent::operator=(kid); return *this; } \      /** ostream operator for derived exceptions */ \   friend std::ostream& operator<<(std::ostream& s, const child& c) throw() \      { c.dump(s); return s; } \}namespace gpstk{      /// Thrown when a function is given a parameter value that it invalid      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(InvalidParameter, Exception);      /// Thrown if a function can not satisfy a request      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(InvalidRequest, Exception);      /// Thrown when a required condition in a function is not met.      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(AssertionFailure, Exception);      /// Thrown if a function makes a request of the OS that can't be satisfied.      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(AccessError, Exception);      /// Attempts to access an "array" or other element that doesn't exist      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(IndexOutOfBoundsException, Exception);      /// A function was passed an invalid argument      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(InvalidArgumentException, Exception);      /// Application's configuration is invalid      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(ConfigurationException, Exception);      /// Attempted to open a file that doesn't exist      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(FileMissingException, Exception);      /// A problem using a system semaphore      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(SystemSemaphoreException, Exception);      /// A problem using a system pipe      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(SystemPipeException, Exception);      /// A problem using a system queue      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(SystemQueueException, Exception);      /// Unable to allocate memory      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(OutOfMemory, Exception);      /// Operation failed because it was unable to locate the requested obj      /// @ingroup exceptiongroup   NEW_EXCEPTION_CLASS(ObjectNotFound, AccessError);} // namespace gpstk#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -