-
Notifications
You must be signed in to change notification settings - Fork 574
/
Copy pathDeserializer.h
38 lines (31 loc) · 1.12 KB
/
Deserializer.h
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
#pragma once
#include <ResponseParser.h>
#include <functional>
namespace weasel {
template <typename T>
void TryDeserialize(boost::archive::text_wiarchive& ia, T& t) {
try {
ia >> t;
} catch (const boost::archive::archive_exception& e) {
const std::string msg =
std::string("boost::archive::archive_exception: ") + e.what();
MessageBoxA(NULL, msg.c_str(), "IPC exception", MB_OK | MB_ICONERROR);
}
}
class Deserializer {
public:
typedef std::vector<std::wstring> KeyType;
typedef std::shared_ptr<Deserializer> Ptr;
typedef std::function<Ptr(ResponseParser* pTarget)> Factory;
Deserializer(ResponseParser* pTarget) : m_pTarget(pTarget) {}
virtual ~Deserializer() {}
virtual void Store(KeyType const& key, std::wstring const& value) {}
static void Initialize(ResponseParser* pTarget);
static void Define(std::wstring const& action, Factory factory);
static bool Require(std::wstring const& action, ResponseParser* pTarget);
protected:
ResponseParser* m_pTarget;
private:
static std::map<std::wstring, Factory> s_factories;
};
} // namespace weasel