aboutsummaryrefslogtreecommitdiff
path: root/src/cache.cpp
blob: e3b4b7efb59320e04d643e8d3cc2bd5b98d5c478 (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
65
66
67
68
69
70
/*
 * Copyright (C) 2007-2012 Xagasoft, All rights reserved.
 *
 * This file is part of the Xagasoft Build and is released under the
 * terms of the license contained in the file LICENSE.
 */
#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;
}