Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: mmcx.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef MMCX_H
  11. #define MMCX_H
  12. #include <bool.h>
  13. // This avoids "warning C4290: C++ Exception Specification ignored"
  14. // JonN 12/16/96
  15. #pragma warning(4:4290)
  16. class MMCX
  17. {
  18. public: enum Code
  19. {
  20. InvalidInstanceData,
  21. InvalidParameter,
  22. InvalidPointer,
  23. InvalidVersion,
  24. UnableToCreateStorage,
  25. UnableToCreateStream,
  26. UnableToDestroyElement,
  27. UnableToSave,
  28. UnableToLoad,
  29. UnableToLoadSomePortionOfTheTree,
  30. UnableToOpenStorage,
  31. UnableToOpenStream,
  32. UnableToWriteToStream,
  33. Unknown,
  34. };
  35. public: MMCX() throw()
  36. : m_Code(Unknown)
  37. #ifdef _DEBUG
  38. , m_File(_T(__FILE__)), m_Line(__LINE__)
  39. #endif
  40. {
  41. }
  42. public: MMCX(Code c, const TCHAR* file, int line) throw()
  43. : m_Code(c)
  44. #ifdef _DEBUG
  45. , m_File(file), m_Line(line)
  46. #endif
  47. {
  48. }
  49. public: MMCX(Code c) throw()
  50. : m_Code(c)
  51. #ifdef _DEBUG
  52. , m_File(_T(__FILE__)), m_Line(__LINE__)
  53. #endif
  54. {
  55. }
  56. public: MMCX(const MMCX& e) throw()
  57. : m_Code(e.m_Code)
  58. #ifdef _DEBUG
  59. , m_File(e.m_File), m_Line(e.m_Line)
  60. #endif
  61. {
  62. }
  63. public: ~MMCX() throw()
  64. {
  65. }
  66. public: MMCX& operator=(const MMCX& e) throw()
  67. {
  68. m_Code = e.m_Code;
  69. #ifdef _DEBUG
  70. m_File = e.m_File;
  71. m_Line = e.m_Line;
  72. #endif
  73. return *this;
  74. }
  75. public: bool operator==(Code c) const throw()
  76. {
  77. return m_Code == c;
  78. }
  79. public: bool operator==(const MMCX& m) const throw()
  80. {
  81. return operator==(m.m_Code);
  82. }
  83. public: bool operator!=(Code c) const throw()
  84. {
  85. return m_Code != c;
  86. }
  87. public: bool operator!=(const MMCX& m) const throw()
  88. {
  89. return operator!=(m.m_Code);
  90. }
  91. public: Code GetCode() const throw()
  92. // Returns the error code.
  93. {
  94. return m_Code;
  95. }
  96. public: const _TCHAR* GetDescription() const throw()
  97. {
  98. // This may be less efficeint than a lookup table, but is
  99. // only used in debug builds, and is much more maintainable (the
  100. // table doesn't have to be kept in exact sync with the code
  101. // enumerations).
  102. switch (m_Code)
  103. {
  104. case InvalidInstanceData:
  105. return _T("Invalid instance data");
  106. case InvalidParameter:
  107. return _T("Invalid parameters passed to a function");
  108. case InvalidPointer:
  109. return _T("Pointer found in invalid state");
  110. case InvalidVersion:
  111. return _T("This version of MMC is not compatible with the ")
  112. _T("file opened");
  113. case UnableToCreateStorage:
  114. return _T("Unable to create storage");
  115. case UnableToCreateStream:
  116. return _T("Unable to create stream in storage");
  117. case UnableToDestroyElement:
  118. return _T("Unable to destroy an element in a docfile");
  119. case UnableToSave:
  120. return _T("Unable to save");
  121. case UnableToLoad:
  122. return _T("Unable to load from storage");
  123. case UnableToLoadSomePortionOfTheTree:
  124. return _T("Unable to load some of the tree");
  125. case UnableToOpenStorage:
  126. return _T("Unable to open a storage");
  127. case UnableToOpenStream:
  128. return _T("Unable to open a stream");
  129. case UnableToWriteToStream:
  130. return _T("Unable to write to stream");
  131. case Unknown:
  132. return _T("Unknown");
  133. }
  134. return _T("Unknown");
  135. }
  136. private: Code m_Code;
  137. #ifdef _DEBUG
  138. private: const TCHAR* m_File;
  139. private: int m_Line;
  140. #endif
  141. }; // class MMCException
  142. template<typename MoreInfoT> class MMCXPlus : public MMCX
  143. {
  144. public: MMCXPlus() throw()
  145. {
  146. }
  147. public: MMCXPlus(const MoreInfoT& m, Code c, const TCHAR* file, int line) throw()
  148. : MMCX(c, file, line), m_MoreInfo(m)
  149. {
  150. }
  151. public: MMCXPlus(const MoreInfoT& m, Code c) throw()
  152. : MMCX(c), m_MoreInfo(m)
  153. {
  154. }
  155. public: MMCXPlus(const MMCXPlus& e) throw()
  156. : MMCX(e), m_MoreInfo(e.m_MoreInfo)
  157. {
  158. }
  159. public: ~MMCXPlus() throw()
  160. {
  161. }
  162. public: MMCXPlus& operator=(const MMCXPlus& e) throw()
  163. {
  164. MMCX::operator=(e);
  165. m_MoreInfo = e.m_MoreInfo;
  166. return *this;
  167. }
  168. public: const MoreInfoT& GetMoreInfo() const throw()
  169. {
  170. return m_MoreInfo;
  171. }
  172. private: MoreInfoT m_MoreInfo;
  173. }; // class MMCXPlus
  174. typedef MMCXPlus<HRESULT> COMX;
  175. #ifdef _DEBUG
  176. #define XCODE(x) MMCX::Code::x, _T(__FILE__), __LINE__
  177. #else
  178. #define XCODE(x) MMCX::Code::x
  179. #endif
  180. // Assert 'n throw macros
  181. #define ANT(test, exception) \
  182. if (!static_cast<bool>(test)) { ASSERT(static_cast<bool>(test)); throw exception; }
  183. #define AssertThenThrow(test, exception) ANT(test, exception)
  184. #define ANTIfNot(exception, acceptableException) \
  185. if (exception != acceptableException) \
  186. { ASSERT(exception != acceptableException); throw exception; }
  187. #define AssertThenThrowIfNot(exception, acceptableException) \
  188. ANTIfNot(exception, acceptableException)
  189. #define MMCEX(x) MMCX(XCODE(x))
  190. #define COMEX(hr, x) COMX(hr, XCODE(x))
  191. #endif // MMCX_H