Team Fortress 2 Source Code as on 22/4/2020
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.

129 lines
3.8 KiB

  1. //========= Copyright (c), Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose: A utility for printing out reports on the GC in an ordered manner
  4. //
  5. //=============================================================================
  6. #ifndef GCREPORTPRINTER_H
  7. #define GCREPORTPRINTER_H
  8. #pragma once
  9. #include "gclogger.h"
  10. namespace GCSDK
  11. {
  12. //-----------------------------------------------------------------------------------------------------
  13. // CGCReportPrinter - A class that will handle formatting a report for outputting to a console or other
  14. // data sources. Just create an instance of the class, add the columns, then add the fields, and print. Below is an example:
  15. //
  16. // CGCReportPrinter rp;
  17. // rp.AddStringColumn( "Names" );
  18. // rp.AddFloatColumn( "SomeValue", 2, CGCReportPrinter::eSummary_Total );
  19. // FOR_EACH_VALUE( v )
  20. // rp.StrValue( v.Name );
  21. // rp.FloatValue( v.Float );
  22. // rp.CommitRow();
  23. // rp.SortReport( "SomeValue" );
  24. // rp.PrintReport( SPEW_CONSOLE );
  25. //
  26. //-----------------------------------------------------------------------------------------------------
  27. class CGCReportPrinter
  28. {
  29. public:
  30. CGCReportPrinter();
  31. ~CGCReportPrinter();
  32. //what type of summary to report at the end of the report for the column (not used for string columns)
  33. enum ESummaryType
  34. {
  35. eSummary_None,
  36. eSummary_Total,
  37. eSummary_Max
  38. };
  39. //how to format memory values
  40. enum EIntDisplayType
  41. {
  42. eIntDisplay_Normal,
  43. eIntDisplay_Memory_MB,
  44. };
  45. //called to handle inserting columns into the report of various data types. These must be called before any data has been added
  46. //to the report, and will fail if there is outstanding data
  47. bool AddStringColumn( const char* pszColumn );
  48. bool AddSteamIDColumn( const char* pszColumn );
  49. bool AddIntColumn( const char* pszColumn, ESummaryType eSummary, EIntDisplayType eIntDisplay = eIntDisplay_Normal );
  50. bool AddFloatColumn( const char* pszColumn, ESummaryType eSummary, uint32 unNumDecimal = 2 );
  51. //called to reset all report data
  52. void ClearData();
  53. //called to reset the entire report
  54. void Clear();
  55. //called to add the various data to the report, the order of this must match the columns that were added originally
  56. bool StrValue( const char* pszStr, const char* pszLink = NULL );
  57. bool IntValue( int64 nValue, const char* pszLink = NULL );
  58. bool FloatValue( double fValue, const char* pszLink = NULL );
  59. bool SteamIDValue( CSteamID id, const char* pszLink = NULL );
  60. //called to commit the values that have been added as a new row
  61. bool CommitRow();
  62. //sorts the report based upon the specified column name
  63. void SortReport( const char* pszColumn, bool bDescending = true );
  64. //same as the above, but sorts based upon the specified column index
  65. void SortReport( uint32 nColIndex, bool bDescending = true );
  66. //called to print out the provided report
  67. void PrintReport( CGCEmitGroup& eg, uint32 nTop = 0 );
  68. private:
  69. friend class CReportRowSorter;
  70. //the type of each column
  71. enum EColumnType
  72. {
  73. eCol_String,
  74. eCol_Int,
  75. eCol_Float,
  76. eCol_SteamID,
  77. };
  78. //our list of columns
  79. struct Column_t
  80. {
  81. CUtlString m_sName;
  82. EColumnType m_eType;
  83. ESummaryType m_eSummary;
  84. uint8 m_nNumDecimals; //for floats only
  85. EIntDisplayType m_eIntDisplay; // for ints only
  86. };
  87. CUtlVector< Column_t > m_Columns;
  88. //a variant that holds onto the column field data
  89. struct Variant_t
  90. {
  91. Variant_t();
  92. CUtlString m_sStr;
  93. CUtlString m_sLink; //optional link to put around the value
  94. int64 m_nInt;
  95. double m_fFloat;
  96. CSteamID m_SteamID;
  97. };
  98. //our data block
  99. typedef CCopyableUtlVector< Variant_t > TRow;
  100. CUtlVector< TRow* > m_Rows;
  101. //a row that isn't quite in the table, but consists of the row being built to
  102. //avoid issues with partial rows
  103. TRow m_RowBuilder;
  104. };
  105. } // namespace GCSDK
  106. #endif // GCLOGGER_H