Leviathan  0.8.0.0
Leviathan game engine
DataStore.h
Go to the documentation of this file.
1 #pragma once
2 // ------------------------------------ //
3 #include "Define.h"
4 // ------------------------------------ //
7 
8 namespace Leviathan{
9 
10 #define DATAINDEX_TICKTIME 1
11 #define DATAINDEX_TICKCOUNT 2
12 #define DATAINDEX_FRAMETIME 3
13 #define DATAINDEX_FPS 4
14 #define DATAINDEX_WIDTH 5
15 #define DATAINDEX_HEIGHT 6
16 
17 #define DATAINDEX_FRAMETIME_MAX 7
18 #define DATAINDEX_FRAMETIME_MIN 8
19 #define DATAINDEX_FRAMETIME_AVERAGE 9
20 
21 #define DATAINDEX_FPS_MIN 10
22 #define DATAINDEX_FPS_MAX 11
23 #define DATAINDEX_FPS_AVERAGE 12
24 
25 #define DATAINDEX_FONT_SIZEMULTIPLIER 13
26 
27 
28 #define DATAINDEX_UND -1
29 
30 
31  struct DataListener{
33  DLLEXPORT DataListener(int index, bool onindex, const std::string &var = "");
34 
37  std::string VarName;
38 
39  //AutoUpdateableObject* Object;
40  };
41 
42  // holds all data listeners related to a object //
45  // free memory //
47  }
48 
49  std::vector<DataListener*> HandledListeners;
50  };
51 
52 
53  class DataStore{
54  public:
56  DLLEXPORT DataStore(bool main);
58 
59  DLLEXPORT void SetPersistance(unsigned int index, bool toset);
60  DLLEXPORT void SetPersistance(const std::string &name, bool toset);
61  DLLEXPORT int GetPersistance(unsigned int index) const;
62  DLLEXPORT int GetPersistance(const std::string &name) const;
63  // ------------------------------------ //
64  DLLEXPORT bool SetValue(const std::string &name, const VariableBlock &value1);
65  DLLEXPORT bool SetValue(const std::string &name, VariableBlock* value1);
66  DLLEXPORT bool SetValue(const std::string &name,
67  const std::vector<VariableBlock*> &values);
68 
69  DLLEXPORT bool SetValue(NamedVariableList &nameandvalues);
70 
71  DLLEXPORT size_t GetValueCount(const std::string &name) const;
72 
73  DLLEXPORT const VariableBlock* GetValue(const std::string &name) const;
74  DLLEXPORT bool GetValue(const std::string &name, VariableBlock &receiver) const;
75  DLLEXPORT bool GetValues(const std::string &name,
76  std::vector<const VariableBlock*> &receiver) const;
77 
78 
79  template<class T>
80  DLLEXPORT bool GetValueAndConvertTo(const std::string &name, T &receiver) const{
81  // use try block to catch all exceptions (not found and conversion fail //
82  try{
83  if(!Values.GetValue(name)->ConvertAndAssingToVariable<T>(receiver)){
84  // Couldn't convert or assign or find the value //
85  return false;
86  }
87  }
88  catch(...){
89  // variable not found / wrong type //
90  return false;
91  }
92  // correct variable has been set //
93  return true;
94  }
95 
96  //DLLEXPORT vector<VariableBlock*>* GetValues(const std::string &name) throw(...);
97 
98  DLLEXPORT void AddVar(std::shared_ptr<NamedVariableList> values);
99  DLLEXPORT void Remove(size_t index);
100  DLLEXPORT void Remove(const std::string &name);
101 
102  DLLEXPORT int GetVariableType(const std::string &name) const;
103  DLLEXPORT int GetVariableTypeOfAll(const std::string &name) const;
104  // ------------------------------------ //
105 
106  DLLEXPORT static std::string GetPersistStorageFile();
107 
108  DLLEXPORT static DataStore* Get();
109 
110  // variables //
111  public:
112  DLLEXPORT int GetTickTime() const;
113  DLLEXPORT int GetTickCount() const;
114  DLLEXPORT int GetFrameTime() const;
115  DLLEXPORT int GetFPS() const;
116  DLLEXPORT int GetHeight() const;
117  DLLEXPORT int GetWidth() const;
118  DLLEXPORT int GetGUiActive() const;
119  DLLEXPORT int GetFrameTimeMin() const;
120  DLLEXPORT int GetFrameTimeMax() const;
121  DLLEXPORT int GetFrameTimeAverage() const;
122  DLLEXPORT int GetFPSMin() const;
123  DLLEXPORT int GetFPSMax() const;
124  DLLEXPORT int GetFPSAverage() const;
125  DLLEXPORT int GetFontSizeMultiplier() const;
126 
127  DLLEXPORT void SetTickTime(int newval);
128  DLLEXPORT void SetTickCount(int newval);
129  DLLEXPORT void SetFrameTime(int newval);
130  DLLEXPORT void SetFPS(int newval);
131  DLLEXPORT void SetGUiActive(int newval);
132  DLLEXPORT void SetFrameTimeMin(int newval);
133  DLLEXPORT void SetFrameTimeMax(int newval);
134  DLLEXPORT void SetFrameTimeAverage(int newval);
135  DLLEXPORT void SetFPSMin(int newval);
136  DLLEXPORT void SetFPSMax(int newval);
137  DLLEXPORT void SetFPSAverage(int newval);
138  DLLEXPORT void SetFontSizeMultiplier(int newval);
139 
140  DLLEXPORT void SetWidth(int newval);
141  DLLEXPORT void SetHeight(int newval);
142 
143  DLLEXPORT int GetValueFromValIndex(int valindex) const;
144  public:
146  DLLEXPORT void RemoveListener(AutoUpdateableObject* object, int valueid,
147  const std::string &name = "", bool all = false);
148 
149  private:
150  // ------------------------------------ //
151  void Load();
152  void Save();
153 
154  //void _RemoveListener(int index);
155  void ValueUpdate(int index);
156  void ValueUpdate(const std::string& name);
157  // ------------------------------------ //
158  NamedVars Values;
159  // NamedVariableLists that should be saved to file on quit //
160  std::vector<bool> Persistencestates;
161 
162 
163  std::map<AutoUpdateableObject*, std::shared_ptr<DataListenHolder>> Listeners;
164 
165 
166  //vector<DataListener*> Listeners;
167 
168 
169 
170  // vars //
171  int TickTime;
172  int TickCount;
173  int FrameTime;
174  int FrameTimeMin;
175  int FrameTimeMax;
176  int FrameTimeAverage;
177 
178  int FPS;
179  int FPSMin;
180  int FPSMax;
181  int FPSAverage;
182  int Gui;
183 
184  int Width;
185  int Height;
186 
187  int FontSizeMultiplier;
188 
189  // static //
190  static DataStore* Staticaccess;
191 
192  };
193 
194 }
195 
DLLEXPORT int GetFontSizeMultiplier() const
Definition: DataStore.cpp:506
DLLEXPORT int GetHeight() const
Definition: DataStore.cpp:382
DLLEXPORT void SetFPS(int newval)
Definition: DataStore.cpp:354
hosts one or more VariableBlocks keeping only one name for all of them
Definition: NamedVars.h:27
DLLEXPORT void SetFPSAverage(int newval)
Definition: DataStore.cpp:501
DLLEXPORT int GetFPSMax() const
Definition: DataStore.cpp:468
DLLEXPORT void SetFPSMax(int newval)
Definition: DataStore.cpp:496
DLLEXPORT int GetFPS() const
Definition: DataStore.cpp:386
DLLEXPORT int GetFPSMin() const
Definition: DataStore.cpp:464
DLLEXPORT void SetFontSizeMultiplier(int newval)
Definition: DataStore.cpp:510
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
DLLEXPORT DataStore()
Definition: DataStore.cpp:12
DLLEXPORT int GetFrameTime() const
Definition: DataStore.cpp:288
DLLEXPORT const VariableBlock * GetValue(const std::string &name) const
Definition: NamedVars.cpp:974
DLLEXPORT int GetTickTime() const
Definition: DataStore.cpp:280
DLLEXPORT int GetFPSAverage() const
Definition: DataStore.cpp:472
DLLEXPORT int GetFrameTimeMin() const
Definition: DataStore.cpp:452
static DLLEXPORT std::string GetPersistStorageFile()
Definition: DataStore.cpp:514
DLLEXPORT int GetWidth() const
Definition: DataStore.cpp:378
DLLEXPORT void SetFrameTimeAverage(int newval)
Definition: DataStore.cpp:486
DLLEXPORT int GetPersistance(unsigned int index) const
Definition: DataStore.cpp:140
std::string VarName
Definition: DataStore.h:37
DLLEXPORT int GetFrameTimeMax() const
Definition: DataStore.cpp:456
DLLEXPORT void SetFPSMin(int newval)
Definition: DataStore.cpp:491
#define SAFE_DELETE_VECTOR(x)
Definition: Define.h:123
DLLEXPORT bool GetValueAndConvertTo(const std::string &name, T &receiver) const
Definition: DataStore.h:80
DLLEXPORT void SetFrameTimeMax(int newval)
Definition: DataStore.cpp:481
bool ConvertAndAssingToVariable(ConvertT &var) const
Definition: DataBlock.h:728
static DLLEXPORT DataStore * Get()
Definition: DataStore.cpp:72
DLLEXPORT void SetFrameTimeMin(int newval)
Definition: DataStore.cpp:476
DLLEXPORT ~DataStore()
Definition: DataStore.cpp:66
DLLEXPORT void SetHeight(int newval)
Definition: DataStore.cpp:339
DLLEXPORT bool SetValue(const std::string &name, const VariableBlock &value1)
Definition: DataStore.cpp:153
DLLEXPORT void SetPersistance(unsigned int index, bool toset)
Definition: DataStore.cpp:128
DLLEXPORT void RegisterListener(AutoUpdateableObject *object, DataListener *listen)
Definition: DataStore.cpp:228
DLLEXPORT int GetGUiActive() const
Definition: DataStore.cpp:374
DLLEXPORT void RemoveListener(AutoUpdateableObject *object, int valueid, const std::string &name="", bool all=false)
Definition: DataStore.cpp:248
DLLEXPORT void Remove(size_t index)
Definition: DataStore.cpp:204
DLLEXPORT void SetGUiActive(int newval)
Definition: DataStore.cpp:349
DLLEXPORT bool GetValues(const std::string &name, std::vector< const VariableBlock *> &receiver) const
Definition: DataStore.cpp:124
DLLEXPORT int GetTickCount() const
Definition: DataStore.cpp:284
#define DLLEXPORT
Definition: Include.h:115
DLLEXPORT int GetValueFromValIndex(int valindex) const
Definition: DataStore.cpp:390
DLLEXPORT void SetFrameTime(int newval)
Definition: DataStore.cpp:359
DLLEXPORT int GetVariableType(const std::string &name) const
Definition: DataStore.cpp:220
DLLEXPORT const VariableBlock * GetValue(const std::string &name) const
DLLEXPORT void SetTickTime(int newval)
Definition: DataStore.cpp:369
DLLEXPORT size_t GetValueCount(const std::string &name) const
Definition: DataStore.cpp:120
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT int GetVariableTypeOfAll(const std::string &name) const
Definition: DataStore.cpp:224
DLLEXPORT DataListener()
Definition: DataStore.cpp:523
std::vector< DataListener * > HandledListeners
Definition: DataStore.h:49
DLLEXPORT void AddVar(std::shared_ptr< NamedVariableList > values)
Definition: DataStore.cpp:194
DLLEXPORT void SetTickCount(int newval)
Definition: DataStore.cpp:364
DLLEXPORT int GetFrameTimeAverage() const
Definition: DataStore.cpp:460
DLLEXPORT void SetWidth(int newval)
Definition: DataStore.cpp:344