Leviathan  0.8.0.0
Leviathan game engine
Leviathan::AutoUpdateableObject Class Reference

#include <AutoUpdateable.h>

Public Member Functions

DLLEXPORT AutoUpdateableObject ()
 
virtual DLLEXPORT ~AutoUpdateableObject ()
 
virtual DLLEXPORT void StartMonitoring (const std::vector< VariableBlock * > &IndexesAndNamesToListen)
 
virtual DLLEXPORT void StopMonitoring (std::vector< std::shared_ptr< VariableBlock >> &unregisterindexandnames, bool all=false)
 
virtual DLLEXPORT bool OnUpdate (const std::shared_ptr< NamedVariableList > &updated)
 

Protected Member Functions

DLLEXPORT void _PopUdated ()
 

Protected Attributes

std::vector< std::shared_ptr< VariableBlock > > MonitoredValues
 
bool ValuesUpdated
 
std::vector< std::shared_ptr< NamedVariableList > > UpdatedValues
 

Detailed Description

Definition at line 13 of file AutoUpdateable.h.

Constructor & Destructor Documentation

◆ AutoUpdateableObject()

Leviathan::AutoUpdateableObject::AutoUpdateableObject ( )

Definition at line 8 of file AutoUpdateable.cpp.

8  {
9  ValuesUpdated = false;
10 }

◆ ~AutoUpdateableObject()

Leviathan::AutoUpdateableObject::~AutoUpdateableObject ( )
virtual

Definition at line 11 of file AutoUpdateable.cpp.

11  {
12  if(MonitoredValues.size() != 0){
14  }
15 }
std::vector< std::shared_ptr< VariableBlock > > MonitoredValues
virtual DLLEXPORT void StopMonitoring(std::vector< std::shared_ptr< VariableBlock >> &unregisterindexandnames, bool all=false)

Member Function Documentation

◆ _PopUdated()

void Leviathan::AutoUpdateableObject::_PopUdated ( )
protected

Definition at line 113 of file AutoUpdateable.cpp.

113  {
114  // just clear the vector, should automatically delete //
115  UpdatedValues.clear();
116 
117  ValuesUpdated = false;
118 }
std::vector< std::shared_ptr< NamedVariableList > > UpdatedValues

◆ OnUpdate()

DLLEXPORT bool Leviathan::AutoUpdateableObject::OnUpdate ( const std::shared_ptr< NamedVariableList > &  updated)
virtual

Definition at line 100 of file AutoUpdateable.cpp.

102 {
103  ValuesUpdated = true;
104 
105  // push to update vector //
106  UpdatedValues.push_back(updated);
107 
108  return true;
109 }
std::vector< std::shared_ptr< NamedVariableList > > UpdatedValues

◆ StartMonitoring()

void Leviathan::AutoUpdateableObject::StartMonitoring ( const std::vector< VariableBlock * > &  IndexesAndNamesToListen)
virtual

Definition at line 17 of file AutoUpdateable.cpp.

19 {
20 
21  // loop through wanted listen indexes and names //
22  for(size_t i = 0; i < IndexesAndNamesToListen.size(); i++){
23  // check for wstring //
24  if(IndexesAndNamesToListen[i]->GetBlockConst()->Type == DATABLOCK_TYPE_WSTRING){
25  // start listening on named index //
26 
27  // register new listener //
28  DataStore::Get()->RegisterListener(this, new DataListener(-1, false,
29  IndexesAndNamesToListen[i]->operator string()));
30 
31  // add to listened things //
32  MonitoredValues.push_back(shared_ptr<VariableBlock>(
33  new VariableBlock(
34  IndexesAndNamesToListen[i]->GetBlockConst()->AllocateNewFromThis())));
35 
36  continue;
37  }
38 
39  // force to int //
40  if(!IndexesAndNamesToListen[i]->IsConversionAllowedNonPtr<int>()){
41  // cannot be listened to //
42  Logger::Get()->Warning("AutoUpdateableObject: StartMonitoring: cannot listen to "
43  "index (not int/string)"+IndexesAndNamesToListen[i]->operator string());
44  continue;
45  }
46 
47  // should be good now //
48  int tmpindex = (int)*IndexesAndNamesToListen[i];
49 
50  // register new listener //
51  DataStore::Get()->RegisterListener(this, new DataListener(tmpindex, true, ""));
52 
53  // add to listened things //
54  MonitoredValues.push_back(shared_ptr<VariableBlock>(new VariableBlock(tmpindex)));
55  }
56 }
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
std::vector< std::shared_ptr< VariableBlock > > MonitoredValues
#define DATABLOCK_TYPE_WSTRING
Definition: DataBlock.h:25
DLLEXPORT void Warning(const std::string &data) override
Definition: Logger.cpp:190
static DLLEXPORT DataStore * Get()
Definition: DataStore.cpp:72
DLLEXPORT void RegisterListener(AutoUpdateableObject *object, DataListener *listen)
Definition: DataStore.cpp:246
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

◆ StopMonitoring()

void Leviathan::AutoUpdateableObject::StopMonitoring ( std::vector< std::shared_ptr< VariableBlock >> &  unregisterindexandnames,
bool  all = false 
)
virtual

Definition at line 57 of file AutoUpdateable.cpp.

59 {
60  // check are all going to be deleted anyways //
61  if(all){
62  // clear all //
63  MonitoredValues.clear();
64  // unregister all //
65  DataStore::Get()->RemoveListener(this, -1, "", true);
66 
67  return;
68 
69  }
70  // remove specific ones //
71  for(size_t i = 0; i < unregisterindexandnames.size(); i++){
72  // find matching already listened index //
73  for(size_t a = 0; a < MonitoredValues.size(); i++){
74  // check match //
75  if(*unregisterindexandnames[i] == *MonitoredValues[a]){
76  // unregister it //
77  string possiblename = "";
78  int possibleindex = -1;
79 
80  if(unregisterindexandnames[i]->GetBlockConst()->Type == DATABLOCK_TYPE_WSTRING){
81  // assign //
82  unregisterindexandnames[i]->ConvertAndAssingToVariable<string>(possiblename);
83 
84  } else {
85  // force to int //
86  unregisterindexandnames[i]->ConvertAndAssingToVariable<int>(possibleindex);
87  }
88 
89  // unregister from listening //
90  DataStore::Get()->RemoveListener(this, possibleindex, possiblename, false);
91 
92  // erase //
93  MonitoredValues.erase(MonitoredValues.begin()+a);
94  break;
95  }
96  }
97  }
98 }
std::vector< std::shared_ptr< VariableBlock > > MonitoredValues
#define DATABLOCK_TYPE_WSTRING
Definition: DataBlock.h:25
static DLLEXPORT DataStore * Get()
Definition: DataStore.cpp:72
DLLEXPORT void RemoveListener(AutoUpdateableObject *object, int valueid, const std::string &name="", bool all=false)
Definition: DataStore.cpp:266

Member Data Documentation

◆ MonitoredValues

std::vector<std::shared_ptr<VariableBlock> > Leviathan::AutoUpdateableObject::MonitoredValues
protected

Definition at line 33 of file AutoUpdateable.h.

◆ UpdatedValues

std::vector<std::shared_ptr<NamedVariableList> > Leviathan::AutoUpdateableObject::UpdatedValues
protected

Definition at line 37 of file AutoUpdateable.h.

◆ ValuesUpdated

bool Leviathan::AutoUpdateableObject::ValuesUpdated
protected

Definition at line 36 of file AutoUpdateable.h.


The documentation for this class was generated from the following files: