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

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