guid: dont pull in std namespace

This commit is contained in:
Danny Robson 2016-03-11 13:02:31 +11:00
parent 809e7b0421
commit e5f2bf32bf

View File

@ -24,9 +24,8 @@
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
guid::guid (uint32_t _data1, guid::guid (uint32_t _data1,
uint16_t _data2, uint16_t _data2,
uint16_t _data3, uint16_t _data3,
@ -35,38 +34,43 @@ guid::guid (uint32_t _data1,
data2 (_data2), data2 (_data2),
data3 (_data3) data3 (_data3)
{ {
copy (_data4, _data4 + elems (data4), data4); std::copy (_data4, _data4 + elems (data4), data4);
} }
//-----------------------------------------------------------------------------
guid::guid (void) guid::guid (void)
{ {
; ;
} }
//-----------------------------------------------------------------------------
guid::guid (const char *str) { guid::guid (const char *str) {
istringstream is (str); std::istringstream is (str);
is >> *this; is >> *this;
} }
//-----------------------------------------------------------------------------
guid::guid (const guid &rhs) { guid::guid (const guid &rhs) {
*this = rhs; *this = rhs;
} }
//-----------------------------------------------------------------------------
guid& guid&
guid::operator= (const guid &rhs) { guid::operator= (const guid &rhs) {
data1 = rhs.data1; data1 = rhs.data1;
data2 = rhs.data2; data2 = rhs.data2;
data3 = rhs.data3; data3 = rhs.data3;
copy (rhs.data4 + 0, rhs.data4 + elems (rhs.data4), data4 + 0); std::copy (rhs.data4 + 0, rhs.data4 + elems (rhs.data4), data4 + 0);
return *this; return *this;
} }
///////////////////////////////////////////////////////////////////////////////
guid guid
guid::from_bytes (const uint8_t *bytes) { guid::from_bytes (const uint8_t *bytes) {
guid g; guid g;
@ -87,11 +91,13 @@ guid::from_bytes (const uint8_t *bytes) {
} }
//-----------------------------------------------------------------------------
guid guid
guid::from_string (const char *bytes) guid::from_string (const char *bytes)
{ return guid (bytes); } { return guid (bytes); }
///////////////////////////////////////////////////////////////////////////////
guid::type guid::type
guid::get_type (void) const { guid::get_type (void) const {
// Top three bits signal the type // Top three bits signal the type
@ -115,6 +121,7 @@ guid::get_type (void) const {
} }
//-----------------------------------------------------------------------------
bool bool
guid::operator< (const guid &rhs) const { guid::operator< (const guid &rhs) const {
if (data1 != rhs.data1) if (data1 != rhs.data1)
@ -134,6 +141,7 @@ guid::operator< (const guid &rhs) const {
} }
//-----------------------------------------------------------------------------
bool bool
guid::operator== (const guid &rhs) const { guid::operator== (const guid &rhs) const {
return data1 == rhs.data1 && return data1 == rhs.data1 &&
@ -149,6 +157,8 @@ guid::operator== (const guid &rhs) const {
data4[7] == rhs.data4[7]; data4[7] == rhs.data4[7];
} }
///////////////////////////////////////////////////////////////////////////////
std::ostream& std::ostream&
operator<< (std::ostream &os, const guid &g) { operator<< (std::ostream &os, const guid &g) {
uint64_t data4_b = static_cast<uint64_t> (g.data4[0]) << 0u | uint64_t data4_b = static_cast<uint64_t> (g.data4[0]) << 0u |
@ -160,17 +170,19 @@ operator<< (std::ostream &os, const guid &g) {
uint16_t data4_a = static_cast<uint16_t> (g.data4[6]) << 0u | uint16_t data4_a = static_cast<uint16_t> (g.data4[6]) << 0u |
static_cast<uint16_t> (g.data4[7]) << 8u; static_cast<uint16_t> (g.data4[7]) << 8u;
os << hex << setfill ('0') << setw (2 * sizeof (g.data1)) << g.data1 << "-" os << std::hex << std::setfill ('0')
<< setw (2 * sizeof (g.data2)) << g.data2 << "-" << std::setw (2 * sizeof (g.data1)) << g.data1 << "-"
<< setw (2 * sizeof (g.data3)) << g.data3 << "-" << std::setw (2 * sizeof (g.data2)) << g.data2 << "-"
<< setw (2 * 2) << data4_a << "-" << std::setw (2 * sizeof (g.data3)) << g.data3 << "-"
<< setw (2 * 6) << data4_b; << std::setw (2 * 2) << data4_a << "-"
<< std::setw (2 * 6) << data4_b;
os << dec; os << std::dec;
return os; return os;
} }
//-----------------------------------------------------------------------------
std::istream& std::istream&
operator>> (std::istream &is, guid &g) { operator>> (std::istream &is, guid &g) {
bool braces = '{' == is.peek (); bool braces = '{' == is.peek ();
@ -181,11 +193,12 @@ operator>> (std::istream &is, guid &g) {
uint16_t data4_a; uint16_t data4_a;
uint64_t data4_b; uint64_t data4_b;
is >> hex >> g.data1 >> dash1 is >> std::hex
>> g.data2 >> dash2 >> g.data1 >> dash1
>> g.data3 >> dash3 >> g.data2 >> dash2
>> data4_a >> dash4a >> g.data3 >> dash3
>> data4_b; >> data4_a >> dash4a
>> data4_b;
uint64_t data4 = data4_b | static_cast<uint64_t> (data4_a) << 48u; uint64_t data4 = data4_b | static_cast<uint64_t> (data4_a) << 48u;
g.data4[0] = data4 & 0xFF; data4 >>= 8u; g.data4[0] = data4 & 0xFF; data4 >>= 8u;
@ -202,4 +215,3 @@ operator>> (std::istream &is, guid &g) {
return is; return is;
} }