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

ImageSetRepositoryInFile.h

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

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