diff options
Diffstat (limited to '')
-rw-r--r-- | src/cache.cpp | 39 | ||||
-rw-r--r-- | src/cache.h | 33 | ||||
-rw-r--r-- | src/variable.cpp | 81 | ||||
-rw-r--r-- | src/variable.h | 6 |
4 files changed, 159 insertions, 0 deletions
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 @@ | |||
1 | #include "cache.h" | ||
2 | #include <bu/file.h> | ||
3 | #include <bu/archive.h> | ||
4 | |||
5 | Cache::Cache() : | ||
6 | bIsLoaded( false ) | ||
7 | { | ||
8 | } | ||
9 | |||
10 | Cache::~Cache() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | void Cache::bind( const Bu::FString &sCacheFile ) | ||
15 | { | ||
16 | this->sCacheFile = sCacheFile; | ||
17 | load(); | ||
18 | } | ||
19 | |||
20 | void Cache::load() | ||
21 | { | ||
22 | if( bIsLoaded ) | ||
23 | return; | ||
24 | Bu::File fIn( sCacheFile, Bu::File::Read ); | ||
25 | Bu::Archive ar( fIn, Bu::Archive::load ); | ||
26 | |||
27 | ar >> hRequires >> hVariables; | ||
28 | |||
29 | bIsLoaded = true; | ||
30 | } | ||
31 | |||
32 | void Cache::save() | ||
33 | { | ||
34 | Bu::File fIn( sCacheFile, Bu::File::WriteNew ); | ||
35 | Bu::Archive ar( fIn, Bu::Archive::save ); | ||
36 | |||
37 | ar << hRequires << hVariables; | ||
38 | } | ||
39 | |||
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 @@ | |||
1 | #ifndef CACHE_H | ||
2 | #define CACHE_H | ||
3 | |||
4 | #include <bu/singleton.h> | ||
5 | #include <bu/fstring.h> | ||
6 | #include <bu/hash.h> | ||
7 | #include <bu/list.h> | ||
8 | |||
9 | #include "variable.h" | ||
10 | |||
11 | class Cache : public Bu::Singleton<Cache> | ||
12 | { | ||
13 | friend class Bu::Singleton<Cache>; | ||
14 | private: | ||
15 | Cache(); | ||
16 | virtual ~Cache(); | ||
17 | |||
18 | public: | ||
19 | void bind( const Bu::FString &sCacheFile ); | ||
20 | |||
21 | void load(); | ||
22 | void save(); | ||
23 | |||
24 | private: | ||
25 | Bu::FString sCacheFile; | ||
26 | bool bIsLoaded; | ||
27 | typedef Bu::Hash<Bu::FString, Bu::List<Bu::FString> > ReqHash; | ||
28 | ReqHash hRequires; | ||
29 | typedef Bu::Hash<Bu::FString, Variable> VarHash; | ||
30 | VarHash hVariables; | ||
31 | }; | ||
32 | |||
33 | #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 ) | |||
890 | return f; | 890 | return f; |
891 | } | 891 | } |
892 | 892 | ||
893 | Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ) | ||
894 | { | ||
895 | ar << (int8_t)v.eType; | ||
896 | switch( v.eType ) | ||
897 | { | ||
898 | case Variable::typeNone: | ||
899 | break; | ||
900 | |||
901 | case Variable::typeBool: | ||
902 | ar << v.uVal.bVal; | ||
903 | break; | ||
904 | |||
905 | case Variable::typeInt: | ||
906 | ar << v.uVal.iVal; | ||
907 | break; | ||
908 | |||
909 | case Variable::typeFloat: | ||
910 | ar << v.uVal.fVal; | ||
911 | break; | ||
912 | |||
913 | case Variable::typeVersion: | ||
914 | break; | ||
915 | |||
916 | case Variable::typeString: | ||
917 | ar << *v.uVal.sVal; | ||
918 | break; | ||
919 | |||
920 | case Variable::typeList: | ||
921 | ar << *v.uVal.lVal; | ||
922 | break; | ||
923 | |||
924 | case Variable::typeRef: | ||
925 | ar << *v.uVal.sVal; | ||
926 | break; | ||
927 | } | ||
928 | |||
929 | return ar; | ||
930 | } | ||
931 | |||
932 | Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ) | ||
933 | { | ||
934 | int8_t t; | ||
935 | ar >> t; | ||
936 | v.eType = (Variable::Type)t; | ||
937 | v.reset( v.eType ); | ||
938 | switch( v.eType ) | ||
939 | { | ||
940 | case Variable::typeNone: | ||
941 | break; | ||
942 | |||
943 | case Variable::typeBool: | ||
944 | ar >> v.uVal.bVal; | ||
945 | break; | ||
946 | |||
947 | case Variable::typeInt: | ||
948 | ar >> v.uVal.iVal; | ||
949 | break; | ||
950 | |||
951 | case Variable::typeFloat: | ||
952 | ar >> v.uVal.fVal; | ||
953 | break; | ||
954 | |||
955 | case Variable::typeVersion: | ||
956 | break; | ||
957 | |||
958 | case Variable::typeString: | ||
959 | ar >> *v.uVal.sVal; | ||
960 | break; | ||
961 | |||
962 | case Variable::typeList: | ||
963 | ar >> *v.uVal.lVal; | ||
964 | break; | ||
965 | |||
966 | case Variable::typeRef: | ||
967 | ar >> *v.uVal.sVal; | ||
968 | break; | ||
969 | } | ||
970 | |||
971 | return ar; | ||
972 | } | ||
973 | |||
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 @@ | |||
2 | #define VARIABLE_H | 2 | #define VARIABLE_H |
3 | 3 | ||
4 | #include "types.h" | 4 | #include "types.h" |
5 | #include <bu/archivebase.h> | ||
5 | 6 | ||
6 | /** | 7 | /** |
7 | * A build variable, which is basically a flexible, limited type range variant. | 8 | * A build variable, which is basically a flexible, limited type range variant. |
8 | */ | 9 | */ |
9 | class Variable | 10 | class Variable |
10 | { | 11 | { |
12 | friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); | ||
13 | friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); | ||
11 | public: | 14 | public: |
12 | enum Type | 15 | enum Type |
13 | { | 16 | { |
@@ -112,4 +115,7 @@ namespace Bu | |||
112 | Bu::Formatter &operator<<( Bu::Formatter &f, const Variable::Type &t ); | 115 | Bu::Formatter &operator<<( Bu::Formatter &f, const Variable::Type &t ); |
113 | Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ); | 116 | Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ); |
114 | 117 | ||
118 | Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); | ||
119 | Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); | ||
120 | |||
115 | #endif | 121 | #endif |