Changed LICENSE. Now referenced to web site and file on project root directory
[anna.git] / include / anna / core / tracing / TraceFunction.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_core_tracing_TraceFunction_hpp
10 #define anna_core_tracing_TraceFunction_hpp
11
12 #include <anna/core/tracing/Logger.hpp>
13
14 namespace anna {
15
16 /**
17   Trazas de funciones.
18
19   Graba una traza en el historico de operaciones por cada entrada y salida de una determinada
20   funcion.
21 */
22 class TraceFunction {
23 public:
24   /**
25     Constructor.
26     @param functionName Nombre de la funcion desde la que se invoca a este constructor.
27     @param fromFile Nombre del fichero desde el que se invoca a este constructor. Normalmente
28     sera el indicado por la macro de compilacion __FILE__.
29     @param fromLine Numero de linea del fichero desde la que se invoca a este constructor.
30     Normalmente sera el indicado por la macro de compilacion __LINE__.
31   */
32   TraceFunction(const char* functionName, const char* fromFile, const int fromLine) :
33     a_functionName(functionName),
34     a_fromFile(fromFile),
35     a_ok(false) {
36     if(Logger::isActive(Logger::Debug) == true) {
37       a_ok = true;
38       Logger::write(Logger::Debug, functionName, "begin", fromFile, fromLine);
39     }
40   }
41
42   /**
43      Destructor.
44   */
45   ~TraceFunction() {
46     if(a_ok == true && Logger::isActive(Logger::Debug) == true)
47       Logger::write(Logger::Debug, a_functionName, "end", a_fromFile, 0);
48   }
49
50 private:
51   const char* a_functionName;
52   const char* a_fromFile;
53   bool a_ok;
54 };
55
56 } //namespace anna
57
58 #endif
59