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.

290 lines
7.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2000.
  5. //
  6. // File: colmastr.cxx
  7. //
  8. // Contents: Classes dealing with the table master column description.
  9. //
  10. // Classes: CColumnMasterDesc - A master column description
  11. // CColumnMasterArray - A simple array of master columns
  12. // CColumnMasterSet - An managed set of master columns
  13. //
  14. // Functions:
  15. //
  16. // History: 28 Feb 1994 AlanW Created
  17. //
  18. //--------------------------------------------------------------------------
  19. #include "pch.cxx"
  20. #pragma hdrstop
  21. #include <tablecol.hxx>
  22. #include <coldesc.hxx>
  23. #include "tabledbg.hxx"
  24. #include "colcompr.hxx"
  25. #include "propdata.hxx"
  26. //
  27. // Generate the implementation of the master set base class
  28. //
  29. IMPL_DYNARRAY( CColumnMasterArray, CColumnMasterDesc )
  30. //+-------------------------------------------------------------------------
  31. //
  32. // Member: CColumnMasterSet::CColumnMasterSet, public
  33. //
  34. // Synopsis: Constructor for a master column set.
  35. //
  36. // Arguments: [pcol] -- A description of the initial output column set
  37. //
  38. // Notes:
  39. //
  40. //--------------------------------------------------------------------------
  41. CColumnMasterSet::CColumnMasterSet( const CColumnSet * const pcol )
  42. : _iNextFree( 0 ),
  43. _aMasterCol( pcol->Size() ),
  44. _fHasUserProp( FALSE )
  45. {
  46. for (unsigned iCol = 0; iCol< pcol->Size(); iCol++)
  47. {
  48. PROPID pid = pcol->Get(iCol);
  49. if ( IsUserDefinedPid( pid ) )
  50. _fHasUserProp = TRUE;
  51. CColumnMasterDesc MasterCol( pid );
  52. Add( MasterCol );
  53. }
  54. }
  55. //+-------------------------------------------------------------------------
  56. //
  57. // Member: CColumnMasterSet::Find, private
  58. //
  59. // Synopsis: Find a master column description in a master column set.
  60. //
  61. // Arguments: [propid] -- The property ID of the column to be located
  62. // [riPos] -- If found, returns the position of the column
  63. // description in the dynamic array.
  64. //
  65. // Returns: CColumnMasterDesc* - a pointer to the master column
  66. // description if found, otherwise NULL
  67. //
  68. // Notes:
  69. //
  70. //--------------------------------------------------------------------------
  71. inline CColumnMasterDesc *
  72. CColumnMasterSet::Find( const PROPID propid, unsigned& riCol )
  73. {
  74. Win4Assert(_iNextFree <= Size());
  75. for (riCol = 0; riCol < _iNextFree; riCol++) {
  76. if (_aMasterCol.Get(riCol)->PropId == propid)
  77. return _aMasterCol.Get(riCol);
  78. }
  79. return NULL;
  80. }
  81. //+-------------------------------------------------------------------------
  82. //
  83. // Member: CColumnMasterSet::Find, public
  84. //
  85. // Synopsis: Find a master column description in a master column set.
  86. //
  87. // Arguments: [propid] -- The property ID of the column to be located
  88. //
  89. // Returns: CColumnMasterDesc* - a pointer to the master column
  90. // description if found, otherwise NULL
  91. //
  92. // Notes:
  93. //
  94. //--------------------------------------------------------------------------
  95. CColumnMasterDesc*
  96. CColumnMasterSet::Find( const PROPID propid )
  97. {
  98. unsigned iCol;
  99. return Find(propid, iCol);
  100. }
  101. //+-------------------------------------------------------------------------
  102. //
  103. // Member: CColumnMasterSet::Add, public
  104. //
  105. // Synopsis: Add a master column description to a master column set.
  106. //
  107. // Arguments: [xpNewCol] -- A reference to the column description to be
  108. // added.
  109. //
  110. // Returns: CColumnMasterDesc* - a pointer to the master column
  111. // description added
  112. //
  113. // Notes: If a property description with the same property ID
  114. // is already in the column set, the new column is not
  115. // added, but the previous column is used.
  116. //
  117. //--------------------------------------------------------------------------
  118. CColumnMasterDesc*
  119. CColumnMasterSet::Add( XPtr<CColumnMasterDesc> & xpNewCol )
  120. {
  121. CColumnMasterDesc* pCol = Find(xpNewCol->PropId);
  122. if ( 0 != pCol )
  123. return pCol;
  124. //
  125. // Column was not found in the existing set, add it.
  126. //
  127. unsigned iCol = _iNextFree++;
  128. if (iCol >= _aMasterCol.Size())
  129. _aMasterCol.Add(0, iCol); // force the array to grow
  130. _aMasterCol.Add(xpNewCol.Acquire(), iCol);
  131. return _aMasterCol.Get(iCol);
  132. }
  133. CColumnMasterDesc*
  134. CColumnMasterSet::Add( CColumnMasterDesc const & rColDesc )
  135. {
  136. CColumnMasterDesc* pCol = Find(rColDesc.PropId);
  137. if ( 0 != pCol )
  138. return pCol;
  139. //
  140. // Column was not found in the existing set, add it.
  141. //
  142. // PERFFIX: to avoid the compression restriction, use the method above.
  143. Win4Assert(! rColDesc.IsCompressedCol() );
  144. CColumnMasterDesc* pNewCol = new CColumnMasterDesc;
  145. XPtr<CColumnMasterDesc> xCol( pNewCol );
  146. *pNewCol = rColDesc;
  147. unsigned iCol = _iNextFree++;
  148. _aMasterCol.Add(pNewCol, iCol);
  149. xCol.Acquire();
  150. return _aMasterCol.Get(iCol);
  151. }
  152. //+-------------------------------------------------------------------------
  153. //
  154. // Member: CColumnMasterDesc::CColumnMasterDesc, public
  155. //
  156. // Synopsis: Constructor for a master column description.
  157. //
  158. // Arguments: [PropertyId] -- the PROPID for the column
  159. // [DataTyp] -- data type of column
  160. //
  161. // Notes:
  162. //
  163. //--------------------------------------------------------------------------
  164. CColumnMasterDesc::CColumnMasterDesc( PROPID PropertyId,
  165. VARTYPE DataTyp)
  166. : PropId( PropertyId ),
  167. DataType( DataTyp ),
  168. _cbData( 0 ),
  169. _fComputedProperty( FALSE ),
  170. _PredominantType( VT_EMPTY ),
  171. _fUniformType( TRUE ),
  172. _fNotVariantType (FALSE),
  173. _pCompression( NULL ),
  174. _CompressMasterID( 0 )
  175. {
  176. if ( DataType == VT_EMPTY )
  177. {
  178. DataType = PropIdToType( PropId );
  179. }
  180. }
  181. //+-------------------------------------------------------------------------
  182. //
  183. // Member: CColumnMasterDesc::CColumnMasterDesc, public
  184. //
  185. // Synopsis: Constructor for a master column description from a
  186. // sort key description.
  187. //
  188. // Arguments: [rSortKey] -- A description of a sort key
  189. //
  190. // Notes:
  191. //
  192. //--------------------------------------------------------------------------
  193. CColumnMasterDesc::CColumnMasterDesc( SSortKey& rSortKey )
  194. : PropId( rSortKey.pidColumn ),
  195. DataType( PropIdToType(rSortKey.pidColumn) ),
  196. _cbData( 0 ),
  197. _fComputedProperty( FALSE ),
  198. _PredominantType( VT_EMPTY ),
  199. _fUniformType( TRUE ),
  200. _fNotVariantType (FALSE),
  201. _pCompression( NULL ),
  202. _CompressMasterID( 0 )
  203. {
  204. }
  205. //+-------------------------------------------------------------------------
  206. //
  207. // Member: CColumnMasterDesc::~CColumnMasterDesc, public
  208. //
  209. // Synopsis: Destructor for a master column description.
  210. //
  211. // Notes:
  212. //
  213. //--------------------------------------------------------------------------
  214. CColumnMasterDesc::~CColumnMasterDesc( )
  215. {
  216. if (_pCompression && _CompressMasterID == 0)
  217. delete _pCompression;
  218. }
  219. //+-------------------------------------------------------------------------
  220. //
  221. // Member: CColumnMasterDesc::SetCompression, public
  222. //
  223. // Synopsis: Install a global compression for a master column.
  224. //
  225. // Arguments: [pCompr] -- A pointer to the compressor for the
  226. // column
  227. // [SharedID] -- If non-zero, the master column ID
  228. // for a shared compression.
  229. //
  230. // Notes:
  231. //
  232. //--------------------------------------------------------------------------
  233. VOID
  234. CColumnMasterDesc::SetCompression(
  235. CCompressedCol* pCompr,
  236. PROPID SharedID
  237. ) {
  238. if (_pCompression && _CompressMasterID == 0)
  239. delete _pCompression;
  240. _pCompression = pCompr;
  241. _CompressMasterID = SharedID;
  242. }