-void StatBag::set(const string &key, int value)
+void StatBag::set(const string &key, unsigned int value)
{
lock();
exists(key);
unlock();
}
-int StatBag::read(const string &key)
+unsigned int StatBag::read(const string &key)
{
lock();
return 0;
}
- int tmp=*d_stats[key];
+ unsigned int tmp=*d_stats[key];
unlock();
return tmp;
-
}
-int StatBag::readZero(const string &key)
+unsigned int StatBag::readZero(const string &key)
{
lock();
}
- int tmp=*d_stats[key];
+ unsigned int tmp=*d_stats[key];
d_stats[key]=0;
unlock();
}
-StatRing::StatRing(int size)
+StatRing::StatRing(unsigned int size)
{
d_size=size;
d_items.resize(d_size);
pthread_mutex_init(d_lock, 0);
}
-void StatRing::resize(int newsize)
+void StatRing::resize(unsigned int newsize)
{
if(d_size==newsize)
return;
int startpos=d_pos-newsize;
int rpos;
vector<string>newring;
- for(int i=startpos;i<d_pos;++i) {
+ for(unsigned int i=startpos;i<d_pos;++i) {
rpos=i>=0 ? i : i+d_size;
newring.push_back(d_items[rpos%d_size]);
return (a.second > b.second);
}
-vector<pair<string,int> >StatRing::get() const
+vector<pair<string,unsigned int> >StatRing::get() const
{
Lock l(d_lock);
- map<string,int> res;
+ map<string,unsigned int> res;
for(vector<string>::const_iterator i=d_items.begin();i!=d_items.end();++i) {
if(!i->empty())
res[*i]++;
}
- vector<pair<string,int> > tmp;
- for(map<string,int>::const_iterator i=res.begin();i!=res.end();++i)
+ vector<pair<string,unsigned int> > tmp;
+ for(map<string,unsigned int>::const_iterator i=res.begin();i!=res.end();++i)
tmp.push_back(*i);
sort(tmp.begin(),tmp.end(),popisort);
d_rings[name].setHelp(help);
}
-vector<pair<string,int> > StatBag::getRing(const string &name)
+vector<pair<string, unsigned int> > StatBag::getRing(const string &name)
{
return d_rings[name].get();
}
d_rings[name].reset();
}
-void StatBag::resizeRing(const string &name, int newsize)
+void StatBag::resizeRing(const string &name, unsigned int newsize)
{
d_rings[name].resize(newsize);
}
-int StatBag::getRingSize(const string &name)
+unsigned int StatBag::getRingSize(const string &name)
{
return d_rings[name].getSize();
}
class StatRing
{
public:
- StatRing(int size=10000);
+ StatRing(unsigned int size=10000);
~StatRing();
void account(const string &item)
{
}
- int getSize()
+ unsigned int getSize()
{
return d_size;
}
- void resize(int newsize);
+ void resize(unsigned int newsize);
void reset();
void setHelp(const string &str);
string getHelp();
- vector<pair<string,int> >get() const;
+ vector<pair<string,unsigned int> >get() const;
private:
- int d_size;
- int d_pos;
- vector<string>d_items;
+ unsigned int d_size;
+ unsigned int d_pos;
+ vector<string> d_items;
pthread_mutex_t *d_lock;
string d_help;
};
void declare(const string &key, const string &descrip=""); //!< Before you can store or access a key, you need to declare it
void declareRing(const string &name, const string &title, unsigned int size=10000);
- vector<pair<string,int> >getRing(const string &name);
+ vector<pair<string, unsigned int> >getRing(const string &name);
string getRingTitle(const string &name);
void ringAccount(const string &name, const string &item)
{
vector<string>listRings();
void resetRing(const string &name);
- void resizeRing(const string &name, int newsize);
- int getRingSize(const string &name);
+ void resizeRing(const string &name, unsigned int newsize);
+ unsigned int getRingSize(const string &name);
string directory(); //!< Returns a list of all data stored
vector<string> getEntries(); //!< returns a vector with datums (items)
void exists(const string &key); //!< call this function to throw an exception in case a key does not exist
inline void deposit(const string &key, int value); //!< increment the statistics behind this key by value amount
inline void inc(const string &key); //!< increase this key's value by one
- void set(const string &key, int value); //!< set this key's value
- int read(const string &key); //!< read the value behind this key
- int readZero(const string &key); //!< read the value behind this key, and zero it afterwards
+ void set(const string &key, unsigned int value); //!< set this key's value
+ unsigned int read(const string &key); //!< read the value behind this key
+ unsigned int readZero(const string &key); //!< read the value behind this key, and zero it afterwards
unsigned int *getPointer(const string &key); //!< get a direct pointer to the value behind a key. Use this for high performance increments
string getValueStr(const string &key); //!< read a value behind a key, and return it as a string
string getValueStrZero(const string &key); //!< read a value behind a key, and return it as a string, and zero afterwards
{
int tot=0;
int entries=0;
- vector<pair <string,int> >ring=S.getRing(ringname);
+ vector<pair <string,unsigned int> >ring=S.getRing(ringname);
- for(vector<pair<string,int> >::const_iterator i=ring.begin(); i!=ring.end();++i) {
+ for(vector<pair<string, unsigned int> >::const_iterator i=ring.begin(); i!=ring.end();++i) {
tot+=i->second;
entries++;
}
"<a href=?resetring="<<ringname<<"><font color=#ffffff>Reset</a></td>";
ret<<"<td align=right>Resize: ";
- int sizes[]={10,100,500,1000,10000,500000,0};
+ unsigned int sizes[]={10,100,500,1000,10000,500000,0};
for(int i=0;sizes[i];++i) {
if(S.getRingSize(ringname)!=sizes[i])
ret<<"<a href=?resizering="<<ringname<<"&size="<<sizes[i]<<">"<<sizes[i]<<"</a> ";
int printed=0;
- for(vector<pair<string,int> >::const_iterator i=ring.begin();limit && i!=ring.end();++i,--limit) {
+ for(vector<pair<string,unsigned int> >::const_iterator i=ring.begin();limit && i!=ring.end();++i,--limit) {
ret<<"<tr><td>"<<i->first<<"</td><td>"<<i->second<<"</td><td align=right>"<< StatWebServer::makePercentage(i->second*100.0/tot)<<"</td>"<<endl;
printed+=i->second;
}