00001 
00010 #ifndef __SIMGEAR_MISC_EXCEPTION_HXX
00011 #define __SIMGEAR_MISC_EXCEPTION_HXX 1
00012 
00013 #include <exception>
00014 #include <simgear/compiler.h>
00015 #include <string>
00016 
00017 using std::string;
00018 
00026 class sg_location
00027 {
00028 public:
00029   enum {max_path = 1024};
00030   sg_location ();
00031   sg_location(const std::string& path, int line = -1, int column = -1);  
00032   explicit sg_location(const char* path, int line = -1, int column = -1);
00033   virtual ~sg_location() throw ();
00034   virtual const char* getPath() const;
00035   virtual void setPath (const char* path);
00036   virtual int getLine () const;
00037   virtual void setLine (int line);
00038   virtual int getColumn () const;
00039   virtual void setColumn (int column);
00040   virtual int getByte () const;
00041   virtual void setByte (int byte);
00042   virtual std::string asString () const;
00043 private:
00044   char _path[max_path];
00045   int _line;
00046   int _column;
00047   int _byte;
00048 };
00049 
00050 
00054 class sg_throwable : public std::exception
00055 {
00056 public:
00057   enum {MAX_TEXT_LEN = 1024};
00058   sg_throwable ();
00059   sg_throwable (const char* message, const char* origin = 0);
00060   virtual ~sg_throwable () throw ();
00061   virtual const char* getMessage () const;
00062   virtual const std::string getFormattedMessage () const;
00063   virtual void setMessage (const char* message);
00064   virtual const char* getOrigin () const;
00065   virtual void setOrigin (const char *origin);
00066   virtual const char* what() const throw();
00067 private:
00068   char _message[MAX_TEXT_LEN];
00069   char _origin[MAX_TEXT_LEN];
00070 };
00071 
00072 
00073 
00083 class sg_error : public sg_throwable
00084 {
00085 public:
00086   sg_error ();
00087   sg_error (const char* message, const char* origin = 0);
00088   sg_error (const std::string& message, const std::string& origin = "");  
00089   virtual ~sg_error () throw ();
00090 };
00091 
00092 
00107 class sg_exception : public sg_throwable
00108 {
00109 public:
00110   sg_exception ();
00111   sg_exception (const char* message, const char* origin = 0);
00112   sg_exception (const std::string& message, const std::string& = "");
00113   virtual ~sg_exception () throw ();
00114 };
00115 
00116 
00128 class sg_io_exception : public sg_exception
00129 {
00130 public:
00131   sg_io_exception ();
00132   sg_io_exception (const char* message, const char* origin = 0);
00133   sg_io_exception (const char* message, const sg_location &location,
00134                    const char* origin = 0);
00135   sg_io_exception (const std::string &message, const std::string &origin = "");
00136   virtual ~sg_io_exception () throw ();
00137   virtual const std::string getFormattedMessage () const;
00138   virtual const sg_location &getLocation () const;
00139   virtual void setLocation (const sg_location &location);
00140 private:
00141   sg_location _location;
00142 };
00143 
00144 
00156 class sg_format_exception : public sg_exception
00157 {
00158 public:
00159   sg_format_exception ();
00160   sg_format_exception (const char* message, const char* text,
00161                        const char* origin = 0);
00162   sg_format_exception (const std::string& message, const std::string& text,
00163                        const std::string& origin = "");
00164   virtual ~sg_format_exception () throw ();
00165   virtual const char* getText () const;
00166   virtual void setText (const char* text);
00167 private:
00168   char _text[MAX_TEXT_LEN];
00169 };
00170 
00171 
00181 class sg_range_exception : public sg_exception
00182 {
00183 public:
00184   sg_range_exception ();
00185   sg_range_exception (const char* message,
00186                       const char* origin = 0);
00187   sg_range_exception (const std::string& message,
00188                       const std::string& origin = "");
00189   virtual ~sg_range_exception () throw ();
00190 };
00191 
00192 #endif
00193 
00194