Hello,
I am writing a wrapper class which gets data over time and has to compute a variety of statistics using boost::accumulators. The accumulator cannot be a variable on the stack (function local variable) as it will go out of scope after the function invocation. I will have to make it a member variable of a class. I will not know the type of calculations to requested at compile time. I therefore need a generic accumulator type as member and add the specific type at runtime.
In short, I need a container to hold accumulator_set objects. Different type of accumulator_set objects in the container will perform different calculations. The type of calculation I want to perform will be based on input at runtime.
pseudo code:
#define MEAN 1
#define MAX 2
class calc {
public:
setmetric(int metricType) {
accumulator_set > *pacc;
if (1 == metricType) {
pacc = new accumulator_settag::mean >;
} else if(2 == metricType) {
pacc = new accumulator_settag::max >;
}
m_Vacc.push_back(pacc);
}
compute(double input) {
// I will iterate over the vector, get the accumulator_set objects
// acc_obj(input) followed by extract
}
private:
std::vector > *> m_Vacc;
};
If features could be added at runtime, I probably could have solved this problem. Other approach is to have an accumulator_set with all supported features (supported by my application) as dropable. Drop all the unnecessary features based on user input. By adding all supported types, I will get a complete accumulator_set class at compile time and having a container to hold it is straight forward.
Any help or advise is really appreciated. I may have raised a lot of basic questions but I am a boost newbie and taking a plunge.
-dhruva
Cricket on your mind? Visit the ultimate cricket website. Enter http://beta.cricket.yahoo.com