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

LabelSet.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Feature_LabelSet_h
00002 #define Impala_Core_Feature_LabelSet_h
00003 
00004 #include "Util/Database.h"
00005 #include "Util/SimpleMap.h"
00006 
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Feature
00012 {
00013 
00014 
00015 class LabelSet
00016 {
00017 public:
00018 
00019     LabelSet()
00020     {
00021         mId = 0;
00022     }
00023 
00024     int
00025     GetNrLabels()
00026     {
00027         return mMap.Size();
00028     }
00029 
00030     Quid
00031     GetQuid(String label)
00032     {
00033         Quid quid = 0;
00034         mMap.GetIdx(label, quid);
00035         return quid;
00036     }
00037 
00038     String
00039     GetString(Quid quid)
00040     {
00041         String res = "unknown";
00042         mMap.Get(quid, res);
00043         return res;
00044     }
00045 
00046     Quid
00047     Add(String label)
00048     {
00049         Quid quid = GetQuid(label);
00050         if (quid == 0)
00051         {
00052             quid = MakeQuidLabel(mId++);
00053             mMap.Add(quid, label);
00054         }
00055         return quid;
00056     }
00057 
00058 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00059     void
00060     Load(String fileName, Util::Database* db)
00061     {
00062         Util::IOBuffer* buf = db->GetIOBuffer(fileName, true, true, "");
00063         if (buf)
00064         {
00065             int nr = 0;
00066             while (buf->Available())
00067             {
00068                 Quid q;
00069                 buf->NativeTypeRead(&q);
00070                 String label = buf->ReadLine();
00071                 mMap.Add(q, label);
00072                 nr++;
00073             }
00074             mId += nr;
00075         }
00076         delete buf;
00077     }
00078 
00079     void
00080     Save(String fileName, Util::Database* db)
00081     {
00082         Util::IOBuffer* buf = db->GetIOBuffer(fileName, false, false, "tmp");
00083         if (buf)
00084         {
00085             std::vector<Quid> quids = mMap.GetAllIdx();
00086             std::vector<String> labels = mMap.GetAll();
00087             for (int i=0 ; i<quids.size() ; i++)
00088             {
00089                 buf->NativeTypeWrite(quids[i]);
00090                 buf->Puts(labels[i]);
00091             }
00092         }
00093         delete buf;
00094     }
00095 #endif // REPOSITORY_USED
00096 
00097     void
00098     Read(Util::IOBuffer* buf)
00099     {
00100         if (buf)
00101         {
00102             int nr = 0;
00103             while (buf->Available())
00104             {
00105                 Quid q;
00106                 buf->NativeTypeRead(&q);
00107                 String label = buf->ReadLine();
00108                 mMap.Add(q, label);
00109                 nr++;
00110             }
00111             mId += nr;
00112         }
00113     }
00114 
00115     void
00116     Write(Util::IOBuffer* buf)
00117     {
00118         if (buf)
00119         {
00120             std::vector<Quid> quids = mMap.GetAllIdx();
00121             std::vector<String> labels = mMap.GetAll();
00122             for (int i=0 ; i<quids.size() ; i++)
00123             {
00124                 buf->NativeTypeWrite(quids[i]);
00125                 buf->Puts(labels[i]);
00126             }
00127         }
00128     }
00129 
00130 private:
00131 
00132     int mId;
00133     Util::SimpleMap<Quid, String> mMap;
00134 
00135 };
00136 
00137 } // namespace Feature
00138 } // namespace Core
00139 } // namespace Impala
00140 
00141 #endif

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