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

ImageSetsRepository.h

Go to the documentation of this file.
00001 #ifndef Impala_Persistency_ImageSetsRepository_h
00002 #define Impala_Persistency_ImageSetsRepository_h
00003 
00004 #include "Basis/Quids.h"
00005 #include "Basis/QuidObj.h"
00006 #include "Util/SimpleMap.h"
00007 #include "Util/StringParser.h"
00008 #include "Persistency/RepositoryInFileSystem.h"
00009 
00010 namespace Impala
00011 {
00012 
00013 // For forward declaration of ImageSet
00014 namespace Core
00015 {
00016 namespace ImageSet
00017 {
00018 
00019 class ImageSet;
00020 
00021 } // namespace ImageSet
00022 } // namespace Core
00023 
00024 
00025 namespace Persistency
00026 {
00027 
00028 
00029 class ImageSetsRepository
00030 {
00031 public:
00032 
00033     typedef Core::ImageSet::ImageSet ImageSet;
00034 
00035     static ImageSetsRepository&
00036     GetInstance()
00037     {
00038         static ImageSetsRepository theImageSetsRepository;
00039         return theImageSetsRepository;
00040     }
00041 
00042     bool
00043     Contains(CString setName)
00044     {
00045         int id = 0;
00046         return mIdMap.GetIdx(FileNameBase(setName), id);
00047     }
00048 
00049     int
00050     GetId(String setName)
00051     {
00052         int id = 0;
00053         mIdMap.GetIdx(FileNameBase(setName), id);
00054         return id;
00055     }
00056 
00057     String
00058     GetSetName(int id)
00059     {
00060         String res = "unknown";
00061         mIdMap.Get(id, res);
00062         return res;
00063     }
00064 
00065     void
00066     Register(ImageSet* vs, String setName)
00067     {
00068         int id = GetId(setName);
00069         if (id == 0)
00070         {
00071             ILOG_ERROR("Cannot find " << setName);
00072             return;
00073         }
00074         mSetMap.Add(id, vs);
00075     }
00076 
00077     ImageSet*
00078     GetImageSet(int id)
00079     {
00080         ImageSet* res = 0;
00081         if (! mSetMap.Get(id, res))
00082             ILOG_INFO("Couldn't find ImageSet with id = " << id);
00083         return res;
00084     }
00085 
00086     ImageSet*
00087     GetImageSet(Quid quid)
00088     {
00089         return GetImageSet(QuidSet(quid));
00090     }
00091 
00092     String
00093     QuidToString(Quid quid, bool elaborate)
00094     {
00095         QuidObj qObj(quid);
00096         if (!elaborate)
00097             return qObj.ToString();
00098         String setName = "unknown";
00099         mIdMap.Get(qObj.Set(), setName);
00100         return "Q(" + QuidClassToString(qObj.Class()) + "," + setName + "," +
00101             MakeString(qObj.Object()) + "," + MakeString(qObj.Id()) + ")";
00102     }
00103 
00104     void
00105     Dump() const
00106     {
00107         mIdMap.Dump("ImageSets: ");
00108     }
00109 
00110 private:
00111 
00112     ImageSetsRepository()
00113     {
00114         CmdOptions& options = CmdOptions::GetInstance();
00115         Locator loc("config", options);
00116         String protocol = loc.GetProtocol();
00117         if ((protocol == "file") || (protocol == "dataServer"))
00118         {
00119             GetFromFileSystem(loc);
00120         }
00121         else
00122         {
00123             ILOG_ERROR("Get: unknown protocol: " << loc.GetProtocol());
00124         }
00125     }
00126 
00127     void
00128     GetFromFileSystem(const Locator& loc)
00129     {
00130         CmdOptions& options = CmdOptions::GetInstance();
00131         String repName = options.GetString("imageSetsRepository");
00132         File f = RepositoryInFileSystem::GetInstance().GetFile(loc, repName,
00133                                                                false, false);
00134         Util::IOBuffer* buf = f.GetReadBuffer();
00135         if (buf)
00136         {
00137             while (buf->Available())
00138             {
00139                 String line = buf->ReadLine();
00140                 if (line[0] && (line[0] != '#'))
00141                 {
00142                     Util::StringParser p(line);
00143                     int setId = p.GetInt();
00144                     String setName = p.GetString2(false);
00145                     mIdMap.Add(setId, setName);
00146                 }
00147             }
00148             delete buf;
00149         }
00150     }
00151 
00152     String                          mFileName;
00153     Util::SimpleMap<int, String>    mIdMap;
00154     Util::SimpleMap<int, ImageSet*> mSetMap;
00155 
00156     ILOG_VAR_DEC;
00157 };
00158 
00159 ILOG_VAR_INIT(ImageSetsRepository, Impala.Persistency);
00160 
00161 } // namespace Persistency
00162 } // namespace Impala
00163 
00164 #endif

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