2 -----------------------------------------------------------------------------
3 This source file is part of VideoTexture library
5 Copyright (c) 2006 The Zdeno Ash Miklas
7 This program is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
12 This program is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
19 http://www.gnu.org/copyleft/lesser.txt.
20 -----------------------------------------------------------------------------
24 #if !defined EXCEPTION_H
35 #define CHCKHRSLTV(fnc,val,err) \
37 HRESULT macroHRslt = (fnc); \
38 if (macroHRslt != val) \
39 throw Exception (err, macroHRslt, __FILE__, __LINE__); \
42 #define THRWEXCP(err,hRslt) throw Exception (err, hRslt, __FILE__, __LINE__);
47 #define CHCKHRSLT(fnc,err) \
49 HRESULT macroHRslt = (fnc); \
50 if (FAILED(macroHRslt)) \
51 throw Exception (err, macroHRslt, __FILE__, __LINE__); \
56 #define CHCKHRSLT(fnc,err) CHCKHRSLTV(fnc,S_OK,err)
61 // forward declarations
66 // exception identificators
67 extern ExceptionID ErrGeneral, ErrNotFound;
74 // class ExceptionID for exception identification
78 // constructor a destructor
80 ~ExceptionID (void) {}
84 ExceptionID (const ExceptionID & obj) throw() {}
85 ExceptionID & operator= (const ExceptionID & obj) throw() { return *this; }
89 // class ExpDesc for exception description
93 // constructor a destructor
94 ExpDesc (ExceptionID & exp, char * desc, RESULT hres = S_OK);
97 // comparision function
98 // returns 0, if exception identification don't match at all
99 // returns 1, if only exception identification is matching
100 // returns 2, if both exception identification and result are matching
101 int isExp (ExceptionID * exp, RESULT hres = S_OK) throw()
103 // check exception identification
106 // check result value
107 if (m_hRslt == hres) return 2;
108 // only identification match
109 if (m_hRslt == S_OK) return 1;
115 // get exception description
116 void loadDesc (std::string & desc) throw()
118 desc = m_description;
121 void registerDesc(void)
123 if (std::find(m_expDescs.begin(), m_expDescs.end(), this) == m_expDescs.end())
124 m_expDescs.push_back(this);
126 // list of exception descriptions
127 static std::vector<ExpDesc*> m_expDescs;
131 ExceptionID & m_expID;
135 char * m_description;
138 ExpDesc (const ExpDesc & obj) : m_expID (ErrNotFound) {}
139 ExpDesc & operator= (const ExpDesc & obj) { return *this; }
145 class Exception : public std::exception
151 virtual ~Exception () throw();
153 Exception (const Exception & xpt);
154 // assignment operator
155 Exception & operator= (const Exception & xpt);
156 // get exception description
157 virtual const char * what(void);
159 // debug version of constructor
160 Exception (ExceptionID & expID, RESULT rslt, char * fil, int lin);
161 // set source file and line of exception
162 void setFileLine (char * fil, int lin);
164 // get description in string
165 std::string & getDesc (void) throw() { return m_desc; }
168 virtual void report (void);
171 ExceptionID * getID (void) throw() { return m_expID; }
173 /// last exception description
174 static std::string m_lastError;
177 static char * m_logFile;
180 // exception identification
181 ExceptionID * m_expID;
185 // exception description
188 // set exception description
189 virtual void setXptDesc (void);
192 void copy (const Exception & xpt);
194 // file name where exception was thrown
195 std::string m_fileName;
196 // line number in file
201 extern ExpDesc MaterialNotAvailDesc;
202 extern ExpDesc ImageSizesNotMatchDesc;
203 extern ExpDesc SceneInvalidDesc;
204 extern ExpDesc CameraInvalidDesc;
205 extern ExpDesc ObserverInvalidDesc;
206 extern ExpDesc MirrorInvalidDesc;
207 extern ExpDesc MirrorSizeInvalidDesc;
208 extern ExpDesc MirrorNormalInvalidDesc;
209 extern ExpDesc MirrorHorizontalDesc;
210 extern ExpDesc MirrorTooSmallDesc;
211 extern ExpDesc SourceVideoEmptyDesc;
212 extern ExpDesc SourceVideoCreationDesc;
215 void registerAllExceptions(void);