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.

101 lines
2.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // propbag.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class PropertyBag.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/20/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <ias.h>
  19. #include <propbag.h>
  20. #include <varvec.h>
  21. PropertyValue::PropertyValue(const VARIANT* v)
  22. {
  23. // Is this a single-valued property?
  24. if (V_VT(v) != (VT_VARIANT | VT_ARRAY))
  25. {
  26. push_back(v);
  27. }
  28. else
  29. {
  30. // Multi-valued, so get the array ...
  31. CVariantVector<VARIANT> array(const_cast<VARIANT*>(v));
  32. resize(array.size());
  33. // ... and assign each element separately.
  34. for (size_t i = 0; i < array.size(); ++i)
  35. {
  36. operator[](i) = array[i];
  37. }
  38. }
  39. }
  40. void PropertyValue::append(const VARIANT* v)
  41. {
  42. // Copy the supplied VARIANT.
  43. _variant_t tmp(v);
  44. // Make room in the vector.
  45. resize(size() + 1);
  46. // Assign the copy.
  47. back().Attach(tmp.Detach());
  48. }
  49. void PropertyValue::get(VARIANT* v) const
  50. {
  51. VariantInit(v);
  52. if (size() == 1)
  53. {
  54. // Single-valued so just copy the front element.
  55. _com_util::CheckError(VariantCopy(v, const_cast<_variant_t*>(&front())));
  56. }
  57. else if (!empty())
  58. {
  59. // Copy all the values.
  60. PropertyValue tmp(*this);
  61. // Create an array of VARIANT's to hold the returned copies.
  62. CVariantVector<VARIANT> array(v, size());
  63. // Assign the copies.
  64. for (size_t i = 0; i < size(); ++i)
  65. {
  66. array[i] = tmp[i].Detach();
  67. }
  68. }
  69. }
  70. void PropertyBag::appendValue(const _bstr_t& name, const VARIANT* value)
  71. {
  72. iterator i = find(name);
  73. (i != end()) ? i->second.append(value) : updateValue(name, value);
  74. }
  75. bool PropertyBag::getValue(const _bstr_t& name, VARIANT* value) const
  76. {
  77. const_iterator i = find(name);
  78. return (i != end()) ? i->second.get(value), true : false;
  79. }
  80. void PropertyBag::updateValue(const _bstr_t& name, const VARIANT* value)
  81. {
  82. PropertyValue tmp(value);
  83. operator[](name).swap(tmp);
  84. }