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.

154 lines
3.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // dsproperty.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file declares the class DSProperty.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/02/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef _DSPROPERTY_H_
  19. #define _DSPROPERTY_H_
  20. #include <datastore2.h>
  21. #include <varvec.h>
  22. //////////
  23. // ATL implementation of IEnumVARIANT
  24. //////////
  25. typedef CComEnum< IEnumVARIANT,
  26. &__uuidof(IEnumVARIANT),
  27. VARIANT,
  28. _Copy<VARIANT>,
  29. CComMultiThreadModelNoCS
  30. > EnumVARIANT;
  31. //////////
  32. // Test if a property is the special 'name' property.
  33. //////////
  34. inline bool isNameProperty(PCWSTR p) throw ()
  35. {
  36. return (*p == L'N' || *p == L'n') ? !_wcsicmp(p, L"NAME") : false;
  37. }
  38. ///////////////////////////////////////////////////////////////////////////////
  39. //
  40. // CLASS
  41. //
  42. // DSProperty
  43. //
  44. // DESCRIPTION
  45. //
  46. // This class implements the IDataStoreProperty interface. It represents
  47. // a single property of an IDataStoreObject.
  48. //
  49. ///////////////////////////////////////////////////////////////////////////////
  50. template <const GUID* plibid>
  51. class DSProperty :
  52. public CComObjectRootEx< CComMultiThreadModelNoCS >,
  53. public IDispatchImpl< IDataStoreProperty,
  54. &__uuidof(IDataStoreProperty),
  55. plibid >
  56. {
  57. public:
  58. BEGIN_COM_MAP(DSProperty)
  59. COM_INTERFACE_ENTRY(IDataStoreProperty)
  60. COM_INTERFACE_ENTRY(IDispatch)
  61. END_COM_MAP()
  62. DSProperty(const _bstr_t& propName,
  63. const _variant_t& propValue,
  64. IDataStoreObject* memberOf) throw (_com_error)
  65. : name(propName),
  66. value(propValue),
  67. owner(memberOf)
  68. { }
  69. //////////
  70. // IUnknown
  71. //////////
  72. STDMETHOD_(ULONG, AddRef)()
  73. {
  74. return InternalAddRef();
  75. }
  76. STDMETHOD_(ULONG, Release)()
  77. {
  78. ULONG l = InternalRelease();
  79. if (l == 0) { delete this; }
  80. return l;
  81. }
  82. STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject)
  83. {
  84. return _InternalQueryInterface(iid, ppvObject);
  85. }
  86. //////////
  87. // IDataStoreProperty
  88. //////////
  89. STDMETHOD(get_Name)(/*[out, retval]*/ BSTR* pVal)
  90. {
  91. if (pVal == NULL) { return E_INVALIDARG; }
  92. *pVal = SysAllocString(name);
  93. return *pVal ? S_OK : E_OUTOFMEMORY;
  94. }
  95. STDMETHOD(get_Value)(/*[out, retval]*/ VARIANT* pVal)
  96. {
  97. if (pVal == NULL) { return E_INVALIDARG; }
  98. return VariantCopy(pVal, &value);
  99. }
  100. STDMETHOD(get_ValueEx)(/*[out, retval]*/ VARIANT* pVal)
  101. {
  102. if (pVal == NULL) { return E_INVALIDARG; }
  103. // Is the value an array ?
  104. if (V_VT(&value) != (VT_VARIANT | VT_ARRAY))
  105. {
  106. // No, so we have to convert it to one.
  107. try
  108. {
  109. // Make sure we can sucessfully copy the VARIANT, ...
  110. _variant_t tmp(value);
  111. // ... then allocate a SAFEARRAY with a single element.
  112. CVariantVector<VARIANT> multi(pVal, 1);
  113. // Load the single value in.
  114. multi[0] = tmp.Detach();
  115. }
  116. CATCH_AND_RETURN()
  117. return S_OK;
  118. }
  119. return VariantCopy(pVal, &value);
  120. }
  121. STDMETHOD(get_Owner)(/*[out, retval]*/ IDataStoreObject** pVal)
  122. {
  123. if (pVal == NULL) { return E_INVALIDARG; }
  124. if (*pVal = owner) { owner.p->AddRef(); }
  125. return S_OK;
  126. }
  127. protected:
  128. _bstr_t name; // Property name.
  129. _variant_t value; // Property value.
  130. CComPtr<IDataStoreObject> owner; // Object to which this property belongs.
  131. };
  132. #endif // _DSPROPERTY_H_