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 //
13 #include <anna/core/util/Microsecond.hpp>
14 #include <anna/core/util/Millisecond.hpp>
15 #include <anna/core/util/Second.hpp>
16 #include <anna/core/functions.hpp>
21 #define implement_operator(op) \
22 bool Microsecond::operator op (const Millisecond& other) const \
25 return a_value op (((type_t) other.a_value) * 1000);\
27 bool Microsecond::operator op (const Second& other) const\
30 return a_value op ((type_t) other.a_value * 1000000);\
33 Microsecond::Microsecond(const Millisecond& other) : a_value(other.a_value) { a_value *= (type_t)1000; }
35 Microsecond::Microsecond(const Second& other) : a_value(other.a_value) { a_value *= (type_t)1000000; }
37 Microsecond& Microsecond::operator= (const Millisecond & other)
39 a_value = other.a_value;
40 a_value *= (type_t)1000;
44 Microsecond& Microsecond::operator= (const Second & other)
46 a_value = other.a_value;
47 a_value *= (type_t)1000000;
51 implement_operator( ==)
52 implement_operator( !=)
53 implement_operator( >)
54 implement_operator( <)
58 Microsecond Microsecond::getTime()
61 gettimeofday(&tv, NULL);
62 Microsecond result(Second(tv.tv_sec));
63 result.a_value += tv.tv_usec;
67 string Microsecond::asString() const
69 string result(functions::asString(a_value));
70 return result += " us";
74 Microsecond Microsecond::fromString(const std::string& value)
76 if(value.find(" us") == string::npos) {
77 string msg("String: ");
79 msg += " | Invalid expression for Microsecond";
80 throw RuntimeException(msg, ANNA_FILE_LOCATION);
83 return Microsecond(atoll(value.c_str()));