EMANE  1.0.1
statisticregistrar.inl
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
34 
35 template <typename T>
38  const StatisticProperties & properties,
39  const std::string & sDescription)
40 {
41  static_assert(std::is_integral<T>() || std::is_floating_point<T>(),
42  "Type not convertable to numeric Any");
43 
44  auto pStatistic = new StatisticNumeric<T>();
45 
46  registerStatistic(sName,
48  properties,
49  sDescription,
50  pStatistic);
51 
52  return pStatistic;
53 }
54 
55 
56 template <typename T>
59  const StatisticProperties & properties,
60  const std::string & sDescription)
61 {
62  static_assert(is_any_convertable_nonnumeric<T>(),"Type not convertable to non-numeric Any");
63 
64  auto pStatistic = new StatisticNonNumeric<T>{};
65 
66  registerStatistic(sName,
68  properties,
69  sDescription,
70  pStatistic);
71 
72  return pStatistic;
73 }
74 
75 template<typename Key, typename Compare, std::size_t scolumn>
77 EMANE::StatisticRegistrar::registerTable(const std::string & sName,
78  const StatisticTableLabels & labels,
79  const StatisticProperties & properties,
80  const std::string & sDescription)
81 {
82  auto pStatisticTable = new StatisticTable<Key,Compare,scolumn>(labels);
83 
84  if(scolumn >= labels.size())
85  {
86  throw makeException<RegistrarException>("table sort column index out of range for: %s",
87  sName.c_str());
88  }
89 
91  properties,
92  sDescription,
93  pStatisticTable,
94  [](StatisticTablePublisher * p){p->clear();});
95 
96  return pStatisticTable;
97 }
98 template<typename Key, typename Function, typename Compare, std::size_t scolumn>
101  const StatisticTableLabels & labels,
102  Function clearFunc,
103  const std::string & sDescription)
104 {
105  auto pStatisticTable = new StatisticTable<Key,Compare,scolumn>(labels);
106 
107  if(scolumn >= labels.size())
108  {
109  throw makeException<RegistrarException>("table sort column index out of range for: %s",
110  sName.c_str());
111  }
112 
115  sDescription,
116  pStatisticTable,
117  clearFunc);
118 
119  return pStatisticTable;
120 }
A two dimentional statistic table that holds Any values.
A non-numeric statistic can be a std::string or an INETAddr.
A StatisticTablePublisher produces two dimensional tables of Anys.
virtual void registerTablePublisher(const std::string &sName, const StatisticProperties &properties, const std::string &sDescription, StatisticTablePublisher *pStatiticTablePublisher, std::function< void(StatisticTablePublisher *p)> clearFunc)=0
std::vector< std::string > StatisticTableLabels
StatisticTable< Key, Compare, scolumn > * registerTable(const std::string &sName, const StatisticTableLabels &labels, const StatisticProperties &properties=StatisticProperties::NONE, const std::string &sDescription="")
StatisticNumeric< T > * registerNumeric(const std::string &sName, const StatisticProperties &properties=StatisticProperties::NONE, const std::string &sDescription="")
StatisticNonNumeric< T > * registerNonNumeric(const std::string &sName, const StatisticProperties &properties=StatisticProperties::NONE, const std::string &sDescription="")
virtual void registerStatistic(const std::string &sName, Any::Type type, const StatisticProperties &properties, const std::string &sDescription, Statistic *pStatistic)=0
Defines a numeric statistic and its operations.