00001 This file is moved to Persistency/VideoSetsRepository.h
00002 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00003
00004 #ifndef Impala_Core_VideoSet_VideoSetRepository_h
00005 #define Impala_Core_VideoSet_VideoSetRepository_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 VideoSet
00017 {
00018
00019
00020 class VideoSet;
00021
00022 class VideoSetRepository
00023 {
00024 public:
00025
00026 static VideoSetRepository&
00027 GetInstance()
00028 {
00029 static VideoSetRepository theVideoSetRepository;
00030 return theVideoSetRepository;
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(VideoSet* 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 VideoSet*
00062 GetVideoSet(int id)
00063 {
00064 VideoSet* res = 0;
00065 if (! mSetMap.Get(id, res))
00066 ILOG_INFO("Couldn't find VideoSet with id = " << id);
00067 return res;
00068 }
00069
00070 VideoSet*
00071 GetVideoSet(Quid quid)
00072 {
00073 return GetVideoSet(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 VideoSetRepository() : mIdMap(false), mSetMap(false)
00091 {
00092 CmdOptions& options = CmdOptions::GetInstance();
00093 mFileName = options.GetString("videoSetRepository");
00094 ILOG_DEBUG("opening video 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, VideoSet*> mSetMap;
00119
00120 ILOG_VAR_DEC;
00121 };
00122
00123 ILOG_VAR_INIT(VideoSetRepository, Impala.Core.VideoSet);
00124
00125 }
00126 }
00127 }
00128
00129 #endif