Skip to content

Commit 9a51fbe

Browse files
committed
Remove EnvironmentListener
1 parent 014933e commit 9a51fbe

4 files changed

Lines changed: 44 additions & 47 deletions

File tree

app/Environment.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#ifndef CPP_CALLBACK_SCRIPT_ENVIRONMENT_H
33
#define CPP_CALLBACK_SCRIPT_ENVIRONMENT_H
44

5-
#include "EnvironmentListener.h"
65
#include "EnvironmentProvider.h"
76

87
#include <map>
@@ -13,34 +12,38 @@ class Environment
1312
Environment() { }
1413
~Environment() { }
1514

16-
void addListener(const String &key, EnvironmentListener *listener)
15+
void addProvider(const String &key, EnvironmentProvider *provider)
1716
{
18-
this->listeners.insert(
19-
std::pair<String, EnvironmentListener *>(key, listener));
17+
this->providers.insert(
18+
std::pair<String, EnvironmentProvider *>(key, provider));
2019
}
2120

2221
Strings get(const String &key)
2322
{
23+
for (auto it : this->providers)
24+
{
25+
if (it.second->hasGetter(key))
26+
{
27+
return it.second->get(key);
28+
}
29+
}
2430
Strings stub;
25-
// TODO
2631
return stub;
2732
}
28-
//void report(const String &key, const Strings &values);
2933
void set(const String &key, const Strings &values)
3034
{
31-
// TODO
32-
33-
}
34-
void setProvider(const String &key, EnvironmentProvider *provider)
35-
{
36-
// TODO
37-
35+
for (auto it : this->providers)
36+
{
37+
if (it.second->hasSetter(key))
38+
{
39+
it.second->set(key, values);
40+
}
41+
}
3842
}
3943

4044
private:
41-
std::map<String, EnvironmentListener *> listeners;
42-
std::map<String, EnvironmentProvider *> providers;
43-
45+
typedef std::map<String, EnvironmentProvider *> Providers;
46+
Providers providers;
4447
};
4548

4649
#endif // CPP_CALLBACK_SCRIPT_ENVIRONMENT_H

app/EnvironmentListener.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

app/EnvironmentProvider.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ class EnvironmentProvider
1818
printf("EnvironmentProvider.destructor\n");
1919
}
2020

21+
virtual bool hasGetter(const String &key)
22+
{
23+
printf("EnvironmentProvider.hasGetter(%s)\n", key.c_str());
24+
return false;
25+
}
2126
virtual Strings get(const String &key)
2227
{
2328
printf("EnvironmentProvider.get(%s)\n", key.c_str());
2429
}
30+
31+
virtual bool hasSetter(const String &key)
32+
{
33+
printf("EnvironmentProvider.hasSetter(%s)\n", key.c_str());
34+
return false;
35+
}
2536
virtual void set(const String &key, const Strings &values)
2637
{
2738
printf(

cpp/module.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#ifndef CPP_CALLBACK_SCRIPT_MODULE_H
3+
#define CPP_CALLBACK_SCRIPT_MODULE_H
4+
5+
#include "EnvironmentListener.h"
6+
#include "EnvironmentProvider.h"
7+
8+
class ModuleListener : public EnvironmentListener
9+
{
10+
11+
};
12+
13+
#endif // CPP_CALLBACK_SCRIPT_MODULE_H
14+

0 commit comments

Comments
 (0)