00001 #ifndef Impala_Persistency_VideoSetRepositoryInFile_h
00002 #define Impala_Persistency_VideoSetRepositoryInFile_h
00003
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Core/VideoSet/VideoSet.h"
00006
00007 namespace Impala
00008 {
00009 namespace Persistency
00010 {
00011
00012
00013 class VideoSetRepositoryInFile
00014 {
00015 public:
00016
00017 typedef Core::VideoSet::VideoSet VideoSet;
00018
00019 VideoSetRepositoryInFile()
00020 {
00021 }
00022
00023 bool
00024 Exists(const Locator& loc)
00025 {
00026 File f = RepFS().GetFile(loc, "VideoData", loc.GetDataSet(), false,
00027 true);
00028 return f.Valid();
00029 }
00030
00031 VideoSet*
00032 Get(const Locator& loc)
00033 {
00034 VideoSet* res = new VideoSet(loc.GetDataSet());
00035 res->SetProtocolAndHost(loc.GetProtocolAndHost());
00036 File f = RepFS().GetFile(loc, "VideoData", loc.GetDataSet(), false,
00037 false);
00038 Timer timer(1);
00039 Util::IOBuffer* buf = f.GetReadBuffer(true, "");
00040 if (buf->Valid())
00041 {
00042 while (buf->Available())
00043 {
00044 String line = buf->ReadLine();
00045 if (line[0] && (line[0] != '#'))
00046 {
00047 int id = -1;
00048 String name("");
00049 Util::StringParser p(line);
00050 while (!p.TheEnd())
00051 {
00052 if (p.At("<id="))
00053 {
00054 p.Eat('=');
00055 id = p.GetInt('>', true);
00056 p.Eat('>');
00057 }
00058 else
00059 {
00060 String s = p.GetString2(false);
00061 name = StringReplaceAll(s, "\\", "/");
00062 }
00063 }
00064 res->AddFile(name, id);
00065 }
00066 }
00067 }
00068 delete buf;
00069 return res;
00070 }
00071
00072 void
00073 Add(const Locator& loc, VideoSet* vidSet)
00074 {
00075 File f = RepFS().GetFile(loc, "VideoData", loc.GetDataSet(), true,
00076 false);
00077
00078 Util::IOBuffer* ioBuf = f.GetWriteBuffer();
00079 if (! ioBuf)
00080 return;
00081 for (int i=0 ; i<vidSet->NrFiles() ; i++)
00082 ioBuf->IOBuffer::Puts("\"" + vidSet->GetAsPath(i) + "\"");
00083 delete ioBuf;
00084 }
00085
00086 void
00087 Delete(const Locator& loc)
00088 {
00089 File file = RepFS().GetFile(loc, "VideoData", loc.GetDataSet(), true,
00090 true);
00091 file.Delete();
00092 }
00093
00094 private:
00095
00096 RepositoryInFileSystem&
00097 RepFS()
00098 {
00099 return RepositoryInFileSystem::GetInstance();
00100 }
00101
00102 ILOG_VAR_DEC;
00103 };
00104
00105 ILOG_VAR_INIT(VideoSetRepositoryInFile, Impala.Persistency);
00106
00107 }
00108 }
00109
00110 #endif