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.

190 lines
4.0 KiB

  1. #pragma once
  2. enum VALUETYPE
  3. {
  4. VALUETYPE_UNKNOWN,
  5. VALUETYPE_INT,
  6. VALUETYPE_LONG,
  7. VALUETYPE_WORD,
  8. VALUETYPE_DWORD,
  9. VALUETYPE_ENUM,
  10. VALUETYPE_EDIT,
  11. VALUETYPE_KONLY
  12. };
  13. #define VALUE_SZMAX 256
  14. #define VALUE_OK 0
  15. #define VALUE_BAD_CHARS 1
  16. #define VALUE_EMPTY 2
  17. #define VALUE_OUTOFRANGE 3
  18. class CValue
  19. {
  20. public:
  21. CValue();
  22. ~CValue();
  23. VOID Init(VALUETYPE type, DWORD value);
  24. VOID InitNotPresent(VALUETYPE type);
  25. VOID Destroy();
  26. BOOL FromString(const WCHAR * const pszValue);
  27. BOOL ToString(PWSTR psz, UINT cb);
  28. VOID Copy(CValue *pvSrc);
  29. int Compare(CValue *v2);
  30. BOOL FLoadFromRegistry(HKEY hk, const WCHAR * pszValueName, HKEY hkParam = (HKEY)INVALID_HANDLE_VALUE);
  31. BOOL FSaveToRegistry(HKEY hk, const WCHAR* pszValueName);
  32. // Value Property accessors
  33. VOID SetType(VALUETYPE e)
  34. {
  35. AssertH(m_fInit);
  36. m_eType = e;
  37. }
  38. VALUETYPE GetType()
  39. {
  40. AssertH(m_fInit);
  41. return m_eType;
  42. }
  43. BOOL IsNumeric()
  44. {
  45. AssertH(m_fInit);
  46. return m_fNumeric;
  47. }
  48. VOID SetNumeric(BOOL f)
  49. {
  50. AssertH(m_fInit);
  51. m_fNumeric = f;
  52. }
  53. BOOL IsHex()
  54. {
  55. AssertH(m_fInit);
  56. return m_fHex;
  57. }
  58. VOID SetHex(BOOL f)
  59. {
  60. AssertH(m_fInit);
  61. m_fHex = f;
  62. }
  63. BOOL IsPresent()
  64. {
  65. AssertH(m_fInit);
  66. return m_fPresent;
  67. }
  68. VOID SetPresent(BOOL f)
  69. {
  70. AssertH(m_fInit);
  71. m_fPresent = f;
  72. }
  73. BOOL IsInvalidChars()
  74. {
  75. AssertH(m_fInit);
  76. return m_fInvalidChars;
  77. }
  78. VOID SetInvalidChars(BOOL f)
  79. {
  80. AssertH(m_fInit);
  81. m_fInvalidChars = f;
  82. }
  83. BOOL IsEmptyString()
  84. {
  85. AssertH(m_fInit);
  86. return m_fEmptyString;
  87. }
  88. VOID SetEmptyString(BOOL f)
  89. {
  90. AssertH(m_fInit);
  91. m_fEmptyString = f;
  92. }
  93. // Data Accessors
  94. WORD GetWord()
  95. {
  96. AssertH(m_fInit);
  97. AssertH (m_fPresent);
  98. AssertH (VALUETYPE_WORD == m_eType);
  99. return m_w;
  100. }
  101. VOID SetWord(WORD w)
  102. {
  103. AssertH(m_fInit);
  104. AssertH(VALUETYPE_WORD == m_eType);
  105. m_w = w;
  106. }
  107. LONG GetLong()
  108. {
  109. AssertH(m_fInit);
  110. AssertH (m_fPresent);
  111. AssertH(VALUETYPE_LONG == m_eType);
  112. return m_l;
  113. }
  114. VOID SetLong(LONG l)
  115. {
  116. AssertH(m_fInit);
  117. AssertH(VALUETYPE_LONG == m_eType);
  118. m_l = l;
  119. }
  120. short GetShort()
  121. {
  122. AssertH(m_fInit);
  123. AssertH (m_fPresent);
  124. AssertH(VALUETYPE_INT == m_eType);
  125. return m_n;
  126. }
  127. VOID SetShort(short n)
  128. {
  129. AssertH(m_fInit);
  130. AssertH(VALUETYPE_INT == m_eType);
  131. m_n = n;
  132. }
  133. DWORD GetDword()
  134. {
  135. AssertH(m_fInit);
  136. AssertH (m_fPresent);
  137. AssertH(VALUETYPE_DWORD == m_eType);
  138. return m_dw;
  139. }
  140. VOID SetDword(DWORD dw)
  141. {
  142. AssertH(m_fInit);
  143. AssertH(VALUETYPE_DWORD == m_eType);
  144. m_dw = dw;
  145. }
  146. int GetNumericValueAsSignedInt();
  147. DWORD GetNumericValueAsDword();
  148. VOID SetNumericValue(DWORD dw);
  149. PWSTR GetPsz()
  150. {
  151. AssertH(m_fInit);
  152. AssertH (m_fPresent);
  153. AssertH(VALUETYPE_EDIT == m_eType || VALUETYPE_ENUM == m_eType);
  154. return m_psz;
  155. }
  156. VOID SetPsz(PWSTR psz)
  157. {
  158. AssertH(m_fInit);
  159. AssertH(VALUETYPE_EDIT == m_eType || VALUETYPE_ENUM == m_eType);
  160. m_psz = psz;
  161. }
  162. private:
  163. BOOL m_fInit;
  164. VALUETYPE m_eType;
  165. BOOL m_fNumeric;
  166. BOOL m_fHex;
  167. BOOL m_fPresent;
  168. BOOL m_fInvalidChars;
  169. BOOL m_fEmptyString;
  170. union {
  171. DWORD m_dw;
  172. LONG m_l;
  173. short m_n;
  174. WORD m_w;
  175. PWSTR m_psz;
  176. };
  177. };