1
2
3
4
5
6 #ifndef CMAJOR_SYMBOLS_EDIT_MODULE_CACHE_INCLUDED
7 #define CMAJOR_SYMBOLS_EDIT_MODULE_CACHE_INCLUDED
8 #include <cmajor/symbols/Module.hpp>
9 #include <sngcm/ast/Project.hpp>
10
11 namespace cmajor { namespace symbols {
12
13 using ReadProjectFunc = std::unique_ptr<sngcm::ast::Project> (*);
14
15 void SetReadProjectFunction(ReadProjectFunc readProjectFunc);
16
17 std::string MakeEditModuleKey(const std::string& projectFilePath, const std::string& backendStr, const std::string& configurationStr);
18
19 enum class LoadEditModuleResultKind
20 {
21 moduleUpToDate, moduleLoaded, moduleReloaded
22 };
23
24 struct LoadEditModuleResult
25 {
26 LoadEditModuleResult() : ok(true), numberOfErrors(), synchronized(false), error(), resultKind(LoadEditModuleResultKind::moduleUpToDate), startLoading(), startParsing(), endLoading()
27 {
28 }
29 bool ok;
30 int numberOfErrors;
31 bool synchronized;
32 std::string error;
33 std::string key;
34 LoadEditModuleResultKind resultKind;
35 std::chrono::steady_clock::time_point startLoading;
36 std::chrono::steady_clock::time_point startParsing;
37 std::chrono::steady_clock::time_point endParsing;
38 std::chrono::steady_clock::time_point endLoading;
39 };
40
41 class EditModuleCache
42 {
43 public:
44 static void Init();
45 static void Done();
46 EditModuleCache(const EditModuleCache&) = delete;
47 EditModuleCache(EditModuleCache&&) = delete;
48 EditModuleCache& operator=(const EditModuleCache&) = delete;
49 EditModuleCache& operator=(EditModuleCache&&) = delete;
50 static EditModuleCache& Instance() { return *instance; }
51 LoadEditModuleResult LoadEditModule(const std::string& projectFilePath, const std::string& backendStr, const std::string& configurationStr);
52 Module* GetEditModule(const std::string& projectFilePath, const std::string& backendStr, const std::string& configurationStr);
53 private:
54 static std::unique_ptr<EditModuleCache> instance;
55 EditModuleCache();
56 std::map<std::string, std::std::pair<Module*, std::string>>editModuleMap;
57 std::vector<std::std::unique_ptr<Module>>editModules;
58 };
59
60 void InitEditModuleCache();
61 void DoneEditModuleCache();
62
63 } }
64
65 #endif // CMAJOR_SYMBOLS_EDIT_MODULE_CACHE_INCLUDED