Remove dynamic exceptions
[anna.git] / include / anna / statistics / Meter.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_statistics_Meter_hpp
10 #define anna_statistics_Meter_hpp
11
12 #include <anna/timex/Meter.hpp>
13
14 // Standard
15 #include <string>
16
17 // Local
18 #include <anna/statistics/Accumulator.hpp>
19
20
21 namespace anna {
22 namespace xml {
23 class Node;
24 }
25 }
26
27
28 namespace anna {
29
30 namespace statistics {
31
32
33 using namespace anna;
34
35
36 //------------------------------------------------------------------------------
37 //------------------------------------------------------------------ class Meter
38 //------------------------------------------------------------------------------
39 /**
40  * Accumulated data information for statistic sample oriented to processing time.
41  * It manage a single concept, with integer nature sample and unit 'milliseconds'.
42  *
43  * @short Processing time control
44  */
45 class Meter {
46 public:
47
48   /**
49   * Constructor.
50   */
51   Meter(const std::string & name);
52
53   /**
54   * Destructor.
55   */
56   ~Meter();
57
58
59   /**
60   * Sets the time control point for processing measure
61   */
62   void setControlPoint(void) { a_meter.setControlPoint(); }
63
64
65   /**
66   * Reset sample
67   */
68   void reset(void) { a_accumulator.reset(); }
69
70
71   /**
72   * Process new value for the sample: milliseconds time since last control point
73   *
74   * @return Returns processed delay
75   */
76   Millisecond process(void) { a_accumulator.process(a_single_accumulator_concept_id, a_meter.getDelay()); return (a_meter.getDelay()); }
77
78
79   /**
80   * Copy operator
81   *
82   * @param Meter Class instance source of data
83   *
84   * @return Returns copied reference
85   */
86   const Meter & operator = (const Meter & meter);
87
88
89
90   // Gets
91
92 //    /**
93 //    * Gets accumulator information in order to extract statistics indicators
94 //    */
95 //    const Accumulator & getAccumulator(void) const { return (a_accumulator); }
96
97   /**
98   * Gets accumulator value information (statistics indicators)
99   *
100   * @param operation Solicited operation
101   *
102   * @return Value for solicited operation
103   */
104   double getAccumulatorValue(const Operation::Type &operation) const { return (a_accumulator.getValue(a_single_accumulator_concept_id, operation)); }
105
106
107   /**
108   * Class string representation
109   *
110   * @param numberOfDecimals Number of float decimals at representation string. Default is 2.
111   *
112   * @return String with class content
113   */
114   std::string asString(const int & numberOfDecimals = 2) const ;
115
116
117   /**
118   * Class XML representation
119   *
120   * @param numberOfDecimals Number of float decimals at XML representation. Default is 2.
121   *
122   * @return XML with class content
123   */
124   anna::xml::Node* asXML(anna::xml::Node* parent, const int & numberOfDecimals = 2) const ;
125
126
127
128 private:
129
130   timex::Meter a_meter;
131   Accumulator a_accumulator;
132   int a_single_accumulator_concept_id;
133 };
134
135 }
136 }
137
138 #endif