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.

247 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. xbf.hxx
  5. Abstract:
  6. Classes to handle extensible buffers
  7. Author:
  8. Philippe Choquier (phillich)
  9. --*/
  10. #if !defined( _IISXBF_HXX )
  11. #define _IISXBF_HXX
  12. #if !defined(dllexp)
  13. #define dllexp __declspec( dllexport )
  14. #endif
  15. #define INDEX_ERROR 0xffffffff
  16. //
  17. // Extensible buffer class
  18. //
  19. // Use GetBuff() & GetUsed() to retrieve buffer ptr & length
  20. //
  21. class CStoreXBF
  22. {
  23. public:
  24. dllexp CStoreXBF( UINT cG = sizeof(DWORD) ) { m_pBuff = NULL; m_cAllocBuff = 0; m_cUsedBuff = 0; m_cGrain = cG; }
  25. dllexp ~CStoreXBF() { Reset(); }
  26. dllexp VOID Reset()
  27. {
  28. if ( m_pBuff )
  29. {
  30. LocalFree( m_pBuff );
  31. m_pBuff = NULL;
  32. m_cAllocBuff = 0;
  33. m_cUsedBuff = 0;
  34. }
  35. }
  36. dllexp VOID Clear()
  37. {
  38. m_cUsedBuff = 0;
  39. }
  40. dllexp BOOL DecreaseUse( DWORD dwD )
  41. {
  42. if ( dwD <= m_cUsedBuff )
  43. {
  44. m_cUsedBuff -= dwD;
  45. return TRUE;
  46. }
  47. return FALSE;
  48. }
  49. dllexp BOOL Append( LPWSTR pszB )
  50. {
  51. return Append( (LPBYTE)pszB, wcslen(pszB)*sizeof(WCHAR) );
  52. }
  53. dllexp BOOL AppendZ( LPWSTR pszB )
  54. {
  55. return Append( (LPBYTE)pszB, (wcslen(pszB)+1)*sizeof(WCHAR) );
  56. }
  57. dllexp BOOL Append( DWORD dwB )
  58. {
  59. return Append( (LPBYTE)&dwB, (DWORD)sizeof(DWORD) );
  60. }
  61. dllexp BOOL Append( LPBYTE pB, DWORD cB )
  62. {
  63. DWORD dwNeed = m_cUsedBuff + cB;
  64. if ( Need( dwNeed ) )
  65. {
  66. memcpy( m_pBuff + m_cUsedBuff, pB, cB );
  67. m_cUsedBuff += cB;
  68. return TRUE;
  69. }
  70. return FALSE;
  71. }
  72. dllexp BOOL Need( DWORD dwNeed );
  73. //
  74. // Get ptr to buffer
  75. //
  76. dllexp LPBYTE GetBuff() { return m_pBuff; }
  77. //
  78. // Get count of bytes in buffer
  79. //
  80. dllexp DWORD GetUsed() { return m_cUsedBuff; }
  81. dllexp BOOL SetUsed( DWORD dw )
  82. { if ( dw <= m_cAllocBuff ) { m_cUsedBuff = dw; return TRUE; } else return FALSE; }
  83. dllexp BOOL Save( HANDLE hFile );
  84. dllexp BOOL Load( HANDLE hFile );
  85. private:
  86. LPBYTE m_pBuff;
  87. DWORD m_cAllocBuff;
  88. DWORD m_cGrain;
  89. DWORD m_cUsedBuff;
  90. } ;
  91. typedef CStoreXBF XBF;
  92. //
  93. // extensible array of LPVOID
  94. //
  95. class CPtrXBF : public CStoreXBF
  96. {
  97. public:
  98. dllexp CPtrXBF() : CStoreXBF( sizeof(LPVOID) ) {}
  99. dllexp DWORD GetNbPtr() { return GetUsed()/sizeof(LPVOID); }
  100. dllexp DWORD AddPtr( LPVOID pV);
  101. dllexp DWORD InsertPtr( DWORD iBefore, LPVOID pV );
  102. dllexp LPVOID GetPtr( DWORD i ) { return ((LPVOID*)GetBuff())[i]; }
  103. dllexp LPVOID GetPtrAddr( DWORD i ) { return ((LPVOID*)GetBuff())+i; }
  104. dllexp BOOL SetPtr( DWORD i, LPVOID pV ) { ((LPVOID*)GetBuff())[i] = pV; return TRUE; }
  105. dllexp BOOL DeletePtr( DWORD i );
  106. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  107. dllexp BOOL Serialize( CStoreXBF* pX );
  108. } ;
  109. //
  110. // string storage class
  111. //
  112. class CAllocString {
  113. public:
  114. dllexp CAllocString() { m_pStr = NULL; }
  115. dllexp ~CAllocString() { Reset(); }
  116. dllexp VOID Reset() { if ( m_pStr != NULL ) {LocalFree( m_pStr ); m_pStr = NULL;} }
  117. dllexp BOOL Set( LPWSTR pS );
  118. dllexp BOOL Append( LPWSTR pS );
  119. dllexp BOOL Unserialize( LPBYTE* ppb, LPDWORD pc );
  120. dllexp BOOL Serialize( CStoreXBF* pX );
  121. dllexp LPWSTR Get() { return m_pStr; }
  122. private:
  123. LPWSTR m_pStr;
  124. } ;
  125. //
  126. // binary object, contains ptr & size
  127. //
  128. class CBlob {
  129. public:
  130. dllexp CBlob() { m_pStr = NULL; m_cStr = 0; }
  131. dllexp ~CBlob() { Reset(); }
  132. dllexp VOID Reset() { if ( m_pStr != NULL ) {LocalFree( m_pStr ); m_pStr = NULL; m_cStr = 0;} }
  133. dllexp BOOL Set( LPBYTE pStr, DWORD cStr );
  134. dllexp BOOL InitSet( LPBYTE pStr, DWORD cStr );
  135. dllexp LPBYTE Get( LPDWORD pc ) { *pc = m_cStr; return m_pStr; }
  136. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC );
  137. dllexp BOOL Serialize( CStoreXBF* pX );
  138. private:
  139. LPBYTE m_pStr;
  140. DWORD m_cStr;
  141. } ;
  142. //
  143. // extensible array of strings
  144. //
  145. class CStrPtrXBF : public CPtrXBF {
  146. public:
  147. dllexp ~CStrPtrXBF();
  148. dllexp DWORD AddEntry( LPWSTR pS );
  149. dllexp DWORD InsertEntry( DWORD iBefore, LPWSTR pS );
  150. dllexp DWORD GetNbEntry() { return GetNbPtr(); }
  151. dllexp LPWSTR GetEntry( DWORD i ) { return ((CAllocString*)GetPtrAddr(i))->Get(); }
  152. dllexp BOOL SetEntry( DWORD i, LPWSTR pS ) { return ((CAllocString*)GetPtrAddr(i))->Set( pS ); }
  153. dllexp BOOL DeleteEntry( DWORD i );
  154. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  155. dllexp BOOL Serialize( CStoreXBF* pX );
  156. } ;
  157. //
  158. // extensible array of binary object
  159. // ptr & size are stored for each entry
  160. //
  161. class CBlobXBF : public CStoreXBF {
  162. public:
  163. dllexp CBlobXBF() : CStoreXBF( sizeof(CBlob) ) {}
  164. dllexp ~CBlobXBF();
  165. dllexp VOID Reset();
  166. dllexp DWORD AddEntry( LPBYTE pS, DWORD cS );
  167. dllexp DWORD InsertEntry( DWORD iBefore, LPBYTE pS, DWORD cS );
  168. dllexp DWORD GetNbEntry() { return GetUsed()/sizeof(CBlob); }
  169. dllexp CBlob* GetBlob( DWORD i )
  170. { return (CBlob*)(GetBuff()+i*sizeof(CBlob)); }
  171. dllexp BOOL GetEntry( DWORD i, LPBYTE* ppB, LPDWORD pcB )
  172. {
  173. if ( i < (GetUsed()/sizeof(CBlob)) )
  174. {
  175. *ppB = GetBlob(i)->Get( pcB );
  176. return TRUE;
  177. }
  178. return FALSE;
  179. }
  180. dllexp BOOL SetEntry( DWORD i, LPBYTE pS, DWORD cS )
  181. { return GetBlob(i)->Set( pS, cS ); }
  182. dllexp BOOL DeleteEntry( DWORD i );
  183. dllexp BOOL Unserialize( LPBYTE* ppB, LPDWORD pC, DWORD cNbEntry );
  184. dllexp BOOL Serialize( CStoreXBF* pX );
  185. } ;
  186. BOOL
  187. Unserialize(
  188. LPBYTE* ppB,
  189. LPDWORD pC,
  190. LPDWORD pU
  191. );
  192. BOOL
  193. Unserialize(
  194. LPBYTE* ppB,
  195. LPDWORD pC,
  196. LPBOOL pU
  197. );
  198. BOOL
  199. Serialize(
  200. CStoreXBF* pX,
  201. DWORD dw
  202. );
  203. BOOL
  204. Serialize(
  205. CStoreXBF* pX,
  206. BOOL f
  207. );
  208. #endif