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

ImageSetRepository.h

Go to the documentation of this file.
00001 This file is moved to Persistency/ImageSetsRepository.h
00002 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00003 
00004 #ifndef Impala_Core_ImageSet_ImageSetRepository_h
00005 #define Impala_Core_ImageSet_ImageSetRepository_h
00006 
00007 #include "Basis/Quids.h"
00008 #include "Basis/QuidObj.h"
00009 #include "Util/Database.h"
00010 #include "Util/SimpleMap.h"
00011 
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace ImageSet
00017 {
00018 
00019 
00020 class ImageSet;
00021 
00022 class ImageSetRepository
00023 {
00024 public:
00025 
00026     static ImageSetRepository&
00027     GetInstance()
00028     {
00029         static ImageSetRepository theImageSetRepository;
00030         return theImageSetRepository;
00031     }
00032 
00033     int
00034     GetId(String setName)
00035     {
00036         int id = 0;
00037         mIdMap.GetIdx(FileNameBase(setName), id);
00038         return id;
00039     }
00040 
00041     String
00042     GetSetName(int id)
00043     {
00044         String res = "unknown";
00045         mIdMap.Get(id, res);
00046         return res;
00047     }
00048 
00049     void
00050     Register(ImageSet* vs, String setName)
00051     {
00052         int id = GetId(setName);
00053         if (id == 0)
00054         {
00055             ILOG_ERROR("Cannot find " << setName);
00056             return;
00057         }
00058         mSetMap.Add(id, vs);
00059     }
00060 
00061     ImageSet*
00062     GetImageSet(int id)
00063     {
00064         ImageSet* res = 0;
00065         if (! mSetMap.Get(id, res))
00066             ILOG_INFO("Couldn't find ImageSet with id = " << id);
00067         return res;
00068     }
00069 
00070     ImageSet*
00071     GetImageSet(Quid quid)
00072     {
00073         return GetImageSet(QuidSet(quid));
00074     }
00075 
00076     String
00077     QuidToString(Quid quid, bool elaborate)
00078     {
00079         QuidObj qObj(quid);
00080         if (!elaborate)
00081             return qObj.ToString();
00082         String setName = "unknown";
00083         mIdMap.Get(qObj.Set(), setName);
00084         return "Q(" + QuidClassToString(qObj.Class()) + "," + setName + "," +
00085             MakeString(qObj.Object()) + "," + MakeString(qObj.Id()) + ")";
00086     }
00087 
00088 private:
00089 
00090     ImageSetRepository() : mIdMap(false), mSetMap(false)
00091     {
00092         CmdOptions& options = CmdOptions::GetInstance();
00093         mFileName = options.GetString("imageSetRepository");
00094         ILOG_DEBUG("opening image datasets file " << mFileName);
00095         Util::Database& db = Util::Database::GetInstance();
00096         CString filePath = db.GetFilePath(mFileName, false, false);
00097         Util::IOBuffer* buf = db.GetIOBuffer(filePath, true, true, "");
00098         if (buf)
00099         {
00100             while (buf->Available())
00101             {
00102                 String line = buf->ReadLine();
00103                 if (line[0] && (line[0] != '#'))
00104                 {
00105                     Util::StringParser p(line);
00106                     int setId = p.GetInt();
00107                     String setName = p.GetString2(false);
00108                     mIdMap.Add(setId, setName);
00109                 }
00110             }
00111             delete buf;
00112         }
00113         ILOG_DEBUG("done read file");
00114     }
00115 
00116     String                          mFileName;
00117     Util::SimpleMap<int, String>    mIdMap;
00118     Util::SimpleMap<int, ImageSet*> mSetMap;
00119 
00120     ILOG_VAR_DEC;
00121 };
00122 
00123 ILOG_VAR_INIT(ImageSetRepository, Impala.Core.ImageSet);
00124 
00125 } // namespace ImageSet
00126 } // namespace Core
00127 } // namespace Impala
00128 
00129 #endif

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