/
sw_context.cpp
59 lines (49 loc) · 1.49 KB
/
sw_context.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
52
53
54
55
56
57
58
// Copyright (C) 2016-2019 Egor Pugin <egor.pugin@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "sw_context.h"
#include "checks_storage.h"
#include "module.h"
namespace sw
{
SwContext::SwContext(const path &local_storage_root_dir)
: SwBuilderContext(local_storage_root_dir)
{
source_dir = fs::canonical(fs::current_path());
module_storage = std::make_unique<ModuleStorage>();
}
SwContext::~SwContext()
{
// do not clear modules on exception, because it may come from there
// TODO: cleanup modules data first
if (std::uncaught_exceptions())
module_storage.release();
}
ChecksStorage &SwContext::getChecksStorage(const String &config) const
{
auto i = checksStorages.find(config);
if (i == checksStorages.end())
{
auto [i, _] = checksStorages.emplace(config, std::make_unique<ChecksStorage>());
return *i->second;
}
return *i->second;
}
ChecksStorage &SwContext::getChecksStorage(const String &config, const path &fn) const
{
auto i = checksStorages.find(config);
if (i == checksStorages.end())
{
auto [i, _] = checksStorages.emplace(config, std::make_unique<ChecksStorage>());
i->second->load(fn);
return *i->second;
}
return *i->second;
}
ModuleStorage &SwContext::getModuleStorage() const
{
return *module_storage;
}
}