39 const std::string & sName,
42 const std::string & sDescription,
45 if(std::find_if_not(sName.begin(),sName.end(),[](
int ch){
return isalnum(ch) || ch ==
'.';}) != sName.end())
47 throw makeException<RegistrarException>(
"Invalid charater in the statistic name: %s",
56 std::unique_ptr<Statistic> pStat{pStatistic};
58 auto iter = buildIdStatisticStore_.find(buildId);
60 if(iter != buildIdStatisticStore_.end())
62 auto & store = iter->second;
64 if(!store.insert(std::make_pair(sName,std::make_pair(std::move(pStat),std::move(info)))).second)
66 throw makeException<RegistrarException>(
"Statistic already registered: %s",
73 store.insert(std::make_pair(sName,std::make_pair(std::move(pStat),std::move(info))));
74 buildIdStatisticStore_.insert(std::make_pair(buildId,std::move(store)));
79 const std::string & sName,
81 const std::string & sDescription,
85 if(std::find_if_not(sName.begin(),sName.end(),[](
int ch){
return isalnum(ch) || ch ==
'.';}) != sName.end())
87 throw makeException<RegistrarException>(
"Invalid charater in the statistic table name: %s",
93 std::unique_ptr<StatisticTablePublisher> pTable{pStatisticTablePublisher};
95 auto iter = buildIdTableStore_.find(buildId);
97 if(iter != buildIdTableStore_.end())
99 auto & store = iter->second;
101 if(!store.insert(std::make_pair(sName,std::make_tuple(std::move(pTable),std::move(info),std::move(clearFunc)))).second)
103 throw makeException<RegistrarException>(
"Statistic table already registered: %s",
110 store.insert(std::make_pair(sName,std::make_tuple(std::move(pTable),std::move(info),std::move(clearFunc))));
111 buildIdTableStore_.insert(std::make_pair(buildId,std::move(store)));
117 std::map<std::string,EMANE::Any>
119 const std::vector<std::string> & names)
const 121 std::map<std::string,Any> values;
123 auto iter = buildIdStatisticStore_.find(buildId);
125 if(iter != buildIdStatisticStore_.end())
127 auto & store = iter->second;
131 std::transform(store.begin(),
133 std::inserter(values,values.end()),
134 [](
const StatisticStore::value_type & p)
136 return std::make_pair(p.first,p.second.first->asAny());
142 for_each(names.begin(),
144 [&store,&values](
const std::string & s)
146 auto iter = store.find(s);
148 if(iter != store.end())
150 values.insert(std::make_pair(s,iter->second.first->asAny()));
154 throw makeException<RegistrarException>(
"Unknown statistic name: %s",
167 const std::vector<std::string> & names)
const 169 auto iter = buildIdStatisticStore_.find(buildId);
171 if(iter != buildIdStatisticStore_.end())
173 auto & store = iter->second;
177 std::for_each(store.begin(),
179 [](
const StatisticStore::value_type & p)
181 if(p.second.second.isClearable())
183 p.second.first->clear();
190 std::vector<Statistic *> statsToClear;
195 for_each(names.begin(),
197 [&store,&statsToClear](
const std::string & s)
199 auto iter = store.find(s);
201 if(iter != store.end())
203 if(iter->second.second.isClearable())
205 statsToClear.push_back(iter->second.first.get());
209 throw makeException<RegistrarException>(
"Statistic not clearable: %s",
215 throw makeException<RegistrarException>(
"Unknown statistic name: %s",
220 for_each(statsToClear.begin(),
223 std::placeholders::_1));
228 std::map<std::string,std::pair<EMANE::StatisticTableLabels,EMANE::StatisticTableValues>>
230 const std::vector<std::string> & names)
const 232 std::map<std::string,std::pair<StatisticTableLabels,StatisticTableValues>> values;
234 auto iter = buildIdTableStore_.find(buildId);
236 if(iter != buildIdTableStore_.end())
238 auto & store = iter->second;
242 std::transform(store.begin(),
244 std::inserter(values,values.end()),
245 [](
const TableStore::value_type & p)
247 auto pTable = std::get<0>(p.second).
get();
248 return std::make_pair(p.first,
249 std::make_pair(pTable->getLabels(),
250 pTable->getValues()));
256 for_each(names.begin(),
258 [&store,&values](
const std::string & s)
260 auto iter = store.find(s);
262 if(iter != store.end())
264 auto pTable = std::get<0>(iter->second).
get();
266 values.insert(std::make_pair(s,
267 std::make_pair(pTable->getLabels(),
268 pTable->getValues())));
272 throw makeException<RegistrarException>(
"Unknown statistic table name: %s",
288 auto iter = buildIdStatisticStore_.find(buildId);
290 if(iter != buildIdStatisticStore_.end())
292 std::transform(iter->second.begin(),
294 std::back_inserter(manifest),
295 std::bind(&StatisticStore::value_type::second_type::second,
296 std::bind(&StatisticStore::value_type::second,
297 std::placeholders::_1)));
308 auto iter = buildIdTableStore_.find(buildId);
310 if(iter != buildIdTableStore_.end())
312 std::transform(iter->second.begin(),
314 std::back_inserter(manifest),
315 std::bind([&manifest](
const TableStore::value_type::second_type & t)
316 {
return std::get<1>(t);},
317 std::bind(&TableStore::value_type::second,
318 std::placeholders::_1)));
326 const std::vector<std::string> & names)
const 328 auto iter = buildIdTableStore_.find(buildId);
330 if(iter != buildIdTableStore_.end())
335 std::vector<std::function<void()>> tablesToClear;
337 auto & store = iter->second;
341 std::for_each(store.begin(),
343 [&tablesToClear](
const TableStore::value_type & p)
345 if(std::get<1>(p.second).isClearable())
347 tablesToClear.push_back(std::bind(std::get<2>(p.second),
348 std::get<0>(p.second).get()));
355 for_each(names.begin(),
357 [&store,&tablesToClear](
const std::string & s)
359 auto iter = store.find(s);
361 if(iter != store.end())
363 if(std::get<1>(iter->second).isClearable())
365 tablesToClear.push_back(std::bind(std::get<2>(iter->second),
366 std::get<0>(iter->second).get()));
370 throw makeException<RegistrarException>(
"Table not clearable: %s",
376 throw makeException<RegistrarException>(
"Unknown table name: %s",
382 for_each(tablesToClear.begin(),
384 [](
const std::function<void()> & f)
A StatisticTablePublisher produces two dimensional tables of Anys.
void clearStatistic(BuildId, const std::vector< std::string > &names) const
std::string manifest(BuildId buildId, const std::string &sName)
std::vector< StatisticInfo > StatisticManifest
std::vector< StatisticTableInfo > StatisticTableManifest
std::map< std::string, std::pair< StatisticTableLabels, StatisticTableValues > > queryTable(BuildId, const std::vector< std::string > &names) const
StatisticManifest getStatisticManifest(BuildId id) const
Holds name, type, property and description of a Statistic.
void registerStatistic(BuildId buildId, const std::string &sName, Any::Type type, const StatisticProperties &properties, const std::string &sDescription, Statistic *pStatistic)
StatisticTableManifest getTableManifest(BuildId id) const
The Statistic interface is the base class of all statistics. It provided methods to access and clear ...
Holds name, property and description of a StatisticTable.
void registerTable(BuildId buildId, const std::string &sName, const StatisticProperties &properties, const std::string &sDescription, StatisticTablePublisher *pStatisticTablePublisher, std::function< void(StatisticTablePublisher *)> clearFunc)
std::map< std::string, EMANE::Any > queryStatistic(BuildId, const std::vector< std::string > &names) const
void clearTable(BuildId, const std::vector< std::string > &names) const