2008-05-14 12:14:13 +04:00
|
|
|
/*
|
|
|
|
* ScoreStats.h
|
|
|
|
* met - Minimum Error Training
|
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCORE_STATS_H
|
|
|
|
#define SCORE_STATS_H
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
2008-10-17 01:14:38 +04:00
|
|
|
#include <cstdlib>
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
#include "Util.h"
|
|
|
|
|
|
|
|
#define SCORE_STATS_MIN (numeric_limits<ScoreStatsType>::min())
|
|
|
|
#define ATOSST(str) ((ScoreStatsType) atoi(str))
|
|
|
|
|
2008-06-05 21:03:54 +04:00
|
|
|
#define scorebytes_ (entries_*sizeof(ScoreStatsType))
|
|
|
|
|
2008-05-14 12:14:13 +04:00
|
|
|
class ScoreStats
|
|
|
|
{
|
|
|
|
private:
|
2011-02-24 15:42:19 +03:00
|
|
|
scorestats_t array_;
|
|
|
|
size_t entries_;
|
|
|
|
size_t available_;
|
|
|
|
|
2008-05-14 12:14:13 +04:00
|
|
|
public:
|
2011-02-24 15:42:19 +03:00
|
|
|
ScoreStats();
|
2011-11-12 04:51:27 +04:00
|
|
|
explicit ScoreStats(const size_t size);
|
|
|
|
explicit ScoreStats(std::string &theString);
|
|
|
|
~ScoreStats();
|
|
|
|
|
|
|
|
// We intentionally allow copying.
|
2011-02-24 15:42:19 +03:00
|
|
|
ScoreStats(const ScoreStats &stats);
|
|
|
|
ScoreStats& operator=(const ScoreStats &stats);
|
|
|
|
|
|
|
|
bool isfull() {
|
|
|
|
return (entries_ < available_)?0:1;
|
|
|
|
}
|
|
|
|
void expand();
|
|
|
|
void add(ScoreStatsType v);
|
|
|
|
|
|
|
|
inline void clear() {
|
|
|
|
memset((void*) array_,0,scorebytes_);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ScoreStatsType get(size_t i) {
|
|
|
|
return array_[i];
|
|
|
|
}
|
|
|
|
inline ScoreStatsType get(size_t i)const {
|
|
|
|
return array_[i];
|
|
|
|
}
|
|
|
|
inline scorestats_t getArray() const {
|
|
|
|
return array_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(std::string &theString);
|
|
|
|
|
|
|
|
inline size_t bytes() const {
|
|
|
|
return scorebytes_;
|
|
|
|
}
|
|
|
|
inline size_t size() const {
|
|
|
|
return entries_;
|
|
|
|
}
|
|
|
|
inline size_t available() const {
|
|
|
|
return available_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void savetxt(const std::string &file);
|
|
|
|
void savetxt(ofstream& outFile);
|
|
|
|
void savebin(ofstream& outFile);
|
|
|
|
inline void savetxt() {
|
|
|
|
savetxt("/dev/stdout");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadtxt(const std::string &file);
|
|
|
|
void loadtxt(ifstream& inFile);
|
|
|
|
void loadbin(ifstream& inFile);
|
|
|
|
|
|
|
|
inline void reset() {
|
|
|
|
entries_ = 0;
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:58:23 +04:00
|
|
|
/**
|
|
|
|
* Write the whole object to a stream.
|
|
|
|
*/
|
2011-02-24 15:42:19 +03:00
|
|
|
friend ostream& operator<<(ostream& o, const ScoreStats& e);
|
2008-05-14 12:14:13 +04:00
|
|
|
};
|
|
|
|
|
2011-11-12 02:59:50 +04:00
|
|
|
#endif // SCORE_STATS_H
|