- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
typedef CStatisticsCalculator* (*TCalcCreator)(string&, const TUltimateStatDataPtr&);
typedef std::map <CStatisticsCalculator::eCalcKind, boost::tuple<string, TUltimateStatDataPtr, TCalcCreator>> TCalcImplMap;
static TCalcImplMap CalcsMap;
CStatisticsCalculator* CStatisticsCalculator::MakeNewCalculator(CStatisticsCalculator::eCalcKind Kind,
const TUltimateStatDataPtr& Data )
{
if (CalcsMap.empty())
{
CalcsMap[eCalcKind::eExtremeDealPrice] =
boost::make_tuple(string("be.commons.calculators.extreme_prices"), Data,
[](string& Name, const TUltimateStatDataPtr& Data_)->CStatisticsCalculator*
{ return new CExtremePricesCalculator(Name.c_str(), Data_);});
CalcsMap[eCalcKind::eTurnOver] =
boost::make_tuple(string("be.commons.calculators.turnover"), Data,
[](string& Name, const TUltimateStatDataPtr& Data_)->CStatisticsCalculator*
{ return new CTurnOverCalculator(Name.c_str(), Data_);});
};
auto i = CalcsMap.find(Kind);
if (i == CalcsMap.end())
return 0;
auto& tpl = i->second;
return tpl.get<2>()(tpl.get<0>(), tpl.get<1>());
};