aboutsummaryrefslogtreecommitdiff
path: root/src/cache.cpp
blob: d6269e36de0906f9dde60c3d4edf09818f978ccf (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "cache.h"
#include <bu/file.h>
#include <bu/archive.h>
#include <bu/sio.h>
using namespace Bu;

Cache::Cache() :
	bCacheChanged( false ),
	bIsLoaded( false )
{
}

Cache::~Cache()
{
	save();
}

void Cache::bind( const Bu::String &sCacheFile )
{
	this->sCacheFile = sCacheFile;
	load();
}

void Cache::load()
{
	if( bIsLoaded )
		return;

	try
	{
		Bu::File fIn( sCacheFile, Bu::File::Read );
		Bu::Archive ar( fIn, Bu::Archive::load );

		ar >> hRequires >> hVariables;
	}
	catch(...) { }

	bIsLoaded = true;
}

void Cache::save()
{
	if( !bIsLoaded )
		return;
	if( bCacheChanged == false )
		return;

	Bu::File fIn( sCacheFile, Bu::File::WriteNew );
	Bu::Archive ar( fIn, Bu::Archive::save );

	ar << hRequires << hVariables;
}

StrList Cache::getRequires( const Bu::String &sOutput )
{
	return hRequires.get( sOutput );
}

void Cache::setRequires( const Bu::String &sOutput, StrList lReqs )
{
	hRequires.insert( sOutput, lReqs );
	bCacheChanged = true;
}