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.

368 lines
9.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: pidmap.hxx
  7. //
  8. // Contents: Maps pid <--> property name.
  9. //
  10. // History: 21-Jan-93 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. class CRestriction;
  15. class CColumnSet;
  16. class CSortSet;
  17. typedef CCountedDynArray<CFullPropSpec> CPropNameArrayBase;
  18. class CPropNameArray : public CPropNameArrayBase
  19. {
  20. public:
  21. CPropNameArray(unsigned size = arraySize);
  22. //
  23. // Serialization
  24. //
  25. void Marshall( PSerStream & stm ) const;
  26. CPropNameArray( PDeSerStream & stm );
  27. # ifdef CIEXTMODE
  28. void CiExtDump(void *ciExtSelf) const;
  29. # endif
  30. };
  31. //+-------------------------------------------------------------------------
  32. //
  33. // Class: PPidConverter
  34. //
  35. // Purpose: Maps FULLPROPSPEC to 'real' PROPID
  36. //
  37. // History: 23-Dec-97 KyleP Created
  38. //
  39. //--------------------------------------------------------------------------
  40. class PPidConverter
  41. {
  42. public:
  43. virtual ~PPidConverter() {}
  44. virtual SCODE FPSToPROPID( CFullPropSpec const & fps, PROPID & pid ) = 0;
  45. };
  46. //+-------------------------------------------------------------------------
  47. //
  48. // Class: CPidMapper
  49. //
  50. // Purpose: Maps 'fake' pid <--> property name
  51. //
  52. // History: 21-Jan-93 KyleP Created
  53. //
  54. //--------------------------------------------------------------------------
  55. class CPidMapper : public CPropNameArray
  56. {
  57. public:
  58. CPidMapper( PPidConverter * pPidConverter = 0);
  59. CPidMapper( unsigned size, PPidConverter * pPidConverter = 0 );
  60. CPidMapper( PDeSerStream & stm, PPidConverter * pPidConverter = 0 );
  61. inline PROPID NameToPid( DBID const & Property );
  62. inline PROPID NameToPid( FULLPROPSPEC const & Property );
  63. PROPID NameToPid( CFullPropSpec const & Property );
  64. inline CFullPropSpec const * PidToName( PROPID pid ) const;
  65. PROPID PidToRealPid( PROPID pid );
  66. inline void Clear( );
  67. inline void SetPidConverter( PPidConverter * pPidConverter );
  68. protected:
  69. inline PROPID RealToFake( PROPID pid ) const;
  70. private:
  71. static BOOL _IsEqual( CFullPropSpec const & p1, CFullPropSpec const & p2 );
  72. CDynArrayInPlace<PROPID> _apidReal; // The 'real' propids are stored here.
  73. PPidConverter * _pPidConverter; // Can convert FULLPROPSPEC to PROPID
  74. };
  75. DECLARE_SMARTP( PidMapper );
  76. //+-------------------------------------------------------------------------
  77. //
  78. // Class: CPidMapperWithNames
  79. //
  80. // Purpose: Maps 'fake' pid <--> property name. Includes associated
  81. // 'friendly' name.
  82. //
  83. // History: 09 Dec 96 Alanw Created
  84. //
  85. //--------------------------------------------------------------------------
  86. class CPidMapperWithNames : public CPidMapper
  87. {
  88. public:
  89. CPidMapperWithNames( unsigned size = 0 );
  90. void SetFriendlyName( PROPID pid, WCHAR const * pwszName );
  91. WCHAR const * GetFriendlyName( PROPID pid ) const;
  92. inline void Clear( );
  93. private:
  94. CDynArray<WCHAR> _apwszNames;
  95. };
  96. //+---------------------------------------------------------------------------
  97. //
  98. // Class: CSimplePidRemapper
  99. //
  100. // Purpose: A simple pid remapper which does not need a catalog. It is
  101. // used during filtering to support translation of fake pids
  102. // to real pids and nothing else.
  103. //
  104. // History: 1-02-97 srikants Created
  105. //
  106. //----------------------------------------------------------------------------
  107. class CSimplePidRemapper
  108. {
  109. public:
  110. CSimplePidRemapper() : _cpidReal(0)
  111. {
  112. }
  113. PROPID FakeToReal( PROPID pid ) const
  114. {
  115. if ( pid < _cpidReal )
  116. return( _xaPidReal[pid] );
  117. else
  118. return( pidInvalid );
  119. }
  120. void Set( XArray<PROPID> & aPids )
  121. {
  122. _xaPidReal.Free();
  123. _cpidReal = aPids.Count();
  124. _xaPidReal.Set( _cpidReal, aPids.Acquire() );
  125. }
  126. unsigned GetCount() const { return _cpidReal; }
  127. const PROPID * GetPropidArray() const { return _xaPidReal.GetPointer(); }
  128. private:
  129. unsigned _cpidReal;
  130. XArray<PROPID> _xaPidReal;
  131. };
  132. //+-------------------------------------------------------------------------
  133. //
  134. // Member: CPidMapper::CPidMapper, public
  135. //
  136. // Synopsis: Create pid mapping object
  137. //
  138. // History: 13-Jan-93 KyleP Created
  139. //
  140. //--------------------------------------------------------------------------
  141. inline CPidMapper::CPidMapper( PPidConverter * pPidConverter )
  142. : _pPidConverter( pPidConverter )
  143. {
  144. }
  145. //+-------------------------------------------------------------------------
  146. //
  147. // Member: CPidMapper::CPidMapper, public
  148. //
  149. // Synopsis: Create pid mapping object
  150. //
  151. // Arguments: [cPids] - initial size of property array
  152. //
  153. // History: 13-Jan-93 KyleP Created
  154. //
  155. //--------------------------------------------------------------------------
  156. inline CPidMapper::CPidMapper( unsigned cPids, PPidConverter * pPidConverter )
  157. : CPropNameArray( cPids ),
  158. _pPidConverter( pPidConverter ),
  159. _apidReal( cPids )
  160. {
  161. }
  162. //+-------------------------------------------------------------------------
  163. //
  164. // Member: CPidMapper::CPidMapper, public
  165. //
  166. // Synopsis: Create pid mapping object
  167. //
  168. // Arguments: [stm] - stream from which a marshalled property array is read
  169. //
  170. // History: 13-Jan-93 KyleP Created
  171. //
  172. //--------------------------------------------------------------------------
  173. inline CPidMapper::CPidMapper( PDeSerStream & stm, PPidConverter * pPidConverter )
  174. : CPropNameArray( stm ),
  175. _apidReal( Count() ),
  176. _pPidConverter( pPidConverter )
  177. {
  178. for ( unsigned i = 0; i < Count(); i++ )
  179. _apidReal[i] = pidInvalid;
  180. }
  181. //+-------------------------------------------------------------------------
  182. //
  183. // Member: CPidMapper::PidToName, public
  184. //
  185. // Arguments: [pid] -- 'fake' property id
  186. //
  187. // Returns: 'real' property name for fake pid.
  188. //
  189. // History: 31-Jan-93 KyleP Created
  190. //
  191. //--------------------------------------------------------------------------
  192. inline CFullPropSpec const * CPidMapper::PidToName( PROPID pid ) const
  193. {
  194. return( Get( pid ) );
  195. }
  196. inline PROPID CPidMapper::NameToPid( FULLPROPSPEC const & Property )
  197. {
  198. return( NameToPid( (CFullPropSpec const &)Property ) );
  199. }
  200. // NOTE: This needs to change if DBID becomes something
  201. // other than a CFullPropSpec.
  202. //
  203. inline PROPID CPidMapper::NameToPid( DBID const & Property )
  204. {
  205. return( NameToPid( (CFullPropSpec const &)Property ) );
  206. }
  207. inline void CPidMapper::Clear( )
  208. {
  209. CPropNameArray::Clear();
  210. Win4Assert( Count() == 0 );
  211. }
  212. //+-------------------------------------------------------------------------
  213. //
  214. // Member: CPidMapper::SetPidConverter, public
  215. //
  216. // Synopsis: Set (or clear) pid converter
  217. //
  218. // Arguments: [pPidConverter] -- Pid converter
  219. //
  220. // History: 30-Dec-97 KyleP Created
  221. //
  222. //--------------------------------------------------------------------------
  223. inline void CPidMapper::SetPidConverter( PPidConverter * pPidConverter )
  224. {
  225. Win4Assert( 0 == _pPidConverter || 0 == pPidConverter );
  226. _pPidConverter = pPidConverter;
  227. }
  228. //+-------------------------------------------------------------------------
  229. //
  230. // Member: CPidMapper::RealToFake, public
  231. //
  232. // Arguments: [pid] -- Real pid (not index into array)
  233. //
  234. // Returns: Fake pid (index into array)
  235. //
  236. // History: 30-Dec-97 KyleP Created
  237. //
  238. //--------------------------------------------------------------------------
  239. inline PROPID CPidMapper::RealToFake( PROPID pid ) const
  240. {
  241. //
  242. // Assume this array is small, and linear search it.
  243. //
  244. for ( PROPID pidFake = 0; pidFake < Count() && pid != _apidReal[pidFake]; pidFake++)
  245. continue; // Null body
  246. if ( pidFake == Count() )
  247. pidFake = 0xFFFFFFFF;
  248. return pidFake;
  249. }
  250. //+-------------------------------------------------------------------------
  251. //
  252. // Member: CPidMapperWithNames::CPidMapperWithNames, public
  253. //
  254. // Synopsis: Create pid mapping with names object
  255. //
  256. // Arguments: [cPids] - initial size of property array
  257. //
  258. //--------------------------------------------------------------------------
  259. inline CPidMapperWithNames::CPidMapperWithNames( unsigned cPids )
  260. : CPidMapper( cPids ),
  261. _apwszNames( 0 )
  262. {
  263. }
  264. inline void CPidMapperWithNames::SetFriendlyName(
  265. PROPID pid,
  266. WCHAR const * pwszName )
  267. {
  268. delete _apwszNames.Acquire(pid);
  269. if (pwszName)
  270. {
  271. unsigned cch = wcslen(pwszName) + 1;
  272. XArray<WCHAR> pwszNewName(cch);
  273. RtlCopyMemory(pwszNewName.GetPointer(), pwszName, cch * sizeof (WCHAR));
  274. _apwszNames.Add( pwszNewName.GetPointer(), pid);
  275. pwszNewName.Acquire();
  276. }
  277. }
  278. inline WCHAR const * CPidMapperWithNames::GetFriendlyName( PROPID pid ) const
  279. {
  280. return (pid < _apwszNames.Size()) ? _apwszNames[pid] : 0;
  281. }
  282. inline void CPidMapperWithNames::Clear( )
  283. {
  284. _apwszNames.Clear();
  285. CPidMapper::Clear();
  286. }