00001 #ifndef Impala_Persistency_AllParameterFileRepositoryInFile_h
00002 #define Impala_Persistency_AllParameterFileRepositoryInFile_h
00003
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Persistency/ModelLocator.h"
00006 #include "Util/PropertySet.h"
00007
00008 namespace Impala
00009 {
00010 namespace Persistency
00011 {
00012
00013
00014 class AllParameterFileRepositoryInFile
00015 {
00016 public:
00017
00018 AllParameterFileRepositoryInFile()
00019 {
00020 }
00021
00022 bool
00023 Exists(const ModelLocator& loc)
00024 {
00025 String dir = GetDir(loc);
00026 String name = loc.GetConcept() + ".allparameters";
00027 File file = RepFS().GetFile(loc, dir, name, false, true);
00028 return file.Valid();
00029 }
00030
00031 std::vector<Util::PropertySet*>*
00032 Get(const ModelLocator& loc)
00033 {
00034 typedef std::vector<Util::PropertySet*> VecPS;
00035 String dir = GetDir(loc);
00036 String name = loc.GetConcept() + ".allparameters";
00037 File file = RepFS().GetFile(loc, dir, name, false, false);
00038 if (!file.Valid())
00039 return 0;
00040
00041 VecPS* res = new VecPS;
00042 Util::IOBuffer* buf = file.GetReadBuffer();
00043 if (buf)
00044 {
00045 while (buf->Available())
00046 {
00047 Util::PropertySet* ps = new Util::PropertySet;
00048 Read(ps, buf);
00049 if (ps->Size() != 0)
00050 (*res).push_back(ps);
00051 }
00052 delete buf;
00053 }
00054 return res;
00055 }
00056
00057 void
00058 Add(const ModelLocator& loc, std::vector<Util::PropertySet*>* set)
00059 {
00060 String dir = GetDir(loc);
00061 String name = loc.GetConcept() + ".allparameters";
00062 File file = RepFS().GetFile(loc, dir, name, true, false);
00063 Util::IOBuffer* buf = file.GetWriteBuffer();
00064 if (buf)
00065 {
00066 std::vector<Util::PropertySet*> tmp = *set;
00067 for (int i=0 ; i<tmp.size() ; i++)
00068 Write(tmp[i], buf);
00069 delete buf;
00070 }
00071 }
00072
00073 private:
00074
00075 RepositoryInFileSystem&
00076 RepFS()
00077 {
00078 return RepositoryInFileSystem::GetInstance();
00079 }
00080
00081 String
00082 GetDir(const ModelLocator& loc)
00083 {
00084 String dir = "ConceptModels";
00085 dir = FileNameConcat(dir, loc.GetConceptSet());
00086 dir = FileNameConcat(dir, loc.GetModel());
00087 dir = FileNameConcat(dir, loc.GetFeature());
00088 return dir;
00089 }
00090
00091 ILOG_VAR_DEC;
00092 };
00093
00094 ILOG_VAR_INIT(AllParameterFileRepositoryInFile, Impala.Persistency);
00095
00096 }
00097 }
00098
00099 #endif