aboutsummaryrefslogtreecommitdiff
path: root/src/build.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-09-12 17:30:23 +0000
committerMike Buland <eichlan@xagasoft.com>2006-09-12 17:30:23 +0000
commite2c430b237da5c0229fd8e0832eedc3b85045ec0 (patch)
tree2f14481a9622c1d9ee913456f12ffb6cdfd53eef /src/build.cpp
parentdaa9ab77fa7ff88a77e028270ec32fa4f3e6d3bb (diff)
downloadbuild-e2c430b237da5c0229fd8e0832eedc3b85045ec0.tar.gz
build-e2c430b237da5c0229fd8e0832eedc3b85045ec0.tar.bz2
build-e2c430b237da5c0229fd8e0832eedc3b85045ec0.tar.xz
build-e2c430b237da5c0229fd8e0832eedc3b85045ec0.zip
Added cache functionality, which is really nice, things go much faster now.
Diffstat (limited to 'src/build.cpp')
-rw-r--r--src/build.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/build.cpp b/src/build.cpp
index 5c0b721..13a2aee 100644
--- a/src/build.cpp
+++ b/src/build.cpp
@@ -1,18 +1,47 @@
1#include "build.h" 1#include "build.h"
2#include "function.h" 2#include "function.h"
3#include "viewerfactory.h" 3#include "viewerfactory.h"
4#include "serializerbinary.h"
4 5
5subExceptionDef( BuildException ); 6subExceptionDef( BuildException );
6 7
7Build::Build() : 8Build::Build() :
8 pStrProc( NULL ), 9 pStrProc( NULL ),
9 pView( NULL ) 10 pView( NULL ),
11 bCacheUpdated( false )
10{ 12{
11 pView = ViewerFactory::getInstance().instantiate("plain"); 13 pView = ViewerFactory::getInstance().instantiate("plain");
12} 14}
13 15
14Build::~Build() 16Build::~Build()
15{ 17{
18 if( sCacheName.size() > 0 && bCacheUpdated )
19 {
20 try
21 {
22 SerializerBinary ar( sCacheName.c_str(), Serializer::save );
23
24 ar << cRequires;
25 }
26 catch( ExceptionBase &e )
27 {
28 }
29 }
30}
31
32void Build::setCache( const std::string &sFileName )
33{
34 sCacheName = sFileName;
35
36 try
37 {
38 SerializerBinary ar( sCacheName.c_str(), Serializer::load );
39
40 ar >> cRequires;
41 }
42 catch( ExceptionBase &e )
43 {
44 }
16} 45}
17 46
18void Build::setStringProc( StringProc *pStrProc ) 47void Build::setStringProc( StringProc *pStrProc )
@@ -271,3 +300,36 @@ StringList &Build::getRequires( std::string sName )
271 return mRequires[sName]; 300 return mRequires[sName];
272} 301}
273 302
303bool Build::getCached( const std::string &sID, int nTime, StringList &lOut )
304{
305 Cache::Entry *pEnt = cRequires.get( sID );
306 if( pEnt == NULL )
307 return false;
308 if( pEnt->tCreated < nTime )
309 return false;
310
311 lOut.insert( lOut.end(), pEnt->lData.begin(), pEnt->lData.end() );
312
313 return true;
314}
315
316void Build::updateCache( const std::string &sID, FunctionList &lFunc, StringList &lOut )
317{
318 Cache::Entry *pEnt = new Cache::Entry;
319 getView()->beginRequiresCheck( false, sID );
320 for( FunctionList::iterator f = lFunc.begin(); f != lFunc.end(); f++ )
321 {
322 StringList lTmpIn;
323 lTmpIn.push_back( sID );
324 (*f)->execute( this, lTmpIn, pEnt->lData );
325 }
326 getView()->endRequiresCheck();
327
328 lOut.insert( lOut.end(), pEnt->lData.begin(), pEnt->lData.end() );
329 cRequires.put( sID, pEnt );
330
331 pEnt->tCreated = time( NULL );
332
333 bCacheUpdated = true;
334}
335