[accumulators] help/advise required: Need a container to hold accumulator_set

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<double, features<> > *pacc; if (1 == metricType) { pacc = new accumulator_set<double, features <tag::mean> >; } else if(2 == metricType) { pacc = new accumulator_set<double, features <tag::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 <accumulator_set<double, features<> > *> 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

dhruva wrote:
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. <snip>
It doesn't sound like Boost.Accumulators is a good fit for your problem. Accumulators uses static type information to resolve computational dependencies and order calculations. As you don't know what you will be computing until runtime, you can't provide Accumulators with the static type information it requires. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Hello, ----- Original Message ----
From: Eric Niebler <eric@boost-consulting.com> To: boost-users@lists.boost.org Sent: Sunday, 22 February, 2009 11:25:30 AM Subject: Re: [Boost-users] [accumulators] help/advise required: Need a container to hold accumulator_set
dhruva wrote:
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.
It doesn't sound like Boost.Accumulators is a good fit for your problem. Accumulators uses static type information to resolve computational dependencies and order calculations. As you don't know what you will be computing until runtime, you can't provide Accumulators with the static type information it requires.
The approach I proposed by using droppable types and dropping those that are not required. is it expensive? Though it might look not so elegant, would that work? -dhruva Connect with friends all over the world. Get Yahoo! India Messenger at http://in.messenger.yahoo.com/?wm=n/
participants (2)
-
dhruva
-
Eric Niebler