Source code of Windows XP (NT5)
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.

75 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. base.h
  5. Abstract:
  6. Universal base class for error cascading and debugging information
  7. Author:
  8. Vlad Sadovsky (vlads) 26-Jan-1997
  9. Revision History:
  10. 26-Jan-1997 VladS created
  11. --*/
  12. #ifndef _BASE_H_
  13. #define _BASE_H_
  14. /*************************************************************************
  15. NAME: BASE (base)
  16. SYNOPSIS: Universal base object, root of every class.
  17. It contains universal error status and debugging
  18. support.
  19. INTERFACE: ReportError() - report an error on the object from
  20. within the object.
  21. QueryError() - return the current error state,
  22. or 0 if no error outstanding.
  23. operator!() - return TRUE if an error is outstanding.
  24. Typically means that construction failed.
  25. CAVEATS: This sort of error reporting is safe enough in a single-
  26. threaded system, but loses robustness when multiple threads
  27. access shared objects. Use it for constructor-time error
  28. handling primarily.
  29. *************************************************************************/
  30. class BASE : public IUnknown
  31. {
  32. private:
  33. UINT m_err;
  34. protected:
  35. LONG m_cRef;
  36. BASE() { m_err = 0; m_cRef = 1;}
  37. VOID ReportError( UINT err ) { m_err = err; }
  38. public:
  39. // *** IUnknown methods ***
  40. STDMETHOD(QueryInterface)( THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  41. STDMETHOD_(ULONG,AddRef)(THIS) PURE;
  42. STDMETHOD_(ULONG,Release)( THIS) PURE;
  43. // *** BASE Methods
  44. UINT QueryError() const { return m_err; }
  45. LONG QueryRefCount() { return m_cRef;}
  46. BOOL operator!() const { return (m_err != 0); }
  47. };
  48. #endif // _BASE_H_