Home || Visual Search || Applications || Architecture || 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, false);
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, false);
00036         File f = RepFS().GetFile(loc, dir, loc.GetName(), false, false);
00037         Util::IOBuffer* buf = f.GetReadBuffer(true, "");
00038         // Mpeg7Doc ctor will delete buf
00039         Mpeg7Doc* res = new Mpeg7Doc(loc.GetName(), buf, loc.GetFrameRateNum(),
00040                                      loc.GetFrameRateDen());
00041         return res;
00042     }
00043 
00044     void
00045     Add(const Mpeg7DocLocator& loc, Mpeg7Doc* doc)
00046     {
00047         String dir = GetDir(loc, false);
00048         File f = RepFS().GetFile(loc, dir, loc.GetName(), true, false);
00049         Util::IOBuffer* ioBuf = f.GetWriteBuffer();
00050         if (! ioBuf)
00051             return;
00052         doc->ExportXml(ioBuf);
00053         delete ioBuf;
00054     }
00055 
00056     void
00057     Delete(const Mpeg7DocLocator& loc)
00058     {
00059         if (loc.GetContainer() == "ALL")
00060         {
00061             String dir = GetDir(loc, true);
00062             RepFS().DeleteDir(loc, dir);
00063         }
00064         else
00065         {
00066             String dir = GetDir(loc, false);
00067             File file = RepFS().GetFile(loc, dir, loc.GetName(), true, true);
00068             file.Delete();
00069         }
00070     }
00071 
00072 private:
00073 
00074     RepositoryInFileSystem&
00075     RepFS()
00076     {
00077         return RepositoryInFileSystem::GetInstance();
00078     }
00079 
00080     String
00081     GetDir(const Mpeg7DocLocator& loc, bool forAll)
00082     {
00083         String dir("unknown");
00084         if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_PLAIN)
00085             dir = "";
00086         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_SHOT)
00087             dir = "MetaData/shots/";
00088         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_CONCEPT)
00089             dir = "MetaData/similarities/";
00090         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_ANNOTATION)
00091             dir = "MetaData/annotations/";
00092         else if (loc.GetDocType() == Mpeg7DocLocator::MPEG7_FEATURE)
00093             dir = "MetaData/features/";
00094         else
00095             ILOG_ERROR("GetDir: unknown type in locator");
00096 
00097         if (forAll)
00098             return dir;
00099 
00100         dir = FileNameConcat(dir, loc.GetContainer());
00101         return dir;
00102     }
00103 
00104     ILOG_VAR_DEC;
00105 };
00106 
00107 ILOG_VAR_INIT(Mpeg7DocRepositoryInFile, Impala.Persistency);
00108 
00109 } // namespace Persistency
00110 } // namespace Impala
00111 
00112 #endif

Generated on Thu Jan 13 09:05:09 2011 for ImpalaSrc by  doxygen 1.5.1