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.

313 lines
9.4 KiB

  1. //=============================================================================
  2. // File: intcat.cpp
  3. // Author: a-jammar
  4. // Covers: GATH_VALUE, GATH_FIELD, GATH_LINESPEC, GATH_LINE,
  5. // INTERNAL_CATEGORY
  6. //
  7. // Copyright (c) 1998-1999 Microsoft Corporation
  8. //
  9. // This file contains the support methods for the INTERNAL_CATERORY struct
  10. // and its related structs, including some constructors and destructors, and
  11. // dump routines to output the contents of the structs. The gathint.h include
  12. // file describes how these structures interrelate.
  13. //
  14. // Also contains some utility functions.
  15. //=============================================================================
  16. #include "stdafx.h"
  17. #include "gather.h"
  18. #include "gathint.h"
  19. //-----------------------------------------------------------------------------
  20. // Here are the constructor and destructor for the internal category struct,
  21. // and some of the structures used within it.
  22. //-----------------------------------------------------------------------------
  23. // INTERNAL_CATEGORY constructor and destructor.
  24. //-----------------------------------------------------------------------------
  25. INTERNAL_CATEGORY::INTERNAL_CATEGORY()
  26. {
  27. m_categoryName.m_strText = CString(" ");
  28. m_fieldName.m_strFormat = CString(" ");
  29. m_strEnumerateClass = CString("");
  30. m_strIdentifier = CString("");
  31. m_strNoInstances = CString("");
  32. m_fListView = FALSE;
  33. m_fDynamic = FALSE;
  34. m_dwID = 0;
  35. m_dwParentID = 0;
  36. m_dwChildID = 0;
  37. m_dwPrevID = 0;
  38. m_dwNextID = 0;
  39. m_dwDynamicChildID = 0;
  40. m_dwColCount = 0;
  41. m_pColSpec = NULL;
  42. m_aCols = NULL;
  43. m_pLineSpec = NULL;
  44. m_dwLineCount = 0;
  45. m_apLines = NULL;
  46. m_fIncluded = TRUE;
  47. m_fRefreshed = FALSE;
  48. m_dwLastError = GATH_ERR_NOERROR;
  49. }
  50. INTERNAL_CATEGORY::~INTERNAL_CATEGORY()
  51. {
  52. if (m_pColSpec)
  53. delete m_pColSpec;
  54. if (m_aCols)
  55. delete [] m_aCols;
  56. if (m_pLineSpec)
  57. delete m_pLineSpec;
  58. if (m_apLines)
  59. {
  60. for (DWORD dwIndex = 0; dwIndex < m_dwLineCount; dwIndex++)
  61. delete m_apLines[dwIndex];
  62. delete [] m_apLines;
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. // GATH_FIELD constructor and destructor.
  67. //-----------------------------------------------------------------------------
  68. GATH_FIELD::GATH_FIELD()
  69. {
  70. m_pArgs = NULL;
  71. m_pNext = NULL;
  72. m_usWidth = 0;
  73. m_sort = NOSORT;
  74. m_datacomplexity = BASIC;
  75. }
  76. GATH_FIELD::~GATH_FIELD()
  77. {
  78. if (m_pArgs) delete m_pArgs;
  79. if (m_pNext) delete m_pNext;
  80. }
  81. //-----------------------------------------------------------------------------
  82. // GATH_VALUE constructor and destructor.
  83. //-----------------------------------------------------------------------------
  84. GATH_VALUE::GATH_VALUE()
  85. {
  86. m_pNext = NULL;
  87. m_dwValue = 0L;
  88. }
  89. GATH_VALUE::~GATH_VALUE()
  90. {
  91. if (m_pNext) delete m_pNext;
  92. }
  93. //-----------------------------------------------------------------------------
  94. // GATH_LINESPEC constructor and destructor.
  95. //-----------------------------------------------------------------------------
  96. GATH_LINESPEC::GATH_LINESPEC()
  97. {
  98. m_pFields = NULL;
  99. m_pEnumeratedGroup = NULL;
  100. m_pConstraintFields = NULL;
  101. m_pNext = NULL;
  102. m_datacomplexity = BASIC;
  103. }
  104. GATH_LINESPEC::~GATH_LINESPEC()
  105. {
  106. if (m_pFields)
  107. delete m_pFields;
  108. if (m_pEnumeratedGroup)
  109. delete m_pEnumeratedGroup;
  110. if (m_pConstraintFields)
  111. delete m_pConstraintFields;
  112. if (m_pNext)
  113. delete m_pNext;
  114. }
  115. //-----------------------------------------------------------------------------
  116. // GATH_LINE constructor and destructor.
  117. //-----------------------------------------------------------------------------
  118. GATH_LINE::GATH_LINE()
  119. {
  120. m_datacomplexity = BASIC;
  121. m_aValue = NULL;
  122. }
  123. GATH_LINE::~GATH_LINE()
  124. {
  125. if (m_aValue)
  126. delete [] m_aValue;
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Dump a category and all its children. Indent by the current iIndent level.
  130. //-----------------------------------------------------------------------------
  131. #if _DEBUG
  132. void INTERNAL_CATEGORY::DumpCategoryRecursive(int iIndent, CDataGatherer * pGatherer)
  133. {
  134. TCHAR szIndent[100];
  135. INTERNAL_CATEGORY * pNextCat;
  136. int i;
  137. for (i = 0; i < iIndent; i++)
  138. szIndent[i] = _T(' ');
  139. szIndent[iIndent] = 0;
  140. // Dump the contents of this category.
  141. TRACE1("%sCATEGORY(", szIndent);
  142. TRACE1("m_categoryName = %s", this->m_categoryName.m_strText);
  143. TRACE0(")-----------------------------\n");
  144. TRACE2("%sm_fieldName = %s\n", szIndent, DumpField(&this->m_fieldName));
  145. TRACE2("%sm_strIdentifier = %s\n", szIndent, this->m_strIdentifier);
  146. TRACE2("%sm_strEnumerateClass = %s\n", szIndent, this->m_strEnumerateClass);
  147. TRACE2("%sm_strNoInstances = %s\n", szIndent, this->m_strNoInstances);
  148. TRACE2("%sm_fListView = %s\n", szIndent, (this->m_fListView ? "TRUE" : "FALSE"));
  149. TRACE2("%sm_fDynamic = %s\n", szIndent, (this->m_fDynamic ? "TRUE" : "FALSE"));
  150. TRACE2("%sm_dwID = %ld\n", szIndent, this->m_dwID);
  151. TRACE2("%sm_dwParentID = %ld\n", szIndent, this->m_dwParentID);
  152. TRACE2("%sm_dwChildID = %ld\n", szIndent, this->m_dwChildID);
  153. TRACE2("%sm_dwDynamicChildID = %ld\n", szIndent, this->m_dwDynamicChildID);
  154. TRACE2("%sm_dwNextID = %ld\n", szIndent, this->m_dwNextID);
  155. TRACE2("%sm_dwPrevID = %ld\n", szIndent, this->m_dwPrevID);
  156. TRACE1("%sm_pColSpec = ", szIndent);
  157. for (GATH_FIELD * pField = this->m_pColSpec; pField; pField = pField->m_pNext)
  158. TRACE1("%s ", DumpField(pField));
  159. TRACE0("\n");
  160. TRACE2("%sm_dwColCount = %ld\n", szIndent, this->m_dwColCount);
  161. TRACE1("%sm_aCols = ", szIndent);
  162. for (i = 0; i < (int)this->m_dwColCount; i++)
  163. TRACE1("(%s) ", this->m_aCols[i].m_strText);
  164. TRACE0("\n");
  165. TRACE1("%sm_pLineSpec =\n", szIndent);
  166. for (GATH_LINESPEC * pLine = this->m_pLineSpec; pLine; pLine = pLine->m_pNext)
  167. TRACE2("%s %s\n", szIndent, DumpLineSpec(pLine, szIndent));
  168. TRACE2("%sm_dwLineCount = %ld\n", szIndent, this->m_dwLineCount);
  169. TRACE1("%sm_apLines = \n", szIndent);
  170. for (i = 0; i < (int)this->m_dwLineCount; i++)
  171. TRACE2("%s %s\n", szIndent, DumpLine(this->m_apLines[i], this->m_dwColCount));
  172. // Dump the children of this category.
  173. if (this->m_dwChildID)
  174. {
  175. pNextCat = pGatherer->GetInternalRep(this->m_dwChildID);
  176. if (pNextCat)
  177. pNextCat->DumpCategoryRecursive(iIndent + 2, pGatherer);
  178. }
  179. // Dump the siblings of this category.
  180. if (this->m_dwNextID)
  181. {
  182. pNextCat = pGatherer->GetInternalRep(this->m_dwNextID);
  183. if (pNextCat)
  184. pNextCat->DumpCategoryRecursive(iIndent, pGatherer);
  185. }
  186. }
  187. //-----------------------------------------------------------------------------
  188. // Return a string containing the text dump of a field variable.
  189. //-----------------------------------------------------------------------------
  190. CString INTERNAL_CATEGORY::DumpField(GATH_FIELD * pField)
  191. {
  192. CString strDump;
  193. strDump.Format(_T("(%s, %s, %d"), pField->m_strSource, pField->m_strFormat, pField->m_usWidth);
  194. for (GATH_VALUE * pArg = pField->m_pArgs; pArg; pArg = pArg->m_pNext)
  195. strDump += CString(", ") + pArg->m_strText;
  196. strDump += CString(")");
  197. return strDump;
  198. }
  199. //-----------------------------------------------------------------------------
  200. // Return a string containing the text dump of a line specifier variable.
  201. //-----------------------------------------------------------------------------
  202. CString INTERNAL_CATEGORY::DumpLineSpec(GATH_LINESPEC * pLineSpec, CString strIndent)
  203. {
  204. CString strDump;
  205. if (pLineSpec->m_strEnumerateClass.IsEmpty() || pLineSpec->m_strEnumerateClass.CompareNoCase(CString(STATIC_SOURCE)) == 0)
  206. {
  207. strDump = CString("LineSpec = ");
  208. for (GATH_FIELD * pField = pLineSpec->m_pFields; pField; pField = pField->m_pNext)
  209. strDump += DumpField(pField) + CString(" ");
  210. }
  211. else
  212. {
  213. strDump.Format(_T("EnumLines(%s) = "), pLineSpec->m_strEnumerateClass);
  214. GATH_LINESPEC * pEnumLine = pLineSpec->m_pEnumeratedGroup;
  215. if /* while TBD */ (pEnumLine)
  216. {
  217. strDump += CString("\n ") + strIndent + DumpLineSpec(pEnumLine, strIndent);
  218. pEnumLine = pEnumLine->m_pNext;
  219. }
  220. }
  221. return strDump;
  222. }
  223. //-----------------------------------------------------------------------------
  224. // Return a string containing the text dump of a line variable.
  225. //-----------------------------------------------------------------------------
  226. CString INTERNAL_CATEGORY::DumpLine(GATH_LINE * pLine, DWORD nColumns)
  227. {
  228. CString strDump("Line = ");
  229. for (DWORD dwIndex = 0; dwIndex < nColumns; dwIndex++)
  230. strDump += pLine->m_aValue[dwIndex].m_strText + CString(" ");
  231. return strDump;
  232. }
  233. #endif
  234. //-----------------------------------------------------------------------------
  235. // This utility function is used to get a token from the front of a string.
  236. // It searches through strString for cDelimiter, returning the token found
  237. // in strToken. strString is modified to remove the token returned, and
  238. // the delimiter character. TBD: inefficient.
  239. //-----------------------------------------------------------------------------
  240. void GetToken(CString & strToken, CString & strString, TCHAR cDelimiter)
  241. {
  242. int iDelimiter = strString.Find(cDelimiter);
  243. if (iDelimiter == -1)
  244. strToken = strString;
  245. else
  246. strToken = strString.Left(iDelimiter);
  247. // Remove the token we found from strString.
  248. if (!strToken.IsEmpty())
  249. {
  250. if (strString.GetLength() >= strToken.GetLength())
  251. strString = strString.Right(strString.GetLength() - strToken.GetLength());
  252. else
  253. strString.Empty();
  254. }
  255. // Remove any leading delimiter characters from strString.
  256. while (!strString.IsEmpty() && strString[0] == cDelimiter)
  257. strString = strString.Right(strString.GetLength() - 1);
  258. }