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

Mpeg7DocRepositoryInFile.h

Go to the documentation of this file.
00001 #ifndef Impala_Persistency_Mpeg7DocRepositoryInFile_h
00002 #define Impala_Persistency_Mpeg7DocRepositoryInFile_h
00003 
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Core/VideoSet/Mpeg7Doc.h"
00006 #include "Persistency/Mpeg7DocLocator.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Persistency
00011 {
00012 
00013 
00014 class Mpeg7DocRepositoryInFile
00015 {
00016 public:
00017 
00018     typedef Core::VideoSet::Mpeg7Doc Mpeg7Doc;
00019 
00020     Mpeg7DocRepositoryInFile()
00021     {
00022     }
00023 
00024     bool
00025     Exists(const Mpeg7DocLocator& loc)
00026     {
00027         String dir = GetDir(loc);
00028         File f = RepFS().GetFile(loc, dir, loc.GetName(), false, true);
00029         return f.Valid();
00030     }
00031 
00032     Mpeg7Doc*
00033     Get(const Mpeg7DocLocator& loc)
00034     {
00035         String dir = GetDir(loc);
00036         File f = RepFS().GetFile(loc, dir, loc.GetName(), false, false);
00037         Util::IOBuffer* buf = f.GetReadBuffer(true, "");
00038         Mpeg7Doc* res = new Mpeg7Doc(loc.GetName(), buf); // will delete buf
00039         return res;
00040     }
00041 
00042     void
00043     Add(const Mpeg7DocLocator& loc, Mpeg7Doc* doc)
00044     {
00045         String dir = GetDir(loc);
00046         File f = RepFS().GetFile(loc, dir, loc.GetName(), true, false);
00047         Util::IOBuffer* ioBuf = f.GetWriteBuffer();
00048         if (! ioBuf)
00049             return;
00050         doc->ExportXml(ioBuf);
00051         delete ioBuf;
00052     }
00053 
00054 private:
00055 
00056     RepositoryInFileSystem&
00057     RepFS()
00058     {
00059         return RepositoryInFileSystem::GetInstance();
00060     }
00061 
00062     String
00063     GetDir(const Mpeg7DocLocator& loc)
00064     {
00065         String dir("unknown");
00066         if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_PLAIN)
00067             dir = "";
00068         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_SHOT)
00069             dir = "MetaData/shots/";
00070         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_CONCEPT)
00071             dir = "MetaData/shots/";
00072         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_ANNOTATION)
00073             dir = "MetaData/annotations/";
00074         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_FEATURE)
00075             dir = "MetaData/features/";
00076         else
00077             ILOG_ERROR("GetDir: unknown type in locator");
00078         dir = FileNameConcat(dir, loc.GetContainer());
00079         return dir;
00080     }
00081 
00082     ILOG_VAR_DEC;
00083 };
00084 
00085 ILOG_VAR_INIT(Mpeg7DocRepositoryInFile, Impala.Persistency);
00086 
00087 } // namespace Persistency
00088 } // namespace Impala
00089 
00090 #endif

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