ezEngine  Milestone 9
Stats.h
1 #pragma once
2 
3 #include <Foundation/Basics.h>
4 #include <Foundation/Communication/Event.h>
5 #include <Foundation/Containers/Map.h>
6 #include <Foundation/Strings/String.h>
7 #include <Foundation/Types/Variant.h>
8 
14 class EZ_FOUNDATION_DLL ezStats
15 {
16 public:
18 
22  static void RemoveStat(const char* szStatName);
23 
30  static void SetStat(const char* szStatName, const ezVariant& value);
31 
33  static const ezVariant& GetStat(const char* szStatName) { return s_Stats[szStatName]; }
34 
36  static const MapType& GetAllStats() { return s_Stats; }
37 
40  {
42  enum EventType
43  {
44  Add,
45  Set,
46  Remove
47  };
48 
49  EventType m_EventType;
50  const char* m_szStatName;
51  ezVariant m_NewStatValue;
52  };
53 
54  typedef ezEvent<const StatsEventData&, ezMutex> ezEventStats;
55 
57  static void AddEventHandler(ezEventStats::Handler handler) { s_StatsEvents.AddEventHandler(handler); }
58 
60  static void RemoveEventHandler(ezEventStats::Handler handler) { s_StatsEvents.RemoveEventHandler(handler); }
61 
62 private:
63  static ezMutex s_Mutex;
64  static MapType s_Stats;
65  static ezEventStats s_StatsEvents;
66 };
67 
Definition: Map.h:322
EventType
Which type of event this is.
Definition: Stats.h:42
static const MapType & GetAllStats()
Returns the entire map of stats, can be used to display them.
Definition: Stats.h:36
Definition: Event.h:136
A variable has been changed.
Definition: Stats.h:45
This class holds a simple map that maps strings (keys) to strings (values), which represent certain s...
Definition: Stats.h:14
static void RemoveEventHandler(ezEventStats::Handler handler)
Removes a previously added event handler.
Definition: Stats.h:60
A variable has been set for the first time.
Definition: Stats.h:44
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition: Mutex.h:10
The event data that is broadcast whenever a stat is changed.
Definition: Stats.h:39
static const ezVariant & GetStat(const char *szStatName)
Returns the value of the given stat. Returns an invalid ezVariant, if the stat did not exist before...
Definition: Stats.h:33
ezVariant is a class that can store different types of variables, which is useful in situations where...
Definition: Variant.h:28
static void AddEventHandler(ezEventStats::Handler handler)
Adds an event handler that is called every time a stat is changed.
Definition: Stats.h:57