Exception.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * Copyright (c) 2006 The Zdeno Ash Miklas
  19. *
  20. * This source file is part of VideoTexture library
  21. *
  22. * Contributor(s):
  23. *
  24. * ***** END GPL LICENSE BLOCK *****
  25. */
  26. /** \file gameengine/VideoTexture/Exception.h
  27. * \ingroup bgevideotex
  28. */
  29. #ifndef __EXCEPTION_H__
  30. #define __EXCEPTION_H__
  31. #include <exception>
  32. #include <vector>
  33. #include <string>
  34. #include <algorithm>
  35. #include "Common.h"
  36. #define CHCKHRSLTV(fnc,val,err) \
  37. { \
  38. HRESULT macroHRslt = (fnc); \
  39. if (macroHRslt != val) \
  40. throw Exception (err, macroHRslt, __FILE__, __LINE__); \
  41. }
  42. #define THRWEXCP(err,hRslt) throw Exception (err, hRslt, __FILE__, __LINE__)
  43. #if defined WIN32
  44. #define CHCKHRSLT(fnc,err) \
  45. { \
  46. HRESULT macroHRslt = (fnc); \
  47. if (FAILED(macroHRslt)) \
  48. throw Exception (err, macroHRslt, __FILE__, __LINE__); \
  49. }
  50. #else
  51. #define CHCKHRSLT(fnc,err) CHCKHRSLTV(fnc,S_OK,err)
  52. #endif
  53. // forward declarations
  54. class ExceptionID;
  55. class Exception;
  56. // exception identificators
  57. extern ExceptionID ErrGeneral, ErrNotFound;
  58. // result type
  59. typedef long RESULT;
  60. // class ExceptionID for exception identification
  61. class ExceptionID
  62. {
  63. public:
  64. // constructor a destructor
  65. ExceptionID (void) {}
  66. ~ExceptionID (void) {}
  67. private:
  68. // not allowed
  69. ExceptionID (const ExceptionID & obj) throw() {}
  70. ExceptionID & operator= (const ExceptionID & obj) throw() { return *this; }
  71. };
  72. // class ExpDesc for exception description
  73. class ExpDesc
  74. {
  75. public:
  76. // constructor a destructor
  77. ExpDesc (ExceptionID & exp, const char * desc, RESULT hres = S_OK);
  78. ~ExpDesc (void);
  79. // comparision function
  80. // returns 0, if exception identification don't match at all
  81. // returns 1, if only exception identification is matching
  82. // returns 2, if both exception identification and result are matching
  83. int isExp (ExceptionID *exp, RESULT hres = S_OK) throw()
  84. {
  85. // check exception identification
  86. if (&m_expID == exp)
  87. {
  88. // check result value
  89. if (m_hRslt == hres) return 2;
  90. // only identification match
  91. if (m_hRslt == S_OK) return 1;
  92. }
  93. // no match
  94. return 0;
  95. }
  96. // get exception description
  97. void loadDesc (std::string & desc) throw()
  98. {
  99. desc = m_description;
  100. }
  101. void registerDesc(void)
  102. {
  103. if (std::find(m_expDescs.begin(), m_expDescs.end(), this) == m_expDescs.end())
  104. m_expDescs.push_back(this);
  105. }
  106. // list of exception descriptions
  107. static std::vector<ExpDesc*> m_expDescs;
  108. private:
  109. // exception ID
  110. ExceptionID & m_expID;
  111. // result
  112. RESULT m_hRslt;
  113. // description
  114. const char * m_description;
  115. // not allowed
  116. ExpDesc (const ExpDesc & obj) : m_expID (ErrNotFound) {}
  117. ExpDesc & operator= (const ExpDesc & obj) { return *this; }
  118. };
  119. // class Exception
  120. class Exception : public std::exception
  121. {
  122. public:
  123. // constructor
  124. Exception ();
  125. // destructor
  126. virtual ~Exception () throw();
  127. // copy constructor
  128. Exception (const Exception & xpt);
  129. // assignment operator
  130. Exception & operator= (const Exception & xpt);
  131. // get exception description
  132. virtual const char * what(void);
  133. // debug version of constructor
  134. Exception (ExceptionID & expID, RESULT rslt, const char * fil, int lin);
  135. // set source file and line of exception
  136. void setFileLine (const char * fil, int lin);
  137. // get description in string
  138. std::string & getDesc (void) throw() { return m_desc; }
  139. // report exception
  140. virtual void report (void);
  141. // get exception id
  142. ExceptionID * getID (void) throw() { return m_expID; }
  143. /// last exception description
  144. static std::string m_lastError;
  145. /// log file name
  146. static const char * m_logFile;
  147. protected:
  148. // exception identification
  149. ExceptionID * m_expID;
  150. // RESULT code
  151. RESULT m_hRslt;
  152. // exception description
  153. std::string m_desc;
  154. // set exception description
  155. virtual void setXptDesc (void);
  156. // copy exception
  157. void copy (const Exception & xpt);
  158. // file name where exception was thrown
  159. std::string m_fileName;
  160. // line number in file
  161. int m_line;
  162. };
  163. extern ExpDesc MaterialNotAvailDesc;
  164. extern ExpDesc ImageSizesNotMatchDesc;
  165. extern ExpDesc ImageHasExportsDesc;
  166. extern ExpDesc InvalidColorChannelDesc;
  167. extern ExpDesc InvalidImageModeDesc;
  168. extern ExpDesc SceneInvalidDesc;
  169. extern ExpDesc CameraInvalidDesc;
  170. extern ExpDesc ObserverInvalidDesc;
  171. extern ExpDesc OffScreenInvalidDesc;
  172. extern ExpDesc MirrorInvalidDesc;
  173. extern ExpDesc MirrorSizeInvalidDesc;
  174. extern ExpDesc MirrorNormalInvalidDesc;
  175. extern ExpDesc MirrorHorizontalDesc;
  176. extern ExpDesc MirrorTooSmallDesc;
  177. extern ExpDesc SourceVideoEmptyDesc;
  178. extern ExpDesc SourceVideoCreationDesc;
  179. extern ExpDesc DeckLinkBadDisplayModeDesc;
  180. extern ExpDesc DeckLinkBadPixelFormatDesc;
  181. extern ExpDesc AutoDetectionNotAvailDesc;
  182. extern ExpDesc DeckLinkOpenCardDesc;
  183. extern ExpDesc DeckLinkBadFormatDesc;
  184. extern ExpDesc DeckLinkInternalErrorDesc;
  185. extern ExpDesc SourceVideoOnlyCaptureDesc;
  186. extern ExpDesc VideoDeckLinkBadFormatDesc;
  187. extern ExpDesc VideoDeckLinkOpenCardDesc;
  188. extern ExpDesc VideoDeckLinkDvpInternalErrorDesc;
  189. extern ExpDesc VideoDeckLinkPinMemoryErrorDesc;
  190. extern ExceptionID InvalidImageMode;
  191. void registerAllExceptions(void);
  192. #endif