summaryrefslogtreecommitdiff
path: root/project2/common/appInstance.cpp
blob: 3f8ab586d15264386ebd280c4d909b80383eb528 (plain)
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
#include "appInstance.h"
#include <boost/tuple/tuple_comparison.hpp>

AppInstance * AppInstance::_current = nullptr;

AppInstance::AppInstance()
{
	if (_current) {
		throw std::runtime_error("One AppInstance at a time please");
	}
	_current = this;
}

AppInstance::~AppInstance()
{
	BOOST_ASSERT_MSG(_current == this, "All kinds of bad, destroying a non-current AppInstance");
	_current = NULL;
}

AppInstance &
AppInstance::current()
{
	if (!_current) {
		throw std::runtime_error("No current AppInstance");
	}
	return *_current;
}

ScriptReaderPtr
AppInstance::cachedScript(const ScriptReader::ScriptKey & sk) const
{
	auto cached = scriptCache.find(sk);
	if (cached != scriptCache.end()) {
		return cached->second;
	}
	return nullptr;
}

void
AppInstance::cacheScript(const ScriptReader::ScriptKey & sk, ScriptReaderPtr s)
{
	scriptCache[sk] = s;
}

void
AppInstance::clearScriptCache()
{
	scriptCache.clear();
}