8842ac57567e6ab9a043dc44a232d6f6301e61c9
[senf.git] / senf / Utils / Statistics.cci
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief Statistics inline non-template implementation */
30
31 //#include "Statistics.ih"
32
33 // Custom includes
34 #include <float.h>
35 #include <senf/Utils/Console/ParsedCommand.hh>
36 #include "Range.hh"
37
38 #define prefix_ inline
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 // senf::StatisticsBase::OutputEntry
43
44 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry()
45     : n(), min(), avg(), max(), dev()
46 {
47     initDir();
48 }
49
50 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(unsigned n_)
51     : n(n_), min(), avg(), max(), dev()
52 {
53     initDir();
54 }
55
56 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(const OutputEntry& other)
57     : n(other.n), min(other.min), avg(other.avg), max(other.max), dev(other.dev)
58 {
59     initDir();
60 }
61
62 prefix_ void senf::StatisticsBase::OutputEntry::initDir()
63 {
64     dir.add("list", console::factory::Command(&OutputEntry::consoleList, this)
65             .doc("List all known connected targets. This list might not be complete.") );
66 }
67
68 prefix_ senf::StatisticsBase::OutputEntry &
69 senf::StatisticsBase::OutputEntry::operator=(const OutputEntry& other)
70 {
71     n = other.n;
72     min = other.min;
73     avg = other.avg;
74     max = other.max;
75     dev = other.dev;
76     return *this;
77 }
78
79 //-/////////////////////////////////////////////////////////////////////////////////////////////////
80 // senf::StatisticsBase
81
82 prefix_ senf::StatisticsBase::StatisticsBase()
83     : min_ (0.0f), avg_ (0.0f), max_ (0.0f), dev_ (0.0f), maxQueueLen_ (0u)
84 {}
85
86 prefix_ senf::StatisticsBase::~StatisticsBase()
87 {}
88
89 prefix_ senf::StatisticsBase::CollectorRange senf::StatisticsBase::collectors()
90 {
91     return senf::make_transform_range(children_,__gnu_cxx::select2nd<Children::value_type>());
92 }
93
94 prefix_ senf::StatisticsBase::const_CollectorRange senf::StatisticsBase::collectors()
95     const
96 {
97     return senf::make_transform_range(children_,__gnu_cxx::select2nd<Children::value_type>());
98 }
99
100 prefix_ float senf::StatisticsBase::min()
101     const
102 {
103     return min_;
104 }
105
106 prefix_ float senf::StatisticsBase::avg()
107     const
108 {
109     return avg_;
110 }
111
112 prefix_ float senf::StatisticsBase::max()
113     const
114 {
115     return max_;
116 }
117
118 prefix_ float senf::StatisticsBase::dev()
119     const
120 {
121     return dev_;
122 }
123
124 prefix_ unsigned senf::StatisticsBase::rank()
125     const
126 {
127     return 1;
128 }
129
130 prefix_ senf::Statistics & senf::StatisticsBase::base()
131 {
132     return v_base();
133 }
134
135 prefix_ senf::Statistics const & senf::StatisticsBase::base()
136     const
137 {
138     return const_cast<StatisticsBase *>(this)->v_base();
139 }
140
141 prefix_ std::string senf::StatisticsBase::path()
142     const
143 {
144     return v_path();
145 }
146
147 prefix_ senf::StatisticsData senf::StatisticsBase::data()
148     const
149 {
150     return StatisticsData(min_, avg_, max_, dev_, 0);
151 }
152
153 //-/////////////////////////////////////////////////////////////////////////////////////////////////
154 // senf::Collector
155
156 prefix_ senf::Collector::Collector(StatisticsBase * owner, unsigned rank)
157     : rank_ (rank), i_ (0u), accMin_ (FLT_MAX), accSum_ (0.0f), accSumSq_ (0.0f), accMax_ (-FLT_MAX),
158       owner_ (owner)
159 {}
160
161 prefix_ unsigned senf::Collector::rank()
162     const
163 {
164     return rank_;
165 }
166
167 prefix_ senf::StatisticsBase::OutputProxy<senf::Collector>
168 senf::Collector::output(unsigned n)
169 {
170
171     return StatisticsBase::OutputProxy<Collector>(this, StatisticsBase::output(n));
172 }
173
174 //-/////////////////////////////////////////////////////////////////////////////////////////////////
175 // senf::Statistics
176
177 prefix_ void senf::Statistics::operator()(unsigned n, float min, float avg, float max,
178                                           float dev)
179 {
180     enter(n, min, avg, max, dev);
181 }
182
183 prefix_ void senf::Statistics::operator()(float min, float avg, float max, float dev)
184 {
185     enter(1, min, avg, max, dev);
186 }
187
188 prefix_ void senf::Statistics::operator()(StatisticsData const & data)
189 {
190   enter(1, data.min, data.avg, data.max, data.stddev);
191 }
192
193 prefix_ void senf::Statistics::operator()(float value, float dev)
194 {
195     enter(1, value, value, value, dev);
196 }
197
198
199 prefix_ senf::StatisticsBase::OutputProxy<senf::Statistics>
200 senf::Statistics::output(unsigned n)
201 {
202     return StatisticsBase::OutputProxy<Statistics>(this, StatisticsBase::output(n));
203 }
204
205 //-/////////////////////////////////////////////////////////////////////////////////////////////////
206 #undef prefix_
207
208 \f
209 // Local Variables:
210 // mode: c++
211 // fill-column: 100
212 // comment-column: 40
213 // c-file-style: "senf"
214 // indent-tabs-mode: nil
215 // ispell-local-dictionary: "american"
216 // compile-command: "scons -u test"
217 // End: