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.

366 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: CatState.hxx
  7. //
  8. // Contents: Catalog state object
  9. //
  10. // Classes: CCatState
  11. //
  12. // History: 09-Feb-96 KyleP Separated from Scanner.hxx
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <parser.hxx>
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Class: CString
  20. //
  21. // Purpose: A simple string class for category names
  22. //
  23. // History: 21-Aug-95 SitaramR Created.
  24. //
  25. //----------------------------------------------------------------------------
  26. class CString
  27. {
  28. public:
  29. inline CString( WCHAR const * wcsString );
  30. ~CString()
  31. {
  32. delete [] _wcsString;
  33. }
  34. // Replaces an existing string with the new one
  35. inline void Replace(WCHAR const *wcsString);
  36. WCHAR const *GetString()
  37. {
  38. return _wcsString;
  39. }
  40. private:
  41. WCHAR * _wcsString;
  42. };
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Class: CCatState
  46. //
  47. // Purpose: Holds state information needed by ci.cxx that can be changed
  48. // by CCommandParser.
  49. //
  50. // History: 06-May-92 AmyA Created.
  51. //
  52. //----------------------------------------------------------------------------
  53. enum SORTDIR
  54. {
  55. SORT_UP,
  56. SORT_DOWN,
  57. };
  58. enum ECategorizationDir
  59. {
  60. UP,
  61. DOWN
  62. };
  63. class CCatState
  64. {
  65. public:
  66. CCatState();
  67. ~CCatState();
  68. void SetDefaultProperty( WCHAR const * wcsProperty );
  69. WCHAR const * GetDefaultProperty() const { return _wcsProperty; }
  70. void SetPropertyType( PropertyType propType ) { _propType = propType; }
  71. PropertyType GetPropertyType() const { return _propType; }
  72. void SetRankMethod( ULONG ulMethod ) { _ulMethod = ulMethod; }
  73. ULONG GetRankMethod() const { return _ulMethod; }
  74. void SetDeep( BOOL isDeep ) { _isDeep = isDeep; }
  75. void AddDepthFlag(BOOL isDeep);
  76. BOOL GetCurrentDepthFlag() const
  77. {
  78. return _afIsDeep[_cCatSets-1];
  79. }
  80. BOOL GetDepthFlag(unsigned int i) const
  81. {
  82. return _afIsDeep[i];
  83. }
  84. BOOL IsDeep() const { return _isDeep; }
  85. void SetVirtual( BOOL isVirtual ) { _isVirtual = isVirtual; }
  86. BOOL IsVirtual() const { return _isVirtual; }
  87. void SetMetaQuery( CiMetaData eType ) { _eType = eType; }
  88. BOOL IsMetaQuery() { return (_eType != CiNormal); }
  89. CiMetaData MetaQueryType() { return _eType; }
  90. void SetCD( WCHAR const * wcsCD );
  91. WCHAR const * GetCD();
  92. void AddDir( XPtrST<WCHAR> & wcsScope );
  93. void ChangeCurrentScope (WCHAR const * wcsScope);
  94. CDynArray<CString> & GetScopes()
  95. {
  96. return _aCatScopes;
  97. }
  98. void SetCatalog( WCHAR const * wcsCatalog );
  99. void AddCatalog( XPtrST<WCHAR> & wcsCatalog );
  100. void ChangeCurrentCatalog(WCHAR const * wcsCatalog );
  101. void ChangeCurrentDepth(BOOL fDepth);
  102. WCHAR const * GetCatalog() const
  103. {
  104. return _wcsCatalog.GetPointer();
  105. }
  106. WCHAR const * GetCatalog(unsigned int i) const
  107. {
  108. return _aCatalogs[i]->GetString();
  109. }
  110. CDynArray<CString> & GetCatalogs()
  111. {
  112. return _aCatalogs;
  113. }
  114. void AddMachine( XPtrST<WCHAR> & wcsMachine );
  115. void ChangeCurrentMachine( WCHAR const * wcsMachine );
  116. CDynArray<CString> & GetMachines()
  117. {
  118. return _aMachines;
  119. }
  120. void SetColumn( WCHAR const * wcsColumn, unsigned int uPos );
  121. void SetNumberOfColumns( unsigned int cCol );
  122. WCHAR const * GetColumn( unsigned int uPos ) const;
  123. unsigned int NumberOfColumns() const;
  124. void SetSortProp( WCHAR const * wcsProp, SORTDIR sd, unsigned int uPos );
  125. void SetNumberOfSortProps( unsigned int cProp );
  126. void GetSortProp( unsigned int uPos, WCHAR const ** pwcsName, SORTDIR * psd ) const;
  127. unsigned int NumberOfSortProps() const;
  128. void SetLastQuery( CDbRestriction * prst )
  129. {
  130. delete _prstLast;
  131. _prstLast = prst;
  132. }
  133. CDbRestriction * GetLastQuery() { return _prstLast; }
  134. void SetLocale( WCHAR const *wcsLocale );
  135. void SetLocale( LCID lcid ) { _lcid = lcid; }
  136. LCID GetLocale() const { return _lcid; }
  137. void SetCodePage( ULONG ulCodePage ) { _ulCodePage = ulCodePage; }
  138. ULONG GetCodePage() const { return _ulCodePage; }
  139. BOOL IsSC() { return _fIsSC; }
  140. void UseSC() { _fIsSC = TRUE; }
  141. void UseNormalCatalog() { _fIsSC = FALSE; }
  142. BOOL UseCI() { return _fUseCI; }
  143. void SetUseCI(BOOL f) { _fUseCI = f; }
  144. //
  145. // Categorization
  146. //
  147. void SetCategory( WCHAR const *wcsCategory, unsigned uPos );
  148. WCHAR const *GetCategory( unsigned uPos ) const;
  149. void SetNumberOfCategories( unsigned cCat ) { _cCategories = cCat; }
  150. unsigned NumberOfCategories() const { return _cCategories; }
  151. void ClearCategories() { _aCategories.Clear(); }
  152. inline void SetCategorizationDir( ECategorizationDir eCategDir, unsigned iRow );
  153. inline void GetCategorizationDir( ECategorizationDir& eCategDir, unsigned& iRow ) const;
  154. //
  155. // Limits on # results
  156. //
  157. BOOL IsMaxResultsSpecified() const { return _cMaxResults > 0; }
  158. ULONG GetMaxResults() const { return _cMaxResults; }
  159. void SetMaxResults( ULONG cMaxResults ) { _cMaxResults = cMaxResults; }
  160. //
  161. // FirstRows
  162. //
  163. BOOL IsFirstRowsSpecified() const { return _cFirstRows > 0; }
  164. ULONG GetFirstRows() const { return _cFirstRows; }
  165. void SetFirstRows( ULONG cFirstRows ) { _cFirstRows = cFirstRows; }
  166. // Support for multiple catalogs. We will maintain several rows of
  167. // <catalog, machine, depth, scope> tuples. From the command line,
  168. // the user can cause the addition of a row by adding a catalog
  169. // or a scope or a machine. The new row will have the specified value
  170. // for the specified column, but default values for all other columns.
  171. // The user can issue subsequent Set commands to change the defaults
  172. // of the most recently added row.
  173. // The following function creates a new row with defaults
  174. SCODE AddCatSetWithDefaults();
  175. unsigned int GetCatSetCount () const
  176. {
  177. return _cCatSets;
  178. };
  179. private:
  180. // default property
  181. WCHAR * _wcsProperty;
  182. PropertyType _propType;
  183. // vector method
  184. ULONG _ulMethod;
  185. // query depth
  186. BOOL _isDeep;
  187. // virtual or real path?
  188. BOOL _isVirtual;
  189. // Metadata query?
  190. CiMetaData _eType;
  191. // use CI exclusively for query?
  192. BOOL _fUseCI;
  193. // use multiple catalog extensions?
  194. BOOL _fUseMultipleCats;
  195. // output column info
  196. WCHAR ** _pwcsColumns;
  197. unsigned int _nColumns;
  198. // sort information
  199. struct SSortInfo
  200. {
  201. WCHAR * wcsProp;
  202. SORTDIR sd;
  203. };
  204. SSortInfo * _psi;
  205. unsigned int _nSort;
  206. // CD before the program started
  207. XArray<WCHAR> _wcsCDOld;
  208. // buffer to hold the current directory
  209. XArray<WCHAR> _wcsCD;
  210. // multi-scope support
  211. CDynArray<CString> _aCatScopes;
  212. // catalog path
  213. XArray<WCHAR> _wcsCatalog;
  214. CDynArray<CString> _aCatalogs;
  215. CDynArray<CString> _aMachines;
  216. CDynArrayInPlace<BOOL> _afIsDeep;
  217. // previous restriction
  218. CDbRestriction * _prstLast;
  219. // locale for word breaking
  220. LCID _lcid;
  221. // mostly for mbstowcs and back
  222. ULONG _ulCodePage;
  223. // For summary catalog use
  224. BOOL _fIsSC;
  225. // For categorization
  226. unsigned _cCategories; // Count of categories
  227. CDynArray<CString> _aCategories; // Array of categories
  228. ECategorizationDir _eCategorizationDir; // Direction of traversing a categorized rowset
  229. unsigned _iCategorizationRow; // Index of categorized row to be expanded
  230. // Limits on # results
  231. ULONG _cMaxResults;
  232. ULONG _cFirstRows;
  233. UINT _cCatSets; // tracks the number of rows (catalog/scope/machine/depth)
  234. };
  235. //+---------------------------------------------------------------------------
  236. //
  237. // Member: CCatState::SetCategorizationDir
  238. //
  239. // Synopsis: Sets categorization direction and row #
  240. //
  241. // History: 21-Aug-95 SitaramR Created
  242. //
  243. //----------------------------------------------------------------------------
  244. inline void CCatState::SetCategorizationDir( ECategorizationDir eCategDir, unsigned iRow )
  245. {
  246. _eCategorizationDir = eCategDir;
  247. _iCategorizationRow = iRow;
  248. }
  249. //+---------------------------------------------------------------------------
  250. //
  251. // Member: CCatState::GetCategorizationDir
  252. //
  253. // Synopsis: Gets categorization direction and row #
  254. //
  255. // History: 21-Aug-95 SitaramR Created
  256. //
  257. //----------------------------------------------------------------------------
  258. inline void CCatState::GetCategorizationDir( ECategorizationDir& eCategDir, unsigned& iRow ) const
  259. {
  260. eCategDir = _eCategorizationDir;
  261. iRow = _iCategorizationRow;
  262. }
  263. //+---------------------------------------------------------------------------
  264. //
  265. // Function: CString::CString
  266. //
  267. // Purpose: Inline constructor
  268. //
  269. // History: 21-Aug-95 SitaramR Created.
  270. //
  271. //----------------------------------------------------------------------------
  272. inline CString::CString( WCHAR const *wcsString )
  273. {
  274. _wcsString = new WCHAR[ wcslen( wcsString ) + 1 ];
  275. RtlCopyMemory( _wcsString, wcsString, ( wcslen( wcsString ) + 1 ) * sizeof( WCHAR ) );
  276. }
  277. //+---------------------------------------------------------------------------
  278. //
  279. // Function: CString::Replace
  280. //
  281. // Purpose: Inline replacement of string
  282. //
  283. // History: 27-Feb-97 KrishnaN Created.
  284. //
  285. //----------------------------------------------------------------------------
  286. inline void CString::Replace(WCHAR const *wcsString)
  287. {
  288. // Keep it simple. Just delete old string and put in the new string.
  289. // Not used in production code.
  290. delete [] _wcsString;
  291. _wcsString = new WCHAR[ wcslen( wcsString ) + 1 ];
  292. RtlCopyMemory( _wcsString, wcsString, ( wcslen( wcsString ) + 1 ) * sizeof( WCHAR ) );
  293. }