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.

198 lines
4.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: dbqrslt.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 <dbqrslt.hxx>
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Member: CDbQueryResults::CDbQueryResults
  19. //
  20. // Synopsis: simple constructor
  21. //
  22. //----------------------------------------------------------------------------
  23. CDbQueryResults::CDbQueryResults()
  24. : _size(0), _cHits(0), _aRank(0), _aPath(0), _pDbRst(0),
  25. _fNotOwnPRst( FALSE )
  26. {
  27. }
  28. //+---------------------------------------------------------------------------
  29. //
  30. // Member: CDbQueryResults::~CDbQueryResults
  31. //
  32. // Synopsis: destructor
  33. //
  34. //----------------------------------------------------------------------------
  35. CDbQueryResults::~CDbQueryResults()
  36. {
  37. if( !_fNotOwnPRst )
  38. delete _pDbRst;
  39. delete _aRank;
  40. for( unsigned i = 0; i < _cHits; i++ )
  41. delete _aPath[i];
  42. delete _aPath;
  43. }
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Member: CDbQueryResults::CDbQueryResults
  47. //
  48. // Synopsis: Constructor that unmarshalls stream
  49. //
  50. // Arguments: [stream] -- stream to unmarshall from
  51. //
  52. //----------------------------------------------------------------------------
  53. CDbQueryResults::CDbQueryResults ( PDeSerStream& stream )
  54. : _fNotOwnPRst( FALSE )
  55. {
  56. _cHits = stream.GetULong();
  57. _size = _cHits;
  58. _aRank = new ULONG [_size];
  59. _aPath = new WCHAR * [_size];
  60. for (unsigned i = 0; i < _cHits; i++ )
  61. {
  62. _aRank[i] = stream.GetULong();
  63. _aPath[i] = stream.GetWString();
  64. }
  65. BYTE fRst = stream.GetByte();
  66. if ( fRst )
  67. _pDbRst = (CDbRestriction *) CDbCmdTreeNode::UnMarshallTree( stream );
  68. else
  69. _pDbRst = 0;
  70. }
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Member: CDbQueryResults::Size
  74. //
  75. // Returns: return size of marshalled CDbQueryResults
  76. //
  77. // History: 26-Sep-94 SitaramR Created.
  78. //
  79. //----------------------------------------------------------------------------
  80. ULONG CDbQueryResults::Size()
  81. {
  82. CSizeSerStream stream;
  83. stream.PutULong( _cHits );
  84. for ( unsigned i=0; i<_cHits; i++ )
  85. {
  86. stream.PutULong( _aRank[i] );
  87. stream.PutWString( _aPath[i] );
  88. }
  89. if ( _pDbRst == 0 )
  90. stream.PutByte( FALSE );
  91. else
  92. {
  93. stream.PutByte( TRUE );
  94. _pDbRst->Marshall( stream );
  95. }
  96. return ( stream.Size() );
  97. }
  98. //+---------------------------------------------------------------------------
  99. //
  100. // Member: CDbQueryResults::Serialize
  101. //
  102. // Synopsis: Marshalls CDbQueryResults
  103. //
  104. // Arguments: [stream] -- marshalled into stream
  105. //
  106. // History: 26-Sep-94 SitaramR Created by modifying exisiting code
  107. //
  108. //----------------------------------------------------------------------------
  109. void CDbQueryResults::Serialize( PSerStream & stream ) const
  110. {
  111. stream.PutULong( _cHits );
  112. for (unsigned i = 0; i < _cHits; i++)
  113. {
  114. stream.PutULong( _aRank[i] );
  115. stream.PutWString( _aPath[i] );
  116. }
  117. if ( _pDbRst == 0 )
  118. stream.PutByte( FALSE );
  119. else
  120. {
  121. stream.PutByte( TRUE );
  122. _pDbRst->Marshall( stream );
  123. }
  124. }
  125. //+---------------------------------------------------------------------------
  126. //
  127. // Member: CDbQueryResults::Add
  128. //
  129. // Synopsis: Adds file path and rank
  130. //
  131. // Arguments: [wszPath] -- file path to be added
  132. // [uRank] -- rank to be added
  133. //
  134. // History: 26-Sep-94 SitaramR Created by modifying existing code.
  135. //
  136. //----------------------------------------------------------------------------
  137. void CDbQueryResults::Add ( WCHAR *wszPath, ULONG uRank )
  138. {
  139. if (_cHits == _size)
  140. {
  141. _size = (_size == 0)? 4: (2 * _size);
  142. WCHAR** aPathNew = new WCHAR *[_size];
  143. XArray<WCHAR *> xPath;
  144. xPath.Set( _size, aPathNew );
  145. ULONG* aRankNew = new ULONG [_size];
  146. for (unsigned i = 0; i < _cHits; i++)
  147. {
  148. aPathNew[i] = _aPath[i];
  149. aRankNew[i] = _aRank[i];
  150. }
  151. delete []_aPath;
  152. delete []_aRank;
  153. _aPath = xPath.Acquire();
  154. _aRank = aRankNew;
  155. }
  156. ULONG len = wcslen( wszPath );
  157. _aPath[_cHits] = new WCHAR[ len+1 ];
  158. memcpy( _aPath[_cHits], wszPath, (len+1) * sizeof (WCHAR) );
  159. _aRank [_cHits] = uRank;
  160. _cHits++;
  161. }