Blender V2.61 - r43446

Exception.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of VideoTexture library
00004 
00005 Copyright (c) 2006 The Zdeno Ash Miklas
00006 
00007 This program is free software; you can redistribute it and/or modify it under
00008 the terms of the GNU Lesser General Public License as published by the Free Software
00009 Foundation; either version 2 of the License, or (at your option) any later
00010 version.
00011 
00012 This program is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License along with
00017 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00018 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00019 http://www.gnu.org/copyleft/lesser.txt.
00020 -----------------------------------------------------------------------------
00021 */
00022 
00023 
00028 #if !defined EXCEPTION_H
00029 #define EXCEPTION_H
00030 
00031 #include <exception>
00032 #include <vector>
00033 #include <string>
00034 #include <algorithm>
00035 
00036 #include "Common.h"
00037 
00038 
00039 #define CHCKHRSLTV(fnc,val,err) \
00040 { \
00041     HRESULT macroHRslt = (fnc); \
00042     if (macroHRslt != val) \
00043     throw Exception (err, macroHRslt, __FILE__, __LINE__); \
00044 }
00045 
00046 #define THRWEXCP(err,hRslt) throw Exception (err, hRslt, __FILE__, __LINE__);
00047 
00048 
00049 #if defined WIN32
00050 
00051 #define CHCKHRSLT(fnc,err) \
00052 { \
00053     HRESULT macroHRslt = (fnc); \
00054     if (FAILED(macroHRslt)) \
00055     throw Exception (err, macroHRslt, __FILE__, __LINE__); \
00056 }
00057 
00058 #else
00059 
00060 #define CHCKHRSLT(fnc,err) CHCKHRSLTV(fnc,S_OK,err)
00061 
00062 #endif
00063 
00064 
00065 // forward declarations
00066 class ExceptionID;
00067 class Exception;
00068 
00069 
00070 // exception identificators
00071 extern ExceptionID ErrGeneral, ErrNotFound;
00072 
00073 
00074 // result type
00075 typedef long RESULT;
00076 
00077 
00078 // class ExceptionID for exception identification
00079 class ExceptionID
00080 {
00081 public:
00082     // constructor a destructor
00083     ExceptionID (void) {}
00084     ~ExceptionID (void) {}
00085 
00086 private:
00087     // not allowed 
00088     ExceptionID (const ExceptionID & obj) throw() {}
00089     ExceptionID & operator= (const ExceptionID & obj) throw() { return *this; }
00090 };
00091 
00092 
00093 // class ExpDesc for exception description
00094 class ExpDesc
00095 {
00096 public:
00097     // constructor a destructor
00098     ExpDesc (ExceptionID & exp, const char * desc, RESULT hres = S_OK);
00099     ~ExpDesc (void);
00100 
00101     // comparision function
00102     // returns 0, if exception identification don't match at all
00103     // returns 1, if only exception identification is matching
00104     // returns 2, if both exception identification and result are matching
00105     int isExp (ExceptionID * exp, RESULT hres = S_OK) throw()
00106     {
00107         // check exception identification
00108         if (&m_expID == exp)
00109         {
00110             // check result value
00111             if (m_hRslt == hres) return 2;
00112             // only identification match
00113             if (m_hRslt == S_OK) return 1;
00114         }
00115         // no match
00116         return 0;
00117     }
00118 
00119     // get exception description
00120     void loadDesc (std::string & desc) throw()
00121     {
00122         desc = m_description;
00123     }
00124 
00125     void registerDesc(void)
00126     {
00127         if (std::find(m_expDescs.begin(), m_expDescs.end(), this) == m_expDescs.end())
00128             m_expDescs.push_back(this);
00129     }
00130     // list of exception descriptions
00131     static std::vector<ExpDesc*> m_expDescs;
00132 
00133 private:
00134     // exception ID
00135     ExceptionID & m_expID;
00136     // result
00137     RESULT m_hRslt;
00138     // description
00139     const char * m_description;
00140 
00141     // not allowed
00142     ExpDesc (const ExpDesc & obj) : m_expID (ErrNotFound) {}
00143     ExpDesc & operator= (const ExpDesc & obj) { return *this; }
00144 };
00145 
00146 
00147 
00148 // class Exception
00149 class Exception : public std::exception  
00150 {
00151 public:
00152     // constructor
00153     Exception ();
00154     // destructor
00155     virtual ~Exception () throw();
00156     // copy constructor
00157     Exception (const Exception & xpt);
00158     // assignment operator
00159     Exception & operator= (const Exception & xpt);
00160     // get exception description
00161     virtual const char * what(void);
00162 
00163     // debug version of constructor
00164     Exception (ExceptionID & expID, RESULT rslt, const char * fil, int lin);
00165     // set source file and line of exception
00166     void setFileLine (const char * fil, int lin);
00167 
00168     // get description in string
00169     std::string & getDesc (void) throw() { return m_desc; }
00170 
00171     // report exception
00172     virtual void report (void);
00173 
00174     // get exception id
00175     ExceptionID * getID (void) throw() { return m_expID; }
00176 
00178     static std::string m_lastError;
00179 
00181     static const char * m_logFile;
00182 
00183 protected:
00184     // exception identification
00185     ExceptionID * m_expID;
00186     // RESULT code
00187     RESULT m_hRslt;
00188 
00189     // exception description
00190     std::string m_desc;
00191 
00192     // set exception description
00193     virtual void setXptDesc (void);
00194 
00195     // copy exception
00196     void copy (const Exception & xpt);
00197 
00198     // file name where exception was thrown
00199     std::string m_fileName;
00200     // line number in file
00201     int m_line;
00202 
00203 };
00204 
00205 extern ExpDesc MaterialNotAvailDesc;
00206 extern ExpDesc ImageSizesNotMatchDesc;
00207 extern ExpDesc ImageHasExportsDesc;
00208 extern ExpDesc InvalidColorChannelDesc;
00209 extern ExpDesc SceneInvalidDesc;
00210 extern ExpDesc CameraInvalidDesc;
00211 extern ExpDesc ObserverInvalidDesc;
00212 extern ExpDesc MirrorInvalidDesc;
00213 extern ExpDesc MirrorSizeInvalidDesc;
00214 extern ExpDesc MirrorNormalInvalidDesc;
00215 extern ExpDesc MirrorHorizontalDesc;
00216 extern ExpDesc MirrorTooSmallDesc;
00217 extern ExpDesc SourceVideoEmptyDesc;
00218 extern ExpDesc SourceVideoCreationDesc;
00219 
00220 
00221 void registerAllExceptions(void);
00222 #endif