EMANE  1.0.1
statistictable.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - 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 
33 #ifndef EMANESTATISTICTABLE_HEADER_
34 #define EMANESTATISTICTABLE_HEADER_
35 
37 
38 #include <cstdint>
39 #include <mutex>
40 #include <unordered_map>
41 #include <functional>
42 
43 namespace EMANE
44 {
45  class StatisticRegistrar;
46 
59  template<typename Key,
60  typename Compare = std::less<EMANE::Any>,
61  std::size_t sortIndex = 0>
63  {
64  public:
69 
80  void setCell(const Key & key,
81  std::size_t columnIndex,
82  const Any & any);
83 
84 
94  void setRow(const Key & key,
95  const std::vector<Any> & anys);
96 
106  void addRow(const Key & key,
107  const std::vector<Any> & anys = {});
108 
114  void deleteRow(const Key & key);
115 
116  StatisticTableLabels getLabels() const override;
117 
118 
119  StatisticTableValues getValues() const override;
120 
121  void clear() override;
122 
123  private:
124  using InternalTable = std::unordered_map<Key,std::vector<Any>>;
125  InternalTable table_;
126  mutable std::mutex mutex_;
127  const StatisticTableLabels labels_;
128  std::function<void()> clearFunc_;
129 
130  StatisticTable(const StatisticTableLabels & labels);
131 
132  template <typename Function>
133  StatisticTable(const StatisticTableLabels & labels,
134  Function clearFunc);
135 
136  friend StatisticRegistrar;
137  };
138 }
139 
140 #include "emane/statistictable.inl"
141 
142 #endif // EMANESTATISTICTABLE_HEADER_
StatisticTableLabels getLabels() const override
A two dimentional statistic table that holds Any values.
std::vector< std::vector< Any > > StatisticTableValues
A StatisticTablePublisher produces two dimensional tables of Anys.
void setCell(const Key &key, std::size_t columnIndex, const Any &any)
StatisticTableValues getValues() const override
void setRow(const Key &key, const std::vector< Any > &anys)
The StatisticRegistrar allows NEM layers to register statistics and statistic tables. Statistics and Statistic tables are owned by the emulator framework and a borrowed reference is returned to the registering NEM layer.
std::vector< std::string > StatisticTableLabels
void addRow(const Key &key, const std::vector< Any > &anys={})
void deleteRow(const Key &key)
The Any class can contain an instance of one of any type in its support type set. ...
Definition: any.h:49
Definition: agent.h:43