00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_TIMESTAMP_HXX_
00023 # define WIFI_TIMESTAMP_HXX_
00024
00025 # include <algorithm>
00026 # include <stack>
00027
00028 # include <boost/array.hpp>
00029
00030 # include "timestamp.hh"
00031
00032 namespace wifi
00033 {
00034
00035 inline
00036 timestamp::timestamp()
00037 {
00038 #ifndef NDEBUG
00039 std::fill(digits_.begin(), digits_.end(), 0);
00040 #endif // ! NDEBUG
00041 }
00042
00043 inline
00044 timestamp::timestamp(uint32_t hi, uint32_t lo)
00045 {
00046 digits_[0] = (lo & 0x000000FF) >> 0;
00047 digits_[1] = (lo & 0x0000FF00) >> 8;
00048 digits_[2] = (lo & 0x00FF0000) >> 16;
00049 digits_[3] = (lo & 0xFF000000) >> 24;
00050 digits_[4] = (hi & 0x000000FF) >> 0;
00051 digits_[5] = (hi & 0x0000FF00) >> 8;
00052 digits_[6] = (hi & 0x00FF0000) >> 16;
00053 digits_[7] = (hi & 0xFF000000) >> 24;
00054 }
00055
00056 inline
00057 bool
00058 timestamp::operator == (const timestamp& rhs) const
00059 {
00060 return digits_ == rhs.digits_;
00061 }
00062
00063 inline
00064 bool
00065 timestamp::operator != (const timestamp& rhs) const
00066 {
00067 return not (*this == rhs);
00068 }
00069
00070 inline
00071 bool
00072 timestamp::operator < (const timestamp& rhs) const
00073 {
00074 return
00075 std::lexicographical_compare(digits_.rbegin(), digits_.rend(),
00076 rhs.digits_.rbegin(), rhs.digits_.rend());
00077 }
00078
00079 inline
00080 std::ostream&
00081 timestamp::print(std::ostream& os) const
00082 {
00083
00084
00085
00086
00087 digits_t tmp;
00088 std::stack<char> out;
00089
00090 std::copy(digits_.begin(), digits_.end(), tmp.rbegin());
00091 while (true)
00092 {
00093 digits_t::iterator i = tmp.begin();
00094 unsigned carry = 0;
00095
00096
00097 while (i != tmp.end() and not *i)
00098 ++i;
00099
00100
00101 if (i == tmp.end())
00102 break;
00103
00104
00105 while (i != tmp.end())
00106 {
00107 carry = (carry << (sizeof (*i) * 8)) + *i;
00108 *i = carry / 10;
00109 carry = carry % 10;
00110 ++i;
00111 }
00112 out.push(carry + '0');
00113 }
00114
00115 if (out.empty())
00116 return os << "0";
00117 while (not out.empty())
00118 {
00119 os << out.top();
00120 out.pop();
00121 }
00122 return os;
00123 }
00124
00125 inline
00126 std::ostream&
00127 operator << (std::ostream& os, const timestamp& ts)
00128 {
00129 return ts.print(os);
00130 }
00131
00132 }
00133
00134 #endif // ! WIFI_TIMESTAMP_HXX_