aboutsummaryrefslogtreecommitdiff
path: root/src/cache.cpp
blob: de505b8a08687b04eb4045c1167ab666cad591dd (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::FString &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::FString &sOutput )
{
	return hRequires.get( sOutput );
}

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