SCAPropBag.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Js
  7. {
  8. //
  9. // Implements ISCAPropBag.
  10. //
  11. class SCAPropBag sealed :
  12. public ScriptContextHolder,
  13. public IUnknown
  14. {
  15. typedef JsUtil::BaseDictionary<InternalString, Var, RecyclerNonLeafAllocator, PowerOf2SizePolicy,
  16. DefaultComparer, JsUtil::DictionaryEntry> PropertyDictionary;
  17. private:
  18. RecyclerRootPtr<PropertyDictionary> m_properties;
  19. ULONG m_refCount;
  20. SCAPropBag(ScriptContext* scriptContext);
  21. HRESULT InternalAdd(LPCWSTR name, charcount_t len, Var value);
  22. public:
  23. ~SCAPropBag();
  24. static void CreateInstance(ScriptContext* scriptContext, SCAPropBag** ppInstance);
  25. STDMETHODIMP_(ULONG) AddRef();
  26. STDMETHODIMP_(ULONG) Release();
  27. STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
  28. HRESULT Add(LPCWSTR name, Var value);
  29. HRESULT Get(LPCWSTR name, Var* pValue);
  30. HRESULT InternalAddNoCopy(LPCWSTR name, charcount_t len, Var value);
  31. //
  32. // PropBag property enumerator for WriteObjectProperties.
  33. //
  34. class PropBagEnumerator
  35. {
  36. private:
  37. PropertyDictionary* m_properties;
  38. int m_curIndex;
  39. public:
  40. PropBagEnumerator(SCAPropBag* propBag)
  41. : m_properties(propBag->m_properties), m_curIndex(-1)
  42. {
  43. }
  44. bool MoveNext();
  45. const char16* GetNameString() const
  46. {
  47. return m_properties->GetKeyAt(m_curIndex).GetBuffer();
  48. }
  49. charcount_t GetNameLength() const
  50. {
  51. return m_properties->GetKeyAt(m_curIndex).GetLength();
  52. }
  53. Var GetValue() const
  54. {
  55. return m_properties->GetValueAt(m_curIndex);
  56. }
  57. };
  58. };
  59. }