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_core_util_Microsecond_hpp
10 #define anna_core_util_Microsecond_hpp
14 #include <anna/core/util/defines.hpp>
15 #include <anna/core/RuntimeException.hpp>
29 Microsecond() : a_value(0) {;}
33 * \param value Valor inicial de esta instancia.
35 explicit Microsecond(const type_t value) : a_value(value) {;}
39 * \param other Instancia de la que copiar.
41 Microsecond(const Microsecond& other) : a_value(other.a_value) {;}
45 * \param other Instancia de la que copiar.
47 Microsecond(const Millisecond& other);
51 * \param other Instancia de la que copiar.
53 Microsecond(const Second& other);
56 * Conversor a numérico.
57 * \return El valor asociado a esta instancia.
59 operator type_t () const throw() { return a_value; }
64 type_t& refValue() throw() { return a_value; }
66 Microsecond& operator= (const Microsecond& other) throw() { a_value = other.a_value; return *this; }
68 Microsecond& operator= (const Millisecond& other) throw();
70 Microsecond& operator= (const Second& other) throw();
72 bool operator== (const Microsecond& other) const throw() { return a_value == other.a_value; }
74 bool operator== (const Millisecond& other) const throw();
76 bool operator== (const Second& other) const throw();
78 bool operator!= (const Microsecond& other) const throw() { return a_value != other.a_value; }
80 bool operator!= (const Millisecond& other) const throw();
82 bool operator!= (const Second& other) const throw();
84 bool operator> (const Microsecond& other) const throw() { return a_value > other.a_value; }
86 bool operator> (const Millisecond& other) const throw();
88 bool operator> (const Second& other) const throw();
90 bool operator< (const Microsecond& other) const throw() { return a_value < other.a_value; }
92 bool operator< (const Millisecond& other) const throw();
94 bool operator< (const Second& other) const throw();
96 bool operator>= (const Microsecond& other) const throw() { return a_value >= other.a_value; }
98 bool operator>= (const Millisecond& other) const throw() { return (operator==(other) == true) ? true : operator>(other); }
100 bool operator>= (const Second& other) const throw() { return (operator==(other) == true) ? true : operator>(other); }
102 bool operator<= (const Microsecond& other) const throw() { return a_value <= other.a_value; }
104 bool operator<= (const Millisecond& other) const throw() { return (operator==(other) == true) ? true : operator<(other); }
106 bool operator<= (const Second& other) const throw() { return (operator==(other) == true) ? true : operator<(other); }
108 Microsecond& operator+= (const Microsecond& other) throw() { a_value += other.a_value; return *this; }
109 Microsecond& operator*= (const int& value) throw() { a_value *= value; return *this; }
112 * Devuelve el valor asociado a esta instancia.
113 * \return el valor asociado a esta instancia.
115 type_t getValue() const throw() { return a_value; }
118 * Devuelve la hora actual de sistema expresada en microsegundos transcurridos desde el 1 de Enero de 1970
119 * \return la hora actual de sistema expresada en microsegundos transcurridos desde el 1 de Enero de 1970
121 static Microsecond getTime() throw();
124 * Devuelve una cadena con el valor de esta instancia y las unidades "us".
125 * \return una cadena con el valor de esta instancia y las unidades "us".
127 std::string asString() const throw();
130 * Obtiene los microsegundos del valor contenido en la cadena recibida como parámetro.
131 * \param value Cadena que contiene los microsegundos habrá sido obtenida con #asString.
132 * \return los microsegundos del valor contenido en la cadena recibida como parámetro.
134 static Microsecond fromString(const std::string& value) throw(RuntimeException);
139 friend class Millisecond;
142 friend class Microsecond operator - (const Microsecond& left, const Microsecond& right) throw();
143 friend class Microsecond operator + (const Microsecond& left, const Microsecond& right) throw();
144 friend class Microsecond operator / (const Microsecond& left, const Microsecond& right) throw();
145 friend class Microsecond operator / (const Microsecond& left, const int right) throw();
146 friend class Microsecond operator / (const Microsecond& left, const unsigned int right) throw();
149 inline Microsecond operator - (const Microsecond& left, const Microsecond& right)
151 return Microsecond(left.a_value - right.a_value);
154 inline Microsecond operator + (const Microsecond& left, const Microsecond& right)
156 return Microsecond(left.a_value + right.a_value);
159 inline Microsecond operator / (const Microsecond& left, const Microsecond& right)
161 return Microsecond(left.a_value / right.a_value);
164 inline Microsecond operator / (const Microsecond& left, const int right)
166 return Microsecond(left.a_value / right);
169 inline Microsecond operator / (const Microsecond& left, const unsigned int right)
171 return Microsecond(left.a_value / right);