00001 #ifndef Impala_Persistency_FeatureListRepositoryInFile_h
00002 #define Impala_Persistency_FeatureListRepositoryInFile_h
00003
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Core/Feature/FeatureList.h"
00006 #include "Persistency/FeatureLocator.h"
00007
00008 namespace Impala
00009 {
00010 namespace Persistency
00011 {
00012
00013
00014 class FeatureListRepositoryInFile
00015 {
00016 public:
00017
00018 typedef Core::Feature::FeatureList FeatureList;
00019
00020 FeatureListRepositoryInFile()
00021 {
00022 }
00023
00024 bool
00025 Exists(const FeatureLocator& loc)
00026 {
00027 String dir = GetDir(loc);
00028 File file = RepFS().GetFile(loc, dir, loc.GetFeatureString(),
00029 false, true);
00030 return file.Valid();
00031 }
00032
00033 FeatureList*
00034 Get(const FeatureLocator& loc)
00035 {
00036 String dir = GetDir(loc);
00037 File file = (StringStartsWith(loc.GetFeatureString(), ".."))
00038 ? RepFS().GetFile(loc, "", loc.GetFeatureString(), false, true)
00039 : RepFS().GetFile(loc, dir, loc.GetFeatureString(), false, true);
00040 if (!file.Valid())
00041 return 0;
00042 FeatureList* res = new FeatureList();
00043 file.ReadStrings(std::back_inserter(*res));
00044 return res;
00045 }
00046
00047 void
00048 Add(const FeatureLocator& loc, FeatureList* keyList)
00049 {
00050 String dir = GetDir(loc);
00051 File file = RepFS().GetFile(loc, dir, loc.GetFeatureString(),
00052 true, false);
00053 if (!file.Valid())
00054 return;
00055 file.WriteStrings(keyList->begin(), keyList->end());
00056 }
00057
00058 private:
00059
00060 RepositoryInFileSystem&
00061 RepFS()
00062 {
00063 return RepositoryInFileSystem::GetInstance();
00064 }
00065
00066 String
00067 GetDir(const FeatureLocator& loc)
00068 {
00069 String dir = loc.GetTopString();
00070 dir = FileNameConcat(dir, loc.GetWalkType());
00071 if (!loc.GetIsCodebook())
00072 dir = FileNameConcat(dir, loc.GetFeatureName());
00073 dir = FileNameConcat(dir, loc.GetContainer());
00074
00075
00076 return dir;
00077 }
00078
00079 ILOG_VAR_DEC;
00080 };
00081
00082 ILOG_VAR_INIT(FeatureListRepositoryInFile, Impala.Persistency);
00083
00084 }
00085 }
00086
00087 #endif