Remove dynamic exceptions
[anna.git] / source / statistics / Meter.cpp
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 //------------------------------------------------------------------------------
10 //--------------------------------------------------------------------- #include
11 //------------------------------------------------------------------------------
12
13
14 // Local
15 #include <anna/statistics/Meter.hpp>
16 #include <anna/statistics/Engine.hpp>
17 #include <anna/xml/xml.hpp>
18
19
20 using namespace anna::statistics;
21
22
23 //******************************************************************************
24 //------------------------------------------------------------------------------
25 //--------------------------------------------------------------- Meter::Meter()
26 //------------------------------------------------------------------------------
27
28 // Default Constructor
29 Meter::Meter(const std::string & name) : a_accumulator(name) {
30   Engine& statsEngine = Engine::instantiate();
31   a_single_accumulator_concept_id = statsEngine.addConcept(name, "ms", true);
32 }
33
34
35 Meter::~Meter() {
36 // LOGMETHOD (TraceMethod tttm ("anna::statistics::Meter", "Destructor", FILE_LOCATION));
37 }
38
39
40
41 //------------------------------------------------------------------------------
42 //------------------------------------------------------------- Meter::operator=
43 //------------------------------------------------------------------------------
44 const Meter & Meter::operator = (const Meter & meter) {
45 // LOGMETHOD (TraceMethod tttm ("anna::statistics::Meter", "operator=", FILE_LOCATION));
46   // Avoid self copy: i.e., Meter a,b; a=&b; a=b; b=a;
47   if(this == &meter) return (*this);
48
49   a_meter = meter.a_meter;
50   a_accumulator = meter.a_accumulator;
51   a_single_accumulator_concept_id = meter.a_single_accumulator_concept_id;
52   return (*this);
53 }
54
55
56
57 //------------------------------------------------------------------------------
58 //------------------------------------------------------------ Meter::asString()
59 //------------------------------------------------------------------------------
60 std::string Meter::asString(const int & numberOfDecimals) const {
61   std::string trace;
62   trace =  "\n=====";
63   trace += "\nMeter";
64   trace += "\n=====\n\n";
65   trace += a_accumulator.asString(numberOfDecimals);
66   return (trace);
67 }
68
69
70 //------------------------------------------------------------------------------
71 //--------------------------------------------------------------- Meter::asXML()
72 //------------------------------------------------------------------------------
73 anna::xml::Node* Meter::asXML(anna::xml::Node* parent, const int & numberOfDecimals) const {
74   anna::xml::Node* result = parent->createChild("anna.statistics.Meter");
75   return (a_accumulator.asXML(result, numberOfDecimals));
76 }