exception.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00036 #ifndef __exception__header__
00037 #define __exception__header__
00038 
00039 #include "gpucalc/prerequisites.h"
00040 
00041 #if PLATFORM == PLATFORM_WIN32
00042 #pragma warning (disable : 4100)
00043 #endif
00044 
00045 namespace gpucalc
00046 {
00047 
00048 
00049 
00050 
00054  enum ExceptionCodes
00055  {
00056   ERR_CANNOT_WRITE_TO_FILE,
00057   ERR_INVALID_STATE,
00058   ERR_INVALIDPARAMS,
00059   ERR_RENDERINGAPI_ERROR,
00060   ERR_DUPLICATE_ITEM,
00061   ERR_ITEM_NOT_FOUND,
00062   ERR_FILE_NOT_FOUND,
00063   ERR_INTERNAL_ERROR,
00064   ERR_RT_ASSERTION_FAILED,
00065   ERR_SOURCE_COMPILATION_ERROR,
00066   ERR_VALUE_NOT_DELETED_ERROR,
00067   ERR_NOT_IMPLEMENTED
00068  };
00069 
00070 
00087  class _GpuCalcExport Exception : public std::exception
00088  {
00089   protected:
00090    long mLine;
00091    const Object * mObject;
00092    int mNumber;
00093    std::string mTypeName;
00094    std::string mDescription;
00095    std::string mSource;
00096    std::string mFile;
00097    mutable std::string mFullDesc;
00098 
00099 
00100   public:
00101 
00102 
00103 
00107    Exception(int number, const Object & object, const std::string & description, const std::string & source);
00108 
00109 
00113    Exception(int number, const Object & object, const std::string & description, const std::string & source,
00114     const char * type, const char * file, long line);
00115 
00116 
00120    Exception(const Exception & rhs);
00121 
00122 
00126    ~Exception() throw()
00127    {
00128    }
00129 
00130 
00134    void operator = (const Exception & rhs);
00135 
00136 
00148    virtual const std::string & getFullDescription() const;
00149 
00150 
00154    virtual int getNumber() const throw();
00155 
00156 
00160    virtual const std::string & getSource() const
00161    {
00162     return mSource;
00163    }
00164 
00165 
00169    virtual const std::string & getFile() const
00170    {
00171     return mFile;
00172    }
00173 
00174 
00178    virtual long getLine() const
00179    {
00180     return mLine;
00181    }
00182 
00183 
00190    virtual const std::string & getDescription() const
00191    {
00192     return mDescription;
00193    }
00194 
00195 
00199    const char * what() const throw()
00200    {
00201     return getFullDescription().c_str();
00202    }
00203  };
00204 
00205 
00206  // Specialised exceptions allowing each to be caught specifically
00207  // backwards-compatible since exception codes still used
00208  class UnimplementedException : public Exception
00209  {
00210   public:
00211    UnimplementedException(int number, const Object & object, const std::string & description, const std::string & source, const char * file, long line):
00212     Exception(number, object, description, source, "UnimplementedException", file, line)
00213    {
00214    }
00215  };
00216 
00217 
00218  class FileNotFoundException : public Exception
00219  {
00220   public:
00221    FileNotFoundException(int number, const Object & object, const std::string & description, const std::string & source, const char * file, long line):
00222     Exception(number, object, description, source, "FileNotFoundException", file, line)
00223    {
00224    }
00225  };
00226 
00227 
00228  class IOException : public Exception
00229  {
00230   public:
00231    IOException(int number, const Object & object, const std::string & description, const std::string & source, const char * file, long line):
00232     Exception(number, object, description, source, "IOException", file, line)
00233    {
00234    }
00235  };
00236 
00237 
00238  class InvalidStateException : public Exception
00239  {
00240   public:
00241    InvalidStateException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00242     Exception(number, object, description, source, "InvalidStateException", file, line)
00243    {
00244    }
00245  };
00246 
00247 
00248  class InvalidParametersException : public Exception
00249  {
00250   public:
00251    InvalidParametersException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00252     Exception(number, object, description, source, "InvalidParametersException", file, line)
00253    {
00254    }
00255  };
00256 
00257 
00258  class ItemIdentityException : public Exception
00259  {
00260   public:
00261    ItemIdentityException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00262     Exception(number, object, description, source, "ItemIdentityException", file, line)
00263    {
00264    }
00265  };
00266 
00267 
00268  class InternalErrorException : public Exception
00269  {
00270   public:
00271    InternalErrorException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00272     Exception(number, object, description, source, "InternalErrorException", file, line)
00273    {
00274    }
00275  };
00276 
00277 
00278  class RenderingAPIException : public Exception
00279  {
00280   public:
00281    RenderingAPIException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00282     Exception(number, object, description, source, "RenderingAPIException", file, line)
00283    {
00284    }
00285  };
00286 
00287 
00288  class RuntimeAssertionException : public Exception
00289  {
00290   public:
00291    RuntimeAssertionException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00292     Exception(number, object, description, source, "RuntimeAssertionException", file, line)
00293    {
00294    }
00295  };
00296 
00297 
00298  class SourceCompilationException : public Exception
00299  {
00300   public:
00301    SourceCompilationException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00302     Exception(number, object, description, source, "SourceCompilationException", file, line)
00303     {
00304     }
00305  };
00306 
00307 
00308  class ValueNotDeletedException : public Exception
00309  {
00310   public:
00311    ValueNotDeletedException(int number, const Object & object, const std::string & description, const std::string & source, const char* file, long line):
00312     Exception(number, object, description, source, "ValueNotDeletedException", file, line)
00313     {
00314     }
00315  };
00316 
00317 
00328  class ExceptionFactory
00329  {
00330   private:
00331 
00335    ExceptionFactory()
00336    {
00337    }
00338 
00339 
00340   public:
00341    static UnimplementedException create(Int2Type<ERR_NOT_IMPLEMENTED> code,
00342     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00343    {
00344     return UnimplementedException(code.number, object, desc, src, file, line);
00345    }
00346 
00347 
00348    static FileNotFoundException create(Int2Type<ERR_FILE_NOT_FOUND> code,
00349     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00350    {
00351     return FileNotFoundException(code.number, object, desc, src, file, line);
00352    }
00353 
00354 
00355    static IOException create(Int2Type<ERR_CANNOT_WRITE_TO_FILE> code,
00356     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00357    {
00358     return IOException(code.number, object, desc, src, file, line);
00359    }
00360 
00361 
00362    static InvalidStateException create(Int2Type<ERR_INVALID_STATE> code,
00363     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00364    {
00365     return InvalidStateException(code.number, object, desc, src, file, line);
00366    }
00367 
00368 
00369    static InvalidParametersException create(Int2Type<ERR_INVALIDPARAMS> code,
00370     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00371    {
00372     return InvalidParametersException(code.number, object, desc, src, file, line);
00373    }
00374 
00375 
00376    static ItemIdentityException create(Int2Type<ERR_ITEM_NOT_FOUND> code,
00377     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00378    {
00379     return ItemIdentityException(code.number, object, desc, src, file, line);
00380    }
00381 
00382 
00383    static ItemIdentityException create(Int2Type<ERR_DUPLICATE_ITEM> code,
00384     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00385    {
00386     return ItemIdentityException(code.number, object, desc, src, file, line);
00387    }
00388 
00389 
00390    static InternalErrorException create(Int2Type<ERR_INTERNAL_ERROR> code,
00391     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00392    {
00393     return InternalErrorException(code.number, object, desc, src, file, line);
00394    }
00395 
00396 
00397    static RenderingAPIException create(Int2Type<ERR_RENDERINGAPI_ERROR> code,
00398     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00399    {
00400     return RenderingAPIException(code.number, object, desc, src, file, line);
00401    }
00402 
00403 
00404    static RuntimeAssertionException create(Int2Type<ERR_RT_ASSERTION_FAILED> code,
00405     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00406    {
00407     return RuntimeAssertionException(code.number, object, desc, src, file, line);
00408    }
00409 
00410 
00411    static SourceCompilationException create(Int2Type<ERR_SOURCE_COMPILATION_ERROR> code,
00412     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00413    {
00414     return SourceCompilationException(code.number, object, desc, src, file, line);
00415    }
00416 
00417 
00418    static ValueNotDeletedException create(Int2Type<ERR_VALUE_NOT_DELETED_ERROR> code,
00419     const Object & object, const std::string & desc, const std::string & src, const char * file, long line)
00420    {
00421     return ValueNotDeletedException(code.number, object, desc, src, file, line);
00422    }
00423 
00424 
00425 
00426    static UnimplementedException create(Int2Type<ERR_NOT_IMPLEMENTED> code,
00427      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00428    {
00429     return UnimplementedException(code.number, *object, desc, src, file, line);
00430    }
00431 
00432 
00433    static FileNotFoundException create(Int2Type<ERR_FILE_NOT_FOUND> code,
00434      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00435    {
00436     return FileNotFoundException(code.number, *object, desc, src, file, line);
00437    }
00438 
00439 
00440    static IOException create(Int2Type<ERR_CANNOT_WRITE_TO_FILE> code,
00441            const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00442    {
00443     return IOException(code.number, *object, desc, src, file, line);
00444    }
00445 
00446 
00447    static InvalidStateException create(Int2Type<ERR_INVALID_STATE> code,
00448      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00449    {
00450     return InvalidStateException(code.number, *object, desc, src, file, line);
00451    }
00452 
00453 
00454    static InvalidParametersException create(Int2Type<ERR_INVALIDPARAMS> code,
00455      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00456    {
00457     return InvalidParametersException(code.number, *object, desc, src, file, line);
00458    }
00459 
00460 
00461    static ItemIdentityException create(Int2Type<ERR_ITEM_NOT_FOUND> code,
00462      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00463    {
00464     return ItemIdentityException(code.number, *object, desc, src, file, line);
00465    }
00466 
00467 
00468    static ItemIdentityException create(Int2Type<ERR_DUPLICATE_ITEM> code,
00469      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00470    {
00471     return ItemIdentityException(code.number, *object, desc, src, file, line);
00472    }
00473 
00474 
00475    static InternalErrorException create(Int2Type<ERR_INTERNAL_ERROR> code,
00476      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00477    {
00478     return InternalErrorException(code.number, *object, desc, src, file, line);
00479    }
00480 
00481 
00482    static RenderingAPIException create(Int2Type<ERR_RENDERINGAPI_ERROR> code,
00483      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00484    {
00485     return RenderingAPIException(code.number, *object, desc, src, file, line);
00486    }
00487 
00488 
00489    static RuntimeAssertionException create(Int2Type<ERR_RT_ASSERTION_FAILED> code,
00490      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00491    {
00492     return RuntimeAssertionException(code.number, *object, desc, src, file, line);
00493    }
00494 
00495 
00496    static SourceCompilationException create(Int2Type<ERR_SOURCE_COMPILATION_ERROR> code,
00497      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00498    {
00499     return SourceCompilationException(code.number, *object, desc, src, file, line);
00500    }
00501 
00502 
00503    static ValueNotDeletedException create(Int2Type<ERR_VALUE_NOT_DELETED_ERROR> code,
00504      const Object * object, const std::string & desc, const std::string & src, const char * file, long line)
00505    {
00506     return ValueNotDeletedException(code.number, *object, desc, src, file, line);
00507    }
00508  };
00509 
00510 
00526  template <ExceptionCodes Value> void Except(const Object * obj, const std::string & Description, const std::string & Source,
00527   const std::string & File, int Line)
00528  {
00529   throw ExceptionFactory::create(Int2Type<Value>(), obj, Description, Source, File.c_str(), Line);
00530  }
00531 
00532  template <ExceptionCodes Value> void Except(const Object & obj, const std::string & Description, const std::string & Source,
00533   const std::string & File, int Line)
00534  {
00535   Except<Value>(&obj, Description, Source, File, Line);
00536  }
00537 
00538 
00539  namespace _workaround
00540  {
00541   class _GpuCalcExport DoWarning
00542   {
00543    public:
00544     static void doWarning(const Object * obj, const std::string & Description, const std::string & Source, const std::string & File, int Line);
00545   };
00546  }
00547  
00548  template <ExceptionCodes Value> void Warning(const Object * obj, const std::string & Description, const std::string & Source,
00549   const std::string & File, int Line)
00550  {
00551   _workaround::DoWarning::doWarning(obj, Description, Source, File, Line);
00552  }
00553 
00554  template <ExceptionCodes Value> void Warning(const Object & obj, const std::string & Description, const std::string & Source,
00555   const std::string & File, int Line)
00556  {
00557   Warning<Value>(&obj, Description, Source, File, Line);
00558  }
00559 }
00560 
00561 #if PLATFORM == PLATFORM_WIN32
00562 #pragma warning (default : 4100)
00563 #endif
00564 
00565 #endif

Generated on Thu Mar 5 22:36:42 2009 for gpucalc by  doxygen 1.5.6