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 wpl
00033 {
00034
00035 namespace wifi
00036 {
00037
00038 inline
00039 timestamp::timestamp()
00040 {
00041 #ifndef NDEBUG
00042 std::fill(digits_.begin(), digits_.end(), 0);
00043 #endif // ! NDEBUG
00044 }
00045
00046 inline
00047 timestamp::timestamp(uint32_t hi, uint32_t lo)
00048 {
00049 digits_[0] = (lo & 0x000000FF) >> 0;
00050 digits_[1] = (lo & 0x0000FF00) >> 8;
00051 digits_[2] = (lo & 0x00FF0000) >> 16;
00052 digits_[3] = (lo & 0xFF000000) >> 24;
00053 digits_[4] = (hi & 0x000000FF) >> 0;
00054 digits_[5] = (hi & 0x0000FF00) >> 8;
00055 digits_[6] = (hi & 0x00FF0000) >> 16;
00056 digits_[7] = (hi & 0xFF000000) >> 24;
00057 }
00058
00059 inline
00060 bool
00061 timestamp::operator == (const timestamp& rhs) const
00062 {
00063 return digits_ == rhs.digits_;
00064 }
00065
00066 inline
00067 bool
00068 timestamp::operator != (const timestamp& rhs) const
00069 {
00070 return not (*this == rhs);
00071 }
00072
00073 inline
00074 bool
00075 timestamp::operator < (const timestamp& rhs) const
00076 {
00077 return
00078 std::lexicographical_compare(digits_.rbegin(), digits_.rend(),
00079 rhs.digits_.rbegin(), rhs.digits_.rend());
00080 }
00081
00082 inline
00083 std::ostream&
00084 timestamp::print(std::ostream& os) const
00085 {
00086
00087
00088
00089
00090 digits_t tmp;
00091 std::stack<char> out;
00092
00093 std::copy(digits_.begin(), digits_.end(), tmp.rbegin());
00094 while (true)
00095 {
00096 digits_t::iterator i = tmp.begin();
00097 unsigned carry = 0;
00098
00099
00100 while (i != tmp.end() and not *i)
00101 ++i;
00102
00103
00104 if (i == tmp.end())
00105 break;
00106
00107
00108 while (i != tmp.end())
00109 {
00110 carry = (carry << (sizeof (*i) * 8)) + *i;
00111 *i = carry / 10;
00112 carry = carry % 10;
00113 ++i;
00114 }
00115 out.push(carry + '0');
00116 }
00117
00118 if (out.empty())
00119 return os << "0";
00120 while (not out.empty())
00121 {
00122 os << out.top();
00123 out.pop();
00124 }
00125 return os;
00126 }
00127
00128 inline
00129 size_t
00130 timestamp::hash() const
00131 {
00132 return *reinterpret_cast<const size_t*> (digits_.data());
00133 }
00134
00135 inline
00136 std::ostream&
00137 operator << (std::ostream& os, const timestamp& ts)
00138 {
00139 return ts.print(os);
00140 }
00141
00142 }
00143
00144 }
00145
00146 WP_HASH_NAMESPACE_BEGIN
00147
00148 inline
00149 size_t
00150 hash<wpl::wifi::timestamp>::operator () (const wpl::wifi::timestamp& t) const
00151 {
00152 return t.hash();
00153 }
00154
00155 WP_HASH_NAMESPACE_END
00156
00157 #endif // ! WIFI_TIMESTAMP_HXX_