HOG2
StatCollection.h
Go to the documentation of this file.
1 /*
2  * $Id: StatCollection.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 6/1/05.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include <vector>
13 #include <string>
14 
15 #ifndef STATCOLLECTION_H
16 #define STATCOLLECTION_H
17 
18 typedef union { double fval; long lval; } statValue;
20 // renamed from "stat" due to conflict with c file stat
21 class statistics {
22 public:
26 };
27 
35 public:
38  void AddStat(const char *category, const char *owner, double value);
39  void AddStat(const char *category, const char *owner, long value);
40  void SumStat(const char *category, const char *owner, double value);
41  void SumStat(const char *category, const char *owner, long value);
42 
43  void ClearAllStats();
44  // void clearOwnerStats(const char *owner); // not define for now; can be defined if needed
45  // void clearCategoryStats(const char *category);
46 
47  int GetNumStats() const;
48  const statistics *GetStatNum(int which) const;
49 
50  int LookupCategory(const char *category) const;
51  int LookupOwner(const char *owner) const;
52  const char *lookupCategoryID(int id) const;
53  const char *LookupOwnerID(int id) const;
54  bool LookupStat(const char *category, const char *owner, statValue &) const;
55  bool LookupStat(unsigned int index, statValue &) const;
56 
57  void AddFilter(const char *category); // this is an include filter
58  void AddIncludeFilter(const char *category); // include only added categories
59  void AddExcludeFilter(const char *category); // exclude only added categories
60  void ClearFilters();
61  void EnablePrintOutput(bool pO) { printOutput = pO; }
62 
63  int FindNextStat(const char *category, const char *owner, int startIndex=0) const;
64  int FindPrevStat(const char *category, const char *owner, int startIndex=-1) const;
65  int FindNextStat(const char *what, bool findCategory, int startIndex = 0) const;
66  int FindPrevStat(const char *what, bool findCategory, int startIndex = -1) const;
67 
68  void PrintStatsTable() const;
69 
70 private:
71  int addCategory(const char *category);
72  int addOwner(const char *owner);
73  bool passFilter(const char *category) const;
74  statValue *getLastStat(const char *category, const char *owner);
75 
76  std::vector<std::string> categories;
77  std::vector<std::string> owners;
78  std::vector<std::string> includeFilters;
79  std::vector<std::string> excludeFilters;
80  std::vector<statistics> stats;
82 };
83 
84 #endif
StatCollection::FindPrevStat
int FindPrevStat(const char *category, const char *owner, int startIndex=-1) const
Find the previous stat entry that matches the given category and owner name.
Definition: StatCollection.cpp:415
StatCollection::passFilter
bool passFilter(const char *category) const
Check to see if the category stats should be saved.
Definition: StatCollection.cpp:359
floatStored
@ floatStored
Definition: StatCollection.h:19
StatCollection::AddFilter
void AddFilter(const char *category)
Adding a filter will cause only stats of the given category to be collected.
Definition: StatCollection.cpp:192
statValue
Definition: StatCollection.h:18
StatCollection::categories
std::vector< std::string > categories
Definition: StatCollection.h:76
StatCollection::LookupStat
bool LookupStat(const char *category, const char *owner, statValue &) const
Find the last stat entered that matches the category and owner.
Definition: StatCollection.cpp:307
StatCollection::LookupOwnerID
const char * LookupOwnerID(int id) const
Given a owner ID, return the text description.
Definition: StatCollection.cpp:182
StatCollection::stats
std::vector< statistics > stats
Definition: StatCollection.h:80
statistics::owner
int owner
Definition: StatCollection.h:23
StatCollection::StatCollection
StatCollection()
Definition: StatCollection.cpp:29
StatCollection::PrintStatsTable
void PrintStatsTable() const
Definition: StatCollection.cpp:506
storedType
storedType
Definition: StatCollection.h:19
StatCollection::EnablePrintOutput
void EnablePrintOutput(bool pO)
Definition: StatCollection.h:61
statistics::sType
storedType sType
Definition: StatCollection.h:25
StatCollection::~StatCollection
~StatCollection()
Definition: StatCollection.cpp:35
StatCollection::LookupCategory
int LookupCategory(const char *category) const
Given a category, look up the ID.
Definition: StatCollection.cpp:241
StatCollection::SumStat
void SumStat(const char *category, const char *owner, double value)
Given stats for the category and owner, find an existing stat (chronologically backwards search) with...
Definition: StatCollection.cpp:109
StatCollection::ClearAllStats
void ClearAllStats()
Remove all stat entries from the collection.
Definition: StatCollection.cpp:148
StatCollection::includeFilters
std::vector< std::string > includeFilters
Definition: StatCollection.h:78
StatCollection::getLastStat
statValue * getLastStat(const char *category, const char *owner)
Find the last stat entered that matches the category and owner.
Definition: StatCollection.cpp:341
StatCollection::AddExcludeFilter
void AddExcludeFilter(const char *category)
Definition: StatCollection.cpp:207
StatCollection::ClearFilters
void ClearFilters()
Clear any filters being used for stat entry.
Definition: StatCollection.cpp:220
StatCollection::lookupCategoryID
const char * lookupCategoryID(int id) const
Given a category ID, return the text description.
Definition: StatCollection.cpp:174
StatCollection::addCategory
int addCategory(const char *category)
Add a new category to the category list.
Definition: StatCollection.cpp:258
StatCollection::GetStatNum
const statistics * GetStatNum(int which) const
Return the nth stat which has been collected.
Definition: StatCollection.cpp:166
StatCollection::excludeFilters
std::vector< std::string > excludeFilters
Definition: StatCollection.h:79
statistics::category
int category
Definition: StatCollection.h:23
StatCollection
The StatCollection class is for collecting stats across different parts of the simulation.
Definition: StatCollection.h:34
StatCollection::printOutput
bool printOutput
Definition: StatCollection.h:81
statistics
Definition: StatCollection.h:21
statistics::value
statValue value
Definition: StatCollection.h:24
StatCollection::owners
std::vector< std::string > owners
Definition: StatCollection.h:77
statValue::lval
long lval
Definition: StatCollection.h:18
StatCollection::addOwner
int addOwner(const char *owner)
Add a new owner to the owner list.
Definition: StatCollection.cpp:289
StatCollection::AddStat
void AddStat(const char *category, const char *owner, double value)
Add a new stat entry for the given category, owner and value.
Definition: StatCollection.cpp:67
StatCollection::AddIncludeFilter
void AddIncludeFilter(const char *category)
Definition: StatCollection.cpp:197
longStored
@ longStored
Definition: StatCollection.h:19
StatCollection::GetNumStats
int GetNumStats() const
The number of stats collected so far.
Definition: StatCollection.cpp:158
StatCollection::FindNextStat
int FindNextStat(const char *category, const char *owner, int startIndex=0) const
Find the next stat entry that matches the given category and owner name.
Definition: StatCollection.cpp:388
StatCollection::LookupOwner
int LookupOwner(const char *owner) const
Given an owner, look up the ID.
Definition: StatCollection.cpp:275