-
Notifications
You must be signed in to change notification settings - Fork 8
/
Serialization.h
90 lines (75 loc) · 2.52 KB
/
Serialization.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
namespace cse
{
namespace serialization
{
class PluginCosaveManager
{
public:
class IEventHandler
{
public:
virtual ~IEventHandler() = 0
{
;//
}
virtual void HandleLoad(const char* PluginName, const char* CosaveDirectory) = 0; // plugin name without extension, only called when there's an active plugin
virtual void HandleSave(const char* PluginName, const char* CosaveDirectory) = 0;
virtual void HandleShutdown(const char* PluginName, const char* CosaveDirectory) = 0; // plugin name without extension, only called when there's an active plugin
};
private:
static const bgsee::ResourceLocation kRepositoryPath;
class GlobalEventSink : public SME::MiscGunk::IEventSink
{
PluginCosaveManager* Parent;
public:
GlobalEventSink(PluginCosaveManager* Parent);
virtual void Handle(SME::MiscGunk::IEventData* Data);
};
friend class GlobalEventSink;
typedef std::vector<IEventHandler*> HandlerArrayT;
HandlerArrayT Handlers;
GlobalEventSink* EventSink;
bool Initialized;
mutable bool InvokingHandlers;
void CleanupEmptyDirectories() const;
int GetFileCount(const std::filesystem::path& DirectoryPath) const; // includes subdirectories
bool CreateCosaveDirectory(TESFile* File) const;
bool GetCosaveDirectory(TESFile* File, std::string& OutPath, bool Create = true) const;
void HandleLoad() const;
void HandleSave() const;
void HandleShutdown() const;
public:
PluginCosaveManager();
~PluginCosaveManager();
void Initialize();
void Deinitialize();
void Register(IEventHandler* Handler);
void Unregister(IEventHandler* Handler);
static PluginCosaveManager Instance;
};
#define _COSAVE serialization::PluginCosaveManager::Instance
template <typename T>
class TextSerializer
{
public:
virtual ~TextSerializer() = 0
{
;//
}
virtual bool Serialize(const T* In, std::string& Out) = 0; // returns true if successful, false otherwise
virtual bool Deserialize(std::string In, T** Out) = 0; // returns true on success
};
class TESForm2Text : public TextSerializer<TESForm>
{
static const char* kSigil;
static const char* kNullEditorID;
public:
virtual ~TESForm2Text();
virtual bool Serialize(const TESForm* In, std::string& Out);
virtual bool Deserialize(std::string In, TESForm** Out);
};
void Initialize();
void Deinitialize();
}
}