Go to the documentation of this file.00001
00002 #ifndef EPT_POPCON_POPCON_H
00003 #define EPT_POPCON_POPCON_H
00004
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <tagcoll/diskindex/mmap.h>
00029 #include <string>
00030
00031 namespace ept {
00032 namespace apt {
00033 class Apt;
00034 }
00035
00036 namespace popcon {
00037
00043 class Score
00044 {
00045 protected:
00046 unsigned offset;
00047
00048 public:
00049 float score;
00050
00051 Score(float score) : offset(offset), score(score) {}
00052
00053 friend class Popcon;
00054 friend class PopconIndexer;
00055 friend class PopconGenerator;
00056 };
00057
00072 class Popcon : public tagcoll::diskindex::MMap
00073 {
00074 struct GeneralInfo : public tagcoll::diskindex::MMap
00075 {
00076 size_t submissions() const;
00077 };
00078
00079 tagcoll::diskindex::MasterMMap mastermmap;
00080 time_t m_timestamp;
00081
00082 GeneralInfo m_info;
00083
00085 const Score* structByIndex(size_t idx) const
00086 {
00087 if (idx >= 0 && idx < size())
00088 return (Score*)m_buf + idx;
00089 return 0;
00090 }
00091
00092 public:
00093 Popcon();
00094
00096 time_t timestamp() const { return m_timestamp; }
00097
00099 bool hasData() const { return m_timestamp != 0; }
00100
00102 size_t submissions() const { return m_info.submissions(); }
00103
00105 size_t size() const
00106 {
00107 if (m_buf)
00108 return ((Score*)m_buf)->offset / sizeof(Score);
00109 else
00110 return 0;
00111 }
00112
00118 std::string name(size_t idx) const
00119 {
00120 const Score* s = structByIndex(idx);
00121 if (s == 0) return std::string();
00122 return std::string(m_buf + s->offset);
00123 }
00124
00126 float scoreByIndex(size_t idx) const
00127 {
00128 const Score* s = structByIndex(idx);
00129 if (!s) return 0;
00130 return s->score;
00131 }
00132
00134 float scoreByName(const std::string& name) const;
00135
00137 float score(size_t idx) const { return scoreByIndex(idx); }
00138
00140 float operator[](int idx) const { return scoreByIndex(idx); }
00141
00143 float score(const std::string& name) const { return scoreByName(name); }
00144
00146 float operator[](const std::string& name) const { return scoreByName(name); }
00147 };
00148
00149 }
00150 }
00151
00152
00153 #endif