-
Notifications
You must be signed in to change notification settings - Fork 574
/
Copy pathDeserializer.cpp
51 lines (42 loc) · 1.46 KB
/
Deserializer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "stdafx.h"
#include "Deserializer.h"
#include "ActionLoader.h"
#include "Committer.h"
#include "ContextUpdater.h"
#include "Configurator.h"
#include "Styler.h"
using namespace weasel;
std::map<std::wstring, Deserializer::Factory> Deserializer::s_factories;
void Deserializer::Initialize(ResponseParser* pTarget) {
if (s_factories.empty()) {
// register factory methods
// TODO: extend the parser's functionality in the future by defining more
// actions here
Define(L"action", ActionLoader::Create);
Define(L"commit", Committer::Create);
Define(L"ctx", ContextUpdater::Create);
Define(L"status", StatusUpdater::Create);
Define(L"config", Configurator::Create);
Define(L"style", Styler::Create);
}
// loaded by default
Require(L"action", pTarget);
}
void Deserializer::Define(std::wstring const& action, Factory factory) {
s_factories[action] = factory;
// s_factories.insert(make_pair(action, factory));
}
bool Deserializer::Require(std::wstring const& action,
ResponseParser* pTarget) {
if (!pTarget)
return false;
std::map<std::wstring, Factory>::iterator i = s_factories.find(action);
if (i == s_factories.end()) {
// unknown action type
return false;
}
Factory& factory = i->second;
pTarget->deserializers[action] = factory(pTarget);
// pTarget->deserializers.insert(make_pair(action, factory(pTarget)));
return true;
}