reverted changes in Statistics.[hh][cci] from rev.1829 to anable
[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::Transform
43
44 prefix_ senf::StatisticsBase::Transform::result_type
45 senf::StatisticsBase::Transform::operator()(first_argument_type i)
46     const
47 {
48     return i.second;
49 }
50
51 //-/////////////////////////////////////////////////////////////////////////////////////////////////
52 // senf::StatisticsBase::OutputEntry
53
54 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry()
55     : n(), min(), avg(), max(), dev()
56 {
57     initDir();
58 }
59
60 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(unsigned n_)
61     : n(n_), min(), avg(), max(), dev()
62 {
63     initDir();
64 }
65
66 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(const OutputEntry& other)
67     : n(other.n), min(other.min), avg(other.avg), max(other.max), dev(other.dev)
68 {
69     initDir();
70 }
71
72 prefix_ void senf::StatisticsBase::OutputEntry::initDir()
73 {
74     dir.add("list", console::factory::Command(&OutputEntry::consoleList, this)
75             .doc("List all known connected targets. This list might not be complete.") );
76 }
77
78 prefix_ senf::StatisticsBase::OutputEntry &
79 senf::StatisticsBase::OutputEntry::operator=(const OutputEntry& other)
80 {
81     n = other.n;
82     min = other.min;
83     avg = other.avg;
84     max = other.max;
85     dev = other.dev;
86     return *this;
87 }
88
89 //-/////////////////////////////////////////////////////////////////////////////////////////////////
90 // senf::StatisticsBase
91
92 prefix_ senf::StatisticsBase::StatisticsBase()
93     : min_ (0.0f), avg_ (0.0f), max_ (0.0f), dev_ (0.0f), maxQueueLen_ (0u)
94 {}
95
96 prefix_ senf::StatisticsBase::~StatisticsBase()
97 {}
98
99 prefix_ senf::StatisticsBase::CollectorRange senf::StatisticsBase::collectors()
100 {
101     return senf::make_transform_range(children_, Transform());
102 }
103
104 prefix_ float senf::StatisticsBase::min()
105     const
106 {
107     return min_;
108 }
109
110 prefix_ float senf::StatisticsBase::avg()
111     const
112 {
113     return avg_;
114 }
115
116 prefix_ float senf::StatisticsBase::max()
117     const
118 {
119     return max_;
120 }
121
122 prefix_ float senf::StatisticsBase::dev()
123     const
124 {
125     return dev_;
126 }
127
128 prefix_ unsigned senf::StatisticsBase::rank()
129     const
130 {
131     return 1;
132 }
133
134 prefix_ senf::Statistics & senf::StatisticsBase::base()
135 {
136     return v_base();
137 }
138
139 prefix_ std::string senf::StatisticsBase::path()
140     const
141 {
142     return v_path();
143 }
144
145 prefix_ senf::StatisticsData senf::StatisticsBase::data()
146 {
147     return StatisticsData(min_, avg_, max_, dev_, 0);
148 }
149
150 //-/////////////////////////////////////////////////////////////////////////////////////////////////
151 // senf::Collector
152
153 prefix_ senf::Collector::Collector(StatisticsBase * owner, unsigned rank)
154     : rank_ (rank), i_ (0u), accMin_ (FLT_MAX), accSum_ (0.0f), accSumSq_ (0.0f), accMax_ (-FLT_MAX),
155       owner_ (owner)
156 {}
157
158 prefix_ unsigned senf::Collector::rank()
159     const
160 {
161     return rank_;
162 }
163
164 prefix_ senf::StatisticsBase::OutputProxy<senf::Collector>
165 senf::Collector::output(unsigned n)
166 {
167
168     return StatisticsBase::OutputProxy<Collector>(this, StatisticsBase::output(n));
169 }
170
171 //-/////////////////////////////////////////////////////////////////////////////////////////////////
172 // senf::Statistics
173
174 prefix_ void senf::Statistics::operator()(unsigned n, float min, float avg, float max,
175                                           float dev)
176 {
177     enter(n, min, avg, max, dev);
178 }
179
180 prefix_ void senf::Statistics::operator()(float min, float avg, float max, float dev)
181 {
182     enter(1, min, avg, max, dev);
183 }
184
185 prefix_ void senf::Statistics::operator()(StatisticsData const & data)
186 {
187   enter(1, data.min, data.avg, data.max, data.stddev);
188 }
189
190 prefix_ void senf::Statistics::operator()(float value, float dev)
191 {
192     enter(1, value, value, value, dev);
193 }
194
195
196 prefix_ senf::StatisticsBase::OutputProxy<senf::Statistics>
197 senf::Statistics::output(unsigned n)
198 {
199     return StatisticsBase::OutputProxy<Statistics>(this, StatisticsBase::output(n));
200 }
201
202 //-/////////////////////////////////////////////////////////////////////////////////////////////////
203 #undef prefix_
204
205 \f
206 // Local Variables:
207 // mode: c++
208 // fill-column: 100
209 // comment-column: 40
210 // c-file-style: "senf"
211 // indent-tabs-mode: nil
212 // ispell-local-dictionary: "american"
213 // compile-command: "scons -u test"
214 // End: