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.

170 lines
2.8 KiB

  1. #pragma once
  2. #include "Error.h"
  3. //---------------------------------------------------------------------------
  4. // VarSet Class
  5. //---------------------------------------------------------------------------
  6. class CVarSet
  7. {
  8. public:
  9. CVarSet() :
  10. m_sp(__uuidof(VarSet)),
  11. m_vntYes(GET_STRING(IDS_YES)),
  12. m_vntNo(GET_STRING(IDS_No))
  13. {
  14. }
  15. CVarSet(const CVarSet& r) :
  16. m_sp(r.m_sp),
  17. m_vntYes(r.m_vntYes),
  18. m_vntNo(r.m_vntNo)
  19. {
  20. }
  21. //
  22. IVarSetPtr GetInterface()
  23. {
  24. return m_sp;
  25. }
  26. //
  27. void Put(UINT uId, bool bValue)
  28. {
  29. m_sp->put(GET_BSTR(uId), bValue ? m_vntYes : m_vntNo);
  30. }
  31. void Put(UINT uId, long lValue)
  32. {
  33. m_sp->put(GET_BSTR(uId), _variant_t(lValue));
  34. }
  35. void Put(UINT uId, LPCTSTR pszValue)
  36. {
  37. m_sp->put(GET_BSTR(uId), _variant_t(pszValue));
  38. }
  39. void Put(UINT uId, _bstr_t strValue)
  40. {
  41. m_sp->put(GET_BSTR(uId), _variant_t(strValue));
  42. }
  43. void Put(UINT uId, const _variant_t& vntValue)
  44. {
  45. m_sp->put(GET_BSTR(uId), vntValue);
  46. }
  47. //
  48. void Put(LPCTSTR pszName, bool bValue)
  49. {
  50. m_sp->put(_bstr_t(pszName), bValue ? m_vntYes : m_vntNo);
  51. }
  52. void Put(LPCTSTR pszName, long lValue)
  53. {
  54. m_sp->put(_bstr_t(pszName), _variant_t(lValue));
  55. }
  56. void Put(LPCTSTR pszName, LPCTSTR pszValue)
  57. {
  58. m_sp->put(_bstr_t(pszName), _variant_t(pszValue));
  59. }
  60. void Put(LPCTSTR pszName, _bstr_t strValue)
  61. {
  62. m_sp->put(_bstr_t(pszName), _variant_t(strValue));
  63. }
  64. void Put(LPCTSTR pszName, const _variant_t& vntValue)
  65. {
  66. m_sp->put(_bstr_t(pszName), vntValue);
  67. }
  68. //
  69. void Put(LPCTSTR pszFormat, long lIndex, bool bValue)
  70. {
  71. _TCHAR szName[256];
  72. _stprintf(szName, pszFormat, lIndex);
  73. m_sp->put(_bstr_t(szName), bValue ? m_vntYes : m_vntNo);
  74. }
  75. void Put(LPCTSTR pszFormat, long lIndex, long lValue)
  76. {
  77. _TCHAR szName[256];
  78. _stprintf(szName, pszFormat, lIndex);
  79. m_sp->put(_bstr_t(szName), _variant_t(lValue));
  80. }
  81. void Put(LPCTSTR pszFormat, long lIndex, LPCTSTR pszValue)
  82. {
  83. _TCHAR szName[256];
  84. _stprintf(szName, pszFormat, lIndex);
  85. m_sp->put(_bstr_t(szName), _variant_t(pszValue));
  86. }
  87. //
  88. _variant_t Get(UINT uId)
  89. {
  90. return m_sp->get(GET_BSTR(uId));
  91. }
  92. //
  93. _variant_t Get(LPCTSTR pszName)
  94. {
  95. return m_sp->get(_bstr_t(pszName));
  96. }
  97. bool GetBool(LPCTSTR pszName)
  98. {
  99. bool bValue = false;
  100. _variant_t vnt = m_sp->get(_bstr_t(pszName));
  101. if (vnt == m_vntYes)
  102. {
  103. bValue = true;
  104. }
  105. return bValue;
  106. }
  107. //
  108. _variant_t Get(LPCTSTR pszFormat, long lIndex)
  109. {
  110. _TCHAR szName[256];
  111. _stprintf(szName, pszFormat, lIndex);
  112. return m_sp->get(_bstr_t(szName));
  113. }
  114. bool GetBool(LPCTSTR pszFormat, long lIndex)
  115. {
  116. _TCHAR szName[256];
  117. _stprintf(szName, pszFormat, lIndex);
  118. return GetBool(szName);
  119. }
  120. //
  121. void Dump(LPCTSTR pszFile = _T("\\VarSetDump.txt"))
  122. {
  123. m_sp->DumpToFile(pszFile);
  124. }
  125. protected:
  126. IVarSetPtr m_sp;
  127. _variant_t m_vntYes;
  128. _variant_t m_vntNo;
  129. };