Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

FeatureTableRepositoryInFile.h

Go to the documentation of this file.
00001 #ifndef Impala_Persistency_FeatureTableRepositoryInFile_h
00002 #define Impala_Persistency_FeatureTableRepositoryInFile_h
00003 
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Core/Feature/FeatureTable.h"
00006 #include "Persistency/FeatureLocator.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Persistency
00011 {
00012 
00013 
00014 class FeatureTableRepositoryInFile
00015 {
00016 public:
00017 
00018     typedef Core::Feature::FeatureTable FeatureTable;
00019 
00020     FeatureTableRepositoryInFile()
00021     {
00022     }
00023 
00024     bool
00025     Exists(const FeatureLocator& loc)
00026     {
00027         String dir = GetDir(loc);
00028         String ext = ".tab";
00029         // todo : kill the .tab for after data is renamed on file system
00030         //if (FileNameExt(loc.GetFeatureString()) == "txt")
00031         //    ext = "";
00032         File file = RepFS().GetFile(loc, dir, loc.GetFeatureString() + ext,
00033                                     false, true);
00034         return file.Valid();
00035     }
00036 
00037     FeatureTable*
00038     Get(const FeatureLocator& loc)
00039     {
00040         FeatureTable* res = new FeatureTable(loc.GetFeatureDef());
00041         String dir = GetDir(loc);
00042         String ext = ".tab";
00043         // todo : kill the .tab for after data is renamed on file system
00044         //if (FileNameExt(loc.GetFeatureString()) == "txt")
00045         //    ext = "";
00046         File file = RepFS().GetFile(loc, dir, loc.GetFeatureString() + ext,
00047                                     false, false);
00048         if (!file.Valid())
00049             return 0;
00050         Read(res, file);
00051         return res;
00052     }
00053 
00054     void
00055     Add(const FeatureLocator& loc, FeatureTable* tab)
00056     {
00057         String dir = GetDir(loc);
00058         File file = RepFS().GetFile(loc, dir, loc.GetFeatureString() + ".tab",
00059                                     true, false);
00060         Write(tab, file);
00061     }
00062 
00063 private:
00064 
00065     RepositoryInFileSystem&
00066     RepFS()
00067     {
00068         return RepositoryInFileSystem::GetInstance();
00069     }
00070 
00071     String
00072     GetDir(const FeatureLocator& loc)
00073     {
00074         String dir = loc.GetTopString();
00075         dir = FileNameConcat(dir, loc.GetWalkType());
00076         if (!loc.GetIsCodebook())
00077             dir = FileNameConcat(dir, loc.GetFeatureName());
00078         dir = FileNameConcat(dir, loc.GetContainer());
00079         if (loc.GetIsPartial())
00080             dir = FileNameConcat(dir, "part_" + MakeString(loc.GetStartFrame()));
00081         return dir;
00082     }
00083 
00084     ILOG_VAR_DEC;
00085 };
00086 
00087 ILOG_VAR_INIT(FeatureTableRepositoryInFile, Impala.Persistency);
00088 
00089 } // namespace Persistency
00090 } // namespace Impala
00091 
00092 #endif

Generated on Fri Mar 19 09:31:42 2010 for ImpalaSrc by  doxygen 1.5.1