home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / h / vd2 / system / protscope.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  9.4 KB  |  246 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    System library component
  3. //    Copyright (C) 1998-2007 Avery Lee, All Rights Reserved.
  4. //
  5. //    Beginning with 1.6.0, the VirtualDub system library is licensed
  6. //    differently than the remainder of VirtualDub.  This particular file is
  7. //    thus licensed as follows (the "zlib" license):
  8. //
  9. //    This software is provided 'as-is', without any express or implied
  10. //    warranty.  In no event will the authors be held liable for any
  11. //    damages arising from the use of this software.
  12. //
  13. //    Permission is granted to anyone to use this software for any purpose,
  14. //    including commercial applications, and to alter it and redistribute it
  15. //    freely, subject to the following restrictions:
  16. //
  17. //    1.    The origin of this software must not be misrepresented; you must
  18. //        not claim that you wrote the original software. If you use this
  19. //        software in a product, an acknowledgment in the product
  20. //        documentation would be appreciated but is not required.
  21. //    2.    Altered source versions must be plainly marked as such, and must
  22. //        not be misrepresented as being the original software.
  23. //    3.    This notice may not be removed or altered from any source
  24. //        distribution.
  25.  
  26. #ifndef f_VD2_SYSTEM_PROTSCOPE_H
  27. #define f_VD2_SYSTEM_PROTSCOPE_H
  28.  
  29. #ifdef _MSC_VER
  30.     #pragma once
  31. #endif
  32.  
  33. ///////////////////////////////////////////////////////////////////////////
  34. //
  35. // Protected scope macros
  36. //
  37. // These macros allow you to define a scope which is known to the crash
  38. // handler -- that is, if the application crashes within a protected scope
  39. // the handler will report the scope information in the crash output.
  40. //
  41.  
  42. class VDProtectedAutoScope;
  43.  
  44. typedef VDProtectedAutoScope *(*tpVDGetProtectedScopeLink)();
  45. typedef void (*tpVDSetProtectedScopeLink)(VDProtectedAutoScope *);
  46.  
  47. extern tpVDGetProtectedScopeLink g_pVDGetProtectedScopeLink;
  48. extern tpVDSetProtectedScopeLink g_pVDSetProtectedScopeLink;
  49.  
  50. // The reason for this function is a bug in the Intel compiler regarding
  51. // construction optimization -- it stores VDProtectedAutoScope::'vtable'
  52. // in the vtable slot instead of VDProtectedAutoScope1<T>::'vtable', thus
  53. // killing the printf()s. "volatile" doesn't work to fix the problem, but
  54. // calling an opaque global function does.  Oh well.
  55.  
  56. #ifdef __INTEL_COMPILER
  57. void VDProtectedAutoScopeICLWorkaround();
  58. #endif
  59.  
  60. class IVDProtectedScopeOutput {
  61. public:
  62.     virtual void write(const char *s) = 0;
  63.     virtual void writef(const char *s, ...) = 0;
  64. };
  65.  
  66. class VDProtectedAutoScope {
  67. public:
  68.     VDProtectedAutoScope(const char *file, int line, const char *action) : mpFile(file), mLine(line), mpAction(action), mpLink(g_pVDGetProtectedScopeLink()) {
  69.         // Note that the assignment to g_protectedScopeLink cannot occur here, as the
  70.         // derived class has not been constructed yet.  Uninitialized objects in
  71.         // the debugging chain are *bad*.
  72.     }
  73.  
  74.     ~VDProtectedAutoScope() {
  75.         g_pVDSetProtectedScopeLink(mpLink);
  76.     }
  77.  
  78.     operator bool() const { return false; }
  79.  
  80.     virtual void Write(IVDProtectedScopeOutput& out) {
  81.         out.write(mpAction);
  82.     }
  83.  
  84.     VDProtectedAutoScope *mpLink;
  85.     const char *const mpFile;
  86.     const int mLine;
  87.     const char *const mpAction;
  88. };
  89.  
  90. class VDProtectedAutoScopeData0 {
  91. public:
  92.     VDProtectedAutoScopeData0(const char *file, int line, const char *action) : mpFile(file), mLine(line), mpAction(action) {}
  93.     const char *const mpFile;
  94.     const int mLine;
  95.     const char *const mpAction;
  96. };
  97.  
  98. template<class T1>
  99. class VDProtectedAutoScopeData1 {
  100. public:
  101.     VDProtectedAutoScopeData1(const char *file, int line, const char *action, const T1 a1) : mpFile(file), mLine(line), mpAction(action), mArg1(a1) {}
  102.     const char *const mpFile;
  103.     const int mLine;
  104.     const char *const mpAction;
  105.     const T1 mArg1;
  106. };
  107.  
  108. template<class T1, class T2>
  109. class VDProtectedAutoScopeData2 {
  110. public:
  111.     VDProtectedAutoScopeData2(const char *file, int line, const char *action, const T1 a1, const T2 a2) : mpFile(file), mLine(line), mpAction(action), mArg1(a1), mArg2(a2) {}
  112.     const char *const mpFile;
  113.     const int mLine;
  114.     const char *const mpAction;
  115.     const T1 mArg1;
  116.     const T2 mArg2;
  117. };
  118.  
  119. template<class T1, class T2, class T3>
  120. class VDProtectedAutoScopeData3 {
  121. public:
  122.     VDProtectedAutoScopeData3(const char *file, int line, const char *action, const T1 a1, const T2 a2, const T3 a3) : mpFile(file), mLine(line), mpAction(action), mArg1(a1), mArg2(a2), mArg3(a3) {}
  123.     const char *const mpFile;
  124.     const int mLine;
  125.     const char *const mpAction;
  126.     const T1 mArg1;
  127.     const T2 mArg2;
  128.     const T3 mArg3;
  129. };
  130.  
  131. template<class T1, class T2, class T3, class T4>
  132. class VDProtectedAutoScopeData4 {
  133. public:
  134.     VDProtectedAutoScopeData4(const char *file, int line, const char *action, const T1 a1, const T2 a2, const T3 a3, const T4 a4) : mpFile(file), mLine(line), mpAction(action), mArg1(a1), mArg2(a2), mArg3(a3), mArg4(a4) {}
  135.     const char *const mpFile;
  136.     const int mLine;
  137.     const char *const mpAction;
  138.     const T1 mArg1;
  139.     const T2 mArg2;
  140.     const T3 mArg3;
  141.     const T4 mArg4;
  142. };
  143.  
  144. class VDProtectedAutoScope0 : public VDProtectedAutoScope {
  145. public:
  146.     VDProtectedAutoScope0(const VDProtectedAutoScopeData0& data) : VDProtectedAutoScope(data.mpFile, data.mLine, data.mpAction) {
  147.         g_pVDSetProtectedScopeLink(this);
  148. #ifdef __INTEL_COMPILER
  149.         VDProtectedAutoScopeICLWorkaround();
  150. #endif
  151.     }
  152. };
  153.  
  154. template<class T1>
  155. class VDProtectedAutoScope1 : public VDProtectedAutoScope {
  156. public:
  157.     VDProtectedAutoScope1(const VDProtectedAutoScopeData1<T1>& data) : VDProtectedAutoScope(data.mpFile, data.mLine, data.mpAction), mArg1(data.mArg1) {
  158.         g_pVDSetProtectedScopeLink(this);
  159. #ifdef __INTEL_COMPILER
  160.         VDProtectedAutoScopeICLWorkaround();
  161. #endif
  162.     }
  163.  
  164.     virtual void Write(IVDProtectedScopeOutput& out) {
  165.         out.writef(mpAction, mArg1);
  166.     }
  167.  
  168.     const T1 mArg1;
  169. };
  170.  
  171. template<class T1, class T2>
  172. class VDProtectedAutoScope2 : public VDProtectedAutoScope {
  173. public:
  174.     VDProtectedAutoScope2(const VDProtectedAutoScopeData2<T1,T2>& data) : VDProtectedAutoScope(data.mpFile, data.mLine, data.mpAction), mArg1(data.mArg1), mArg2(data.mArg2) {
  175.         g_pVDSetProtectedScopeLink(this);
  176. #ifdef __INTEL_COMPILER
  177.         VDProtectedAutoScopeICLWorkaround();
  178. #endif
  179.     }
  180.  
  181.     virtual void Write(IVDProtectedScopeOutput& out) {
  182.         out.writef(mpAction, mArg1, mArg2);
  183.     }
  184.  
  185.     const T1 mArg1;
  186.     const T2 mArg2;
  187. };
  188.  
  189. template<class T1, class T2, class T3>
  190. class VDProtectedAutoScope3 : public VDProtectedAutoScope {
  191. public:
  192.     VDProtectedAutoScope3(const VDProtectedAutoScopeData3<T1,T2,T3>& data) : VDProtectedAutoScope(data.mpFile, data.mLine, data.mpAction), mArg1(data.mArg1), mArg2(data.mArg2), mArg3(data.mArg3) {
  193.         g_pVDSetProtectedScopeLink(this);
  194. #ifdef __INTEL_COMPILER
  195.         VDProtectedAutoScopeICLWorkaround();
  196. #endif
  197.     }
  198.  
  199.     virtual void Write(IVDProtectedScopeOutput& out) {
  200.         out.writef(mpAction, mArg1, mArg2, mArg3);
  201.     }
  202.  
  203.     const T1 mArg1;
  204.     const T2 mArg2;
  205.     const T3 mArg3;
  206. };
  207.  
  208. template<class T1, class T2, class T3, class T4>
  209. class VDProtectedAutoScope4 : public VDProtectedAutoScope {
  210. public:
  211.     VDProtectedAutoScope4(const VDProtectedAutoScopeData4<T1,T2,T3,T4>& data) : VDProtectedAutoScope(data.mpFile, data.mLine, data.mpAction), mArg1(data.mArg1), mArg2(data.mArg2), mArg3(data.mArg3), mArg4(data.mArg4) {
  212.         g_pVDSetProtectedScopeLink(this);
  213. #ifdef __INTEL_COMPILER
  214.         VDProtectedAutoScopeICLWorkaround();
  215. #endif
  216.     }
  217.  
  218.     virtual void Write(IVDProtectedScopeOutput& out) {
  219.         out.writef(mpAction, mArg1, mArg2, mArg3, mArg4);
  220.     }
  221.  
  222.     const T1 mArg1;
  223.     const T2 mArg2;
  224.     const T3 mArg3;
  225.     const T4 mArg4;
  226. };
  227.  
  228.  
  229. #define vdprotected(action) vdobjectscope(VDProtectedAutoScope0 autoscope = VDProtectedAutoScopeData0(__FILE__, __LINE__, action))
  230. #define vdprotected1(actionf, type1, arg1) vdobjectscope(VDProtectedAutoScope1<type1> autoscope = VDProtectedAutoScopeData1<type1>(__FILE__, __LINE__, actionf, arg1))
  231.  
  232. // @&#(* preprocessor doesn't view template brackets as escaping commas, so we have a slight
  233. // problem....
  234.  
  235. #if defined(VD_COMPILER_MSVC) && (VD_COMPILER_MSVC < 1400 || defined(VD_COMPILER_MSVC_VC8_DDK))
  236. #define vdprotected2(actionf, type1, arg1, type2, arg2) if(VDProtectedAutoScope2<type1, type2> autoscope = VDProtectedAutoScopeData2<type1, type2>(__FILE__, __LINE__, actionf, arg1, arg2)) VDNEVERHERE; else
  237. #define vdprotected3(actionf, type1, arg1, type2, arg2, type3, arg3) if(VDProtectedAutoScope3<type1, type2, type3> autoscope = VDProtectedAutoScopeData3<type1, type2, type3>(__FILE__, __LINE__, actionf, arg1, arg2, arg3)) VDNEVERHERE; else
  238. #define vdprotected4(actionf, type1, arg1, type2, arg2, type3, arg3, type4, arg4) if(VDProtectedAutoScope4<type1, type2, type3, type4> autoscope = VDProtectedAutoScopeData4<type1, type2, type3, type4>(__FILE__, __LINE__, actionf, arg1, arg2, arg3, arg4)) VDNEVERHERE; else
  239. #else
  240. #define vdprotected2(actionf, type1, arg1, type2, arg2) switch(VDProtectedAutoScope2<type1, type2> autoscope = VDProtectedAutoScopeData2<type1, type2>(__FILE__, __LINE__, actionf, arg1, arg2)) case 0: default:
  241. #define vdprotected3(actionf, type1, arg1, type2, arg2, type3, arg3) switch(VDProtectedAutoScope3<type1, type2, type3> autoscope = VDProtectedAutoScopeData3<type1, type2, type3>(__FILE__, __LINE__, actionf, arg1, arg2, arg3)) case 0: default:
  242. #define vdprotected4(actionf, type1, arg1, type2, arg2, type3, arg3, type4, arg4) switch(VDProtectedAutoScope4<type1, type2, type3, type4> autoscope = VDProtectedAutoScopeData4<type1, type2, type3, type4>(__FILE__, __LINE__, actionf, arg1, arg2, arg3, arg4)) case 0: default:
  243. #endif
  244.  
  245. #endif
  246.