From 501bac50016628b787906392ce7af8262e561e52 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 29 Dec 2009 01:11:27 +0000 Subject: Ok, cache stuff is in, and that's good, now we have to use it. --- src/cache.cpp | 39 +++++++++++++++++++++++++++ src/cache.h | 33 +++++++++++++++++++++++ src/variable.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/variable.h | 6 +++++ 4 files changed, 159 insertions(+) create mode 100644 src/cache.cpp create mode 100644 src/cache.h diff --git a/src/cache.cpp b/src/cache.cpp new file mode 100644 index 0000000..1646d0a --- /dev/null +++ b/src/cache.cpp @@ -0,0 +1,39 @@ +#include "cache.h" +#include +#include + +Cache::Cache() : + bIsLoaded( false ) +{ +} + +Cache::~Cache() +{ +} + +void Cache::bind( const Bu::FString &sCacheFile ) +{ + this->sCacheFile = sCacheFile; + load(); +} + +void Cache::load() +{ + if( bIsLoaded ) + return; + Bu::File fIn( sCacheFile, Bu::File::Read ); + Bu::Archive ar( fIn, Bu::Archive::load ); + + ar >> hRequires >> hVariables; + + bIsLoaded = true; +} + +void Cache::save() +{ + Bu::File fIn( sCacheFile, Bu::File::WriteNew ); + Bu::Archive ar( fIn, Bu::Archive::save ); + + ar << hRequires << hVariables; +} + diff --git a/src/cache.h b/src/cache.h new file mode 100644 index 0000000..b255e94 --- /dev/null +++ b/src/cache.h @@ -0,0 +1,33 @@ +#ifndef CACHE_H +#define CACHE_H + +#include +#include +#include +#include + +#include "variable.h" + +class Cache : public Bu::Singleton +{ +friend class Bu::Singleton; +private: + Cache(); + virtual ~Cache(); + +public: + void bind( const Bu::FString &sCacheFile ); + + void load(); + void save(); + +private: + Bu::FString sCacheFile; + bool bIsLoaded; + typedef Bu::Hash > ReqHash; + ReqHash hRequires; + typedef Bu::Hash VarHash; + VarHash hVariables; +}; + +#endif diff --git a/src/variable.cpp b/src/variable.cpp index 99bac59..87571b6 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -890,3 +890,84 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ) return f; } +Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ) +{ + ar << (int8_t)v.eType; + switch( v.eType ) + { + case Variable::typeNone: + break; + + case Variable::typeBool: + ar << v.uVal.bVal; + break; + + case Variable::typeInt: + ar << v.uVal.iVal; + break; + + case Variable::typeFloat: + ar << v.uVal.fVal; + break; + + case Variable::typeVersion: + break; + + case Variable::typeString: + ar << *v.uVal.sVal; + break; + + case Variable::typeList: + ar << *v.uVal.lVal; + break; + + case Variable::typeRef: + ar << *v.uVal.sVal; + break; + } + + return ar; +} + +Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ) +{ + int8_t t; + ar >> t; + v.eType = (Variable::Type)t; + v.reset( v.eType ); + switch( v.eType ) + { + case Variable::typeNone: + break; + + case Variable::typeBool: + ar >> v.uVal.bVal; + break; + + case Variable::typeInt: + ar >> v.uVal.iVal; + break; + + case Variable::typeFloat: + ar >> v.uVal.fVal; + break; + + case Variable::typeVersion: + break; + + case Variable::typeString: + ar >> *v.uVal.sVal; + break; + + case Variable::typeList: + ar >> *v.uVal.lVal; + break; + + case Variable::typeRef: + ar >> *v.uVal.sVal; + break; + } + + return ar; +} + diff --git a/src/variable.h b/src/variable.h index 1b5542e..c8679a8 100644 --- a/src/variable.h +++ b/src/variable.h @@ -2,12 +2,15 @@ #define VARIABLE_H #include "types.h" +#include /** * A build variable, which is basically a flexible, limited type range variant. */ class Variable { +friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); +friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); public: enum Type { @@ -112,4 +115,7 @@ namespace Bu Bu::Formatter &operator<<( Bu::Formatter &f, const Variable::Type &t ); Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ); +Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); +Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); + #endif -- cgit v1.2.3