1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
9 #ifndef anna_timex_Meter_hpp
10 #define anna_timex_Meter_hpp
12 #include <anna/core/functions.hpp>
19 Facilita la medicion de los tiempos empleados las distintas partes de nuestra aplicacion.
21 Permite calcular tiempos acumulados como tiempos individuales. Por ejemplo:
25 #include <anna.timex.Meter.h>
31 Millisecond gooTime = meter.getDelay ();
34 Millisecond goohooTime = meter.setControlPoint ();
37 Millisecond jooTime = meter.getDelay ();
45 Inicializa la cuenta de temporizacion.
47 Meter() { a_timestamp = functions::millisecond(); a_topReference = 0; }
51 * Copia la cuenta de utilizacion de la instancia recibida como parametro.
52 * \param other Instancia de la copiar los parametros para calcular el tiempo transcurrido.
54 Meter(const Meter& other) : a_timestamp(other.a_timestamp) { a_topReference = 0; ;}
57 * Inicializa la cuenta de temporizacion. Este metodo es invocado automaticamente desde el contructor la clase
58 * por lo que si vamos usar esta instancia para tomar un unica medida no es necesario invocarlo.
59 * \warning Elimina el punto de referencia temporal que puediera haberse establecido con #setTopReference.
60 * \return El número de milisegundos transcurridos desde la última vez que inicializamos la cuenta de temporizacion.
62 Millisecond setControlPoint() throw() {
63 Millisecond now = functions::millisecond();
64 Millisecond result = (now > a_timestamp) ? (now - a_timestamp) : (Millisecond)0;
71 * Se da la posiblidad de establecer un punto de referencia temporal de forma
72 * que cuando se invoque a Meter::getDelay, el calculo de la diferencia de tiempo
73 * no se hará entre la marca de tiempo y el tiempo actual, sino la marca de
74 * tiempo y ésta marca de referencia.
76 * Esta funcionalidad ha sido requerida para medir el tiempo de ejecución "real"
77 * de tareas que se ejecutan dentro de un thread. Ya que puede pasar un tiempo
78 * indeterminado desde que se termina la tarea MT (momento en el que se establecerá
79 * la marca de tiempo) y el núcleo y demás partes pueden tener conocimiento de que
80 * esa tarea ha sido finalidad.
83 void setTopReference(const Millisecond & topReference) throw() { a_topReference = topReference; }
86 * Elimina el punto de referencia temporal.
88 void clearTopReference() throw() { a_topReference = 0; }
91 * Devuelve el número de milisegundos transcurridos desde la última vez que inicializamos la cuenta de temporización.
92 * Si se ha establecido un punto de referencia mediante #setTopReference, devolverá la diferencia entre el
93 * el punto de control y la referencia, en otro caso, devolverá la diferencia entre el punto de control y el
95 * \return El número de milisegundos transcurridos desde la última vez que inicializamos la cuenta de temporizacion.
96 * \warning Si detecta algun fallo devolvera 0.
98 Millisecond getDelay() const throw() {
99 Millisecond now = (a_topReference == 0) ? functions::millisecond() : a_topReference;
100 return (now > a_timestamp) ? (now - a_timestamp) : (Millisecond)0;
105 * \param timestamp Milisegundo en el que inicilizar la cuenta de esta instancia.
106 * \warning Elimina el punto de referencia temporal que puediera haberse establecido con #setTopReference.
107 * \see anna::functions::millisecond.
109 Meter& operator= (const Millisecond & timestamp) throw() { a_timestamp = timestamp; a_topReference = 0; return *this; }
113 * \param other Instancia de la que copiar.
115 Meter& operator= (const Meter& other) throw() { a_timestamp = other.a_timestamp; a_topReference = other.a_topReference; return *this; }
118 Millisecond a_topReference;
119 Millisecond a_timestamp;