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.

227 lines
5.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: qresult.cxx
  7. //
  8. // Contents: Storage/picklers for results of a query
  9. //
  10. //--------------------------------------------------------------------------
  11. #include <pch.cxx>
  12. #pragma hdrstop
  13. #include <sstream.hxx>
  14. #include <sizeser.hxx>
  15. #include "qresult.hxx"
  16. // Smart pointer for aPathNew (see Add() below )
  17. class XPath
  18. {
  19. public:
  20. XPath( WCHAR** p = 0 )
  21. {
  22. _p = p;
  23. }
  24. ~XPath()
  25. {
  26. delete _p;
  27. }
  28. WCHAR** Acquire()
  29. {
  30. WCHAR** ptmp = _p;
  31. _p = 0;
  32. return( ptmp );
  33. }
  34. private:
  35. WCHAR** _p;
  36. };
  37. //+---------------------------------------------------------------------------
  38. //
  39. // Member: CQueryResults::CQueryResults
  40. //
  41. // Synopsis: simple constructor
  42. //
  43. //----------------------------------------------------------------------------
  44. CQueryResults::CQueryResults()
  45. : _size(0), _cWid(0), _aRank(0), _aPath(0), pRst(0),
  46. _fNotOwnPRst( FALSE )
  47. {
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // Member: CQueryResults::~CQueryResults
  52. //
  53. // Synopsis: destructor
  54. //
  55. //----------------------------------------------------------------------------
  56. CQueryResults::~CQueryResults()
  57. {
  58. if( !_fNotOwnPRst )
  59. delete pRst;
  60. delete _aRank;
  61. for( unsigned i = 0; i < _cWid; i++ )
  62. delete _aPath[i];
  63. delete _aPath;
  64. }
  65. //+---------------------------------------------------------------------------
  66. //
  67. // Member: CQueryResults::CQueryResults
  68. //
  69. // Synopsis: Constructor that unmarshalls stream
  70. //
  71. // Arguments: [stream] -- stream to unmarshall from
  72. //
  73. //----------------------------------------------------------------------------
  74. CQueryResults::CQueryResults ( PDeSerStream& stream )
  75. : _fNotOwnPRst( FALSE )
  76. {
  77. _cWid = stream.GetULong();
  78. _size = _cWid;
  79. _aRank = new ULONG [_size];
  80. _aPath = new WCHAR * [_size];
  81. for (unsigned i = 0; i < _cWid; i++ )
  82. {
  83. _aRank[i] = stream.GetULong();
  84. _aPath[i] = stream.GetWString();
  85. }
  86. BYTE fRst = stream.GetByte();
  87. if ( fRst )
  88. pRst = CRestriction::UnMarshall( stream );
  89. else
  90. pRst = 0;
  91. END_CONSTRUCTION ( CQueryResults );
  92. }
  93. //+---------------------------------------------------------------------------
  94. //
  95. // Member: CQueryResults::Size
  96. //
  97. // Returns: return size of marshalled CQueryResults
  98. //
  99. // History: 26-Sep-94 SitaramR Created.
  100. //
  101. //----------------------------------------------------------------------------
  102. ULONG CQueryResults::Size()
  103. {
  104. CSizeSerStream stream;
  105. stream.PutULong( _cWid );
  106. for ( unsigned i=0; i<_cWid; i++ )
  107. {
  108. stream.PutULong( _aRank[i] );
  109. stream.PutWString( _aPath[i] );
  110. }
  111. if ( pRst == 0 )
  112. stream.PutByte( FALSE );
  113. else
  114. {
  115. stream.PutByte( TRUE );
  116. pRst->Marshall( stream );
  117. }
  118. return ( stream.Size() );
  119. }
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Member: CQueryResults::Serialize
  123. //
  124. // Synopsis: Marshalls CQueryResults
  125. //
  126. // Arguments: [stream] -- marshalled into stream
  127. //
  128. // History: 26-Sep-94 SitaramR Created by modifying exisiting code
  129. //
  130. //----------------------------------------------------------------------------
  131. void CQueryResults::Serialize( PSerStream & stream ) const
  132. {
  133. stream.PutULong( _cWid );
  134. for (unsigned i = 0; i < _cWid; i++)
  135. {
  136. stream.PutULong( _aRank[i] );
  137. stream.PutWString( _aPath[i] );
  138. }
  139. if ( pRst == 0 )
  140. stream.PutByte( FALSE );
  141. else
  142. {
  143. stream.PutByte( TRUE );
  144. pRst->Marshall( stream );
  145. }
  146. }
  147. //+---------------------------------------------------------------------------
  148. //
  149. // Member: CQueryResults::Add
  150. //
  151. // Synopsis: Adds file path and rank
  152. //
  153. // Arguments: [wszPath] -- file path to be added
  154. // [uRank] -- rank to be added
  155. //
  156. // History: 26-Sep-94 SitaramR Created by modifying existing code.
  157. //
  158. //----------------------------------------------------------------------------
  159. void CQueryResults::Add ( WCHAR *wszPath, ULONG uRank )
  160. {
  161. if (_cWid == _size)
  162. {
  163. _size = (_size == 0)? 4: (2 * _size);
  164. WCHAR** aPathNew = new WCHAR *[_size];
  165. XPath xPath( aPathNew );
  166. ULONG* aRankNew = new ULONG [_size];
  167. for (unsigned i = 0; i < _cWid; i++)
  168. {
  169. aPathNew[i] = _aPath[i];
  170. aRankNew[i] = _aRank[i];
  171. }
  172. delete []_aPath;
  173. delete []_aRank;
  174. _aPath = xPath.Acquire();
  175. _aRank = aRankNew;
  176. }
  177. ULONG len = wcslen( wszPath );
  178. _aPath[_cWid] = new WCHAR[ len+1 ];
  179. memcpy( _aPath[_cWid], wszPath, (len+1) * sizeof (WCHAR) );
  180. _aRank [_cWid] = uRank;
  181. _cWid++;
  182. }