diff options
Diffstat (limited to '')
-rw-r--r-- | src/build.cpp | 64 |
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 | ||
5 | subExceptionDef( BuildException ); | 6 | subExceptionDef( BuildException ); |
6 | 7 | ||
7 | Build::Build() : | 8 | Build::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 | ||
14 | Build::~Build() | 16 | Build::~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 | |||
32 | void 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 | ||
18 | void Build::setStringProc( StringProc *pStrProc ) | 47 | void 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 | ||
303 | bool 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 | |||
316 | void 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 | |||