diff options
author | James H. Hill <hilljh82@gmail.com> | 2009-04-19 07:00:40 +0000 |
---|---|---|
committer | James H. Hill <hilljh82@gmail.com> | 2009-04-19 07:00:40 +0000 |
commit | 2ae8a1846ea167c796d84d3feb20f9c78096a2f9 (patch) | |
tree | ba0bf93b6f32978d774a3edbc0ba62be76c8a160 | |
parent | 57dc3413f0e26ad54addac1d09a2b0afe9b3123b (diff) | |
download | ATCD-2ae8a1846ea167c796d84d3feb20f9c78096a2f9.tar.gz |
Sun Apr 19 06:57:04 UTC 2009 James H. Hill <hillj@isis.vanderbilt.edu>
-rw-r--r-- | ACE/ChangeLog | 19 | ||||
-rw-r--r-- | ACE/ace/UUID.cpp | 286 | ||||
-rw-r--r-- | ACE/ace/UUID.h | 85 | ||||
-rw-r--r-- | ACE/ace/UUID.inl | 112 | ||||
-rw-r--r-- | ACE/tests/UUID_Test.cpp | 81 |
5 files changed, 271 insertions, 312 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 3f3582bd106..6b37318bc70 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,20 @@ +Sun Apr 19 06:57:04 UTC 2009 James H. Hill <hillj@isis.vanderbilt.edu> + + * ace/UUID.h: + * ace/UUID.inl: + * ace/UUID.cpp: + * tests/UUID_Test.cpp: + + Redesigned the internal structure of the UUID so that its key + data members are a contiguous chunk of memory. + + Implemented a hash () method for the UUID. This will enable it + to be used in ACE_Hash_Map_Manager objects. + + Remvoed the default constructor (), copy constructor () and + assignmetnt operator from the UUID_Node object since the UUID + performs such operations. + Fri Apr 17 15:06:32 UTC 2009 Johnny Willemsen <jwillemsen@remedy.nl> * debianbuild/patches/19-gcc43.dpatch: @@ -52,7 +69,7 @@ Thu Apr 16 16:03:32 UTC 2009 Phil Mesnier <mesnier_p@ociweb.com> Tue Apr 14 10:06:19 CDT 2009 Phil Mesnier <mesnier_p@ociweb.com> - * ACE version 5.6.9 released. + * ACE version 5.6.9 released. Tue Apr 14 13:57:16 UTC 2009 Phil Mesnier <mesnier_p@ociweb.com> diff --git a/ACE/ace/UUID.cpp b/ACE/ace/UUID.cpp index d43bbc8139c..ea3feffa338 100644 --- a/ACE/ace/UUID.cpp +++ b/ACE/ace/UUID.cpp @@ -24,185 +24,124 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL namespace ACE_Utils { - UUID_Node::UUID_Node (void) - { - for (int i = 0; i < UUID_Node::NODE_ID_SIZE; ++i) - node_ID_[i] = 0; - } + // NIL version of the UUID + const UUID UUID::NIL_UUID; - UUID_Node::UUID_Node (const UUID_Node & node) + void UUID::init (void) { - for (int i = 0; i < UUID_Node::NODE_ID_SIZE; ++i) - this->node_ID_[i] = node.node_ID_[i]; + // Zero the contents of the UUID. We do not have to worry about the + // node ID in the case since its constructor will zero its contents. + ACE_OS::memset (&this->uuid_, 0, BINARY_SIZE); } - UUID_Node::Node_ID & - UUID_Node::node_ID (void) - { - return node_ID_; - } - - const UUID_Node::Node_ID & - UUID_Node::node_ID (void) const - { - return node_ID_; - } - - void - UUID_Node::node_ID (Node_ID& node_ID) + UUID::UUID (const UUID &right) + : thr_id_ (right.thr_id_), + pid_ (right.pid_) { - for (int i = 0; i < UUID_Node::NODE_ID_SIZE; ++i) - node_ID_[i] = node_ID[i]; + ACE_OS::memcpy (&this->uuid_, &right.uuid_, BINARY_SIZE); } - const UUID_Node & - UUID_Node::operator = (const UUID_Node & rhs) + const UUID & + UUID::operator = (const UUID & rhs) { - // Check for self assignment. if (this == &rhs) return *this; - // Copy the content of the node id. - for (int i = 0; i < UUID_Node::NODE_ID_SIZE; ++i) - this->node_ID_[i] = rhs.node_ID_[i]; - - return *this; - } + // Reset the string version of the UUID a string version + // exist, and the UUID is not equal to the old UUID. + if (0 != this->as_string_.get ()) + { + if (0 == rhs.as_string_.get () || *this != rhs) + this->as_string_.reset (); + } - UUID UUID::NIL_UUID; + // Copy the contents of the UUID. + ACE_OS::memcpy (&this->uuid_, &rhs.uuid_, BINARY_SIZE); - /// Construct a nil UUID. Such a UUID has every one of it's data - /// elements set to zero. - UUID::UUID (void) - : time_low_ (0), - time_mid_ (0), - time_hi_and_version_ (0), - clock_seq_hi_and_reserved_ (0), - clock_seq_low_ (0) - { + /// @todo We should create an UUID_Ex class for UUIDs that + /// contain the thread id and process id. + this->thr_id_ = rhs.thr_id_; + this->pid_ = rhs.pid_; + return *this; } - /// Construct a UUID from a string representation of an UUID. - UUID::UUID (const ACE_CString& uuid_string) - : time_low_ (0), - time_mid_ (0), - time_hi_and_version_ (0), - clock_seq_hi_and_reserved_ (0), - clock_seq_low_ (0) + unsigned long UUID::hash (void) const { - this->from_string_i (uuid_string); + return ACE::hash_pjw (reinterpret_cast <const char *> (&this->uuid_), + UUID::BINARY_SIZE); } - UUID::UUID (const UUID &right) - : time_low_ (right.time_low_), - time_mid_ (right.time_mid_), - time_hi_and_version_ (right.time_hi_and_version_), - clock_seq_hi_and_reserved_ (right.clock_seq_hi_and_reserved_), - clock_seq_low_ (right.clock_seq_low_), - node_ (right.node_) + const ACE_CString * UUID::to_string (void) const { + // Compute the string representation only once. + if (0 != this->as_string_.get ()) + return this->as_string_.get (); - } + // Get a buffer exactly the correct size. Use the nil UUID as a + // gauge. Don't forget the trailing nul. + ACE_Auto_Array_Ptr <char> auto_clean; + size_t UUID_STRING_LENGTH = 36 + thr_id_.length () + pid_.length (); + char *buf = 0; - UUID::~UUID (void) - { + if (36 == UUID_STRING_LENGTH) + { + ACE_NEW_RETURN (buf, + char[UUID_STRING_LENGTH + 1], + 0); - } + // Let the auto array pointer manage the buffer. + auto_clean.reset (buf); - const UUID & - UUID::operator = (const UUID & rhs) - { - if (this != &rhs) - { - // Copy the values of the UUID. - this->time_low_ = rhs.time_low_; - this->time_mid_ = rhs.time_mid_; - this->time_hi_and_version_ = rhs.time_hi_and_version_; - this->clock_seq_hi_and_reserved_ = rhs.clock_seq_hi_and_reserved_; - this->clock_seq_low_ = rhs.clock_seq_low_; - this->node_ = rhs.node_; - - // Delete the string version of the UUID. - this->as_string_.reset (0); + ACE_OS::sprintf (buf, + "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", + this->uuid_.time_low_, + this->uuid_.time_mid_, + this->uuid_.time_hi_and_version_, + this->uuid_.clock_seq_hi_and_reserved_, + this->uuid_.clock_seq_low_, + (this->uuid_.node_.node_ID ()) [0], + (this->uuid_.node_.node_ID ()) [1], + (this->uuid_.node_.node_ID ()) [2], + (this->uuid_.node_.node_ID ()) [3], + (this->uuid_.node_.node_ID ()) [4], + (this->uuid_.node_.node_ID ()) [5]); } - return *this; - } - - const ACE_CString* - UUID::to_string (void) const - { - /// Only compute the string representation once. - if (this->as_string_.get () == 0) + else { - // Get a buffer exactly the correct size. Use the nil UUID as a - // gauge. Don't forget the trailing nul. - ACE_Auto_Array_Ptr <char> auto_clean; - size_t UUID_STRING_LENGTH = 36 + thr_id_.length () + pid_.length (); - char *buf = 0; + UUID_STRING_LENGTH += 2; //for '-' + ACE_NEW_RETURN (buf, + char[UUID_STRING_LENGTH + 1], + 0); - if ((thr_id_.length () != 0) && (pid_.length () != 0)) - { - UUID_STRING_LENGTH += 2; //for '-' - ACE_NEW_RETURN (buf, - char[UUID_STRING_LENGTH + 1], - 0); - - // Let the auto array pointer manage the buffer. - auto_clean.reset (buf); - - ACE_OS::sprintf (buf, - "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x-%s-%s", - this->time_low_, - this->time_mid_, - this->time_hi_and_version_, - this->clock_seq_hi_and_reserved_, - this->clock_seq_low_, - (this->node_.node_ID ()) [0], - (this->node_.node_ID ()) [1], - (this->node_.node_ID ()) [2], - (this->node_.node_ID ()) [3], - (this->node_.node_ID ()) [4], - (this->node_.node_ID ()) [5], - thr_id_.c_str (), - pid_.c_str () - ); - } - else - { - ACE_NEW_RETURN (buf, - char[UUID_STRING_LENGTH + 1], - 0); - - // Let the auto array pointer manage the buffer. - auto_clean.reset (buf); - - ACE_OS::sprintf (buf, - "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", - this->time_low_, - this->time_mid_, - this->time_hi_and_version_, - this->clock_seq_hi_and_reserved_, - this->clock_seq_low_, - (this->node_.node_ID ()) [0], - (this->node_.node_ID ()) [1], - (this->node_.node_ID ()) [2], - (this->node_.node_ID ()) [3], - (this->node_.node_ID ()) [4], - (this->node_.node_ID ()) [5] - ); - } + // Let the auto array pointer manage the buffer. + auto_clean.reset (buf); - // Save the string. - ACE_CString * as_string = 0; + ACE_OS::sprintf (buf, + "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x-%s-%s", + this->uuid_.time_low_, + this->uuid_.time_mid_, + this->uuid_.time_hi_and_version_, + this->uuid_.clock_seq_hi_and_reserved_, + this->uuid_.clock_seq_low_, + (this->uuid_.node_.node_ID ()) [0], + (this->uuid_.node_.node_ID ()) [1], + (this->uuid_.node_.node_ID ()) [2], + (this->uuid_.node_.node_ID ()) [3], + (this->uuid_.node_.node_ID ()) [4], + (this->uuid_.node_.node_ID ()) [5], + thr_id_.c_str (), + pid_.c_str ()); + } - ACE_NEW_RETURN (as_string, - ACE_CString (buf, UUID_STRING_LENGTH), - 0); + // Save the string. + ACE_CString * as_string = 0; - this->as_string_.reset (as_string); - } + ACE_NEW_RETURN (as_string, + ACE_CString (buf, UUID_STRING_LENGTH), + 0); + this->as_string_.reset (as_string); return this->as_string_.get (); } @@ -315,20 +254,18 @@ namespace ACE_Utils } } - this->time_low_ = static_cast<ACE_UINT32> (time_low); - this->time_mid_ = static_cast<ACE_UINT16> (time_mid); - this->time_hi_and_version_ = static_cast<ACE_UINT16> (time_hi_and_version); - this->clock_seq_hi_and_reserved_ = static_cast<u_char> (clock_seq_hi_and_reserved); - this->clock_seq_low_ = static_cast<u_char> (clock_seq_low); - - UUID_Node::Node_ID node_id; - for (int i = 0; i < UUID_Node::NODE_ID_SIZE; ++i) - node_id[i] = static_cast<u_char> (node[i]); + this->uuid_.time_low_ = static_cast<ACE_UINT32> (time_low); + this->uuid_.time_mid_ = static_cast<ACE_UINT16> (time_mid); + this->uuid_.time_hi_and_version_ = static_cast<ACE_UINT16> (time_hi_and_version); + this->uuid_.clock_seq_hi_and_reserved_ = static_cast<u_char> (clock_seq_hi_and_reserved); + this->uuid_.clock_seq_low_ = static_cast<u_char> (clock_seq_low); - this->node_.node_ID (node_id); + for (size_t i = 0; i < UUID_Node::NODE_ID_SIZE; ++ i) + this->uuid_.node_.node_ID ()[i] = static_cast <u_char> (node[i]); // Support varient 10- only - if ((this->clock_seq_hi_and_reserved_ & 0xc0) != 0x80 && (this->clock_seq_hi_and_reserved_ & 0xc0) != 0xc0) + if ((this->uuid_.clock_seq_hi_and_reserved_ & 0xc0) != 0x80 && + (this->uuid_.clock_seq_hi_and_reserved_ & 0xc0) != 0xc0) { ACE_DEBUG ((LM_DEBUG, "ACE_UUID::from_string_i - " @@ -337,7 +274,7 @@ namespace ACE_Utils } /// Support versions 1, 3, and 4 only - ACE_UINT16 V1 = this->time_hi_and_version_; + ACE_UINT16 V1 = this->uuid_.time_hi_and_version_; if ((V1 & 0xF000) != 0x1000 && (V1 & 0xF000) != 0x3000 && @@ -349,7 +286,7 @@ namespace ACE_Utils return; } - if ((this->clock_seq_hi_and_reserved_ & 0xc0) == 0xc0) + if ((this->uuid_.clock_seq_hi_and_reserved_ & 0xc0) == 0xc0) { if (uuid_string.length () == NIL_UUID.to_string ()->length ()) { @@ -391,20 +328,12 @@ namespace ACE_Utils int result = ACE_OS::getmacaddress (&macaddress); UUID_Node::Node_ID node_id; - if (result != -1) + + if (-1 != result) { -// ACE_DEBUG ((LM_DEBUG, -// "%02X-%02X-%02X-%02X-%02X-%02X\n", -// macaddress.node [0], -// macaddress.node [1], -// macaddress.node [2], -// macaddress.node [3], -// macaddress.node [4], -// macaddress.node [5])); - - ACE_OS::memcpy (&node_id, + ACE_OS::memcpy (node_id, macaddress.node, - sizeof (node_id)); + UUID_Node::NODE_ID_SIZE); } else { @@ -421,13 +350,16 @@ namespace ACE_Utils { ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, *lock_); uuid_state_.timestamp = time_last_; - uuid_state_.node.node_ID (node_id); + + ACE_OS::memcpy (uuid_state_.node.node_ID (), + node_id, + UUID_Node::NODE_ID_SIZE); } } void - UUID_Generator::generate_UUID (UUID& uuid,ACE_UINT16 version, - u_char variant) + UUID_Generator:: + generate_UUID (UUID& uuid, ACE_UINT16 version, u_char variant) { UUID_Time timestamp; ACE_UINT16 clock_sequence; @@ -450,7 +382,7 @@ namespace ACE_Utils cseqHAV |= variant; uuid.clock_seq_hi_and_reserved (cseqHAV); - uuid.node (& (uuid_state_.node)); + uuid.node (uuid_state_.node); if (variant == 0xc0) { diff --git a/ACE/ace/UUID.h b/ACE/ace/UUID.h index 06f09a95404..e3066549c11 100644 --- a/ACE/ace/UUID.h +++ b/ACE/ace/UUID.h @@ -29,7 +29,11 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL namespace ACE_Utils { - /// Class to hold a MAC address + /** + * @class UUID_Node + * + * @brief Holds the MAC-address of the UUID. + */ class ACE_Export UUID_Node { public: @@ -39,30 +43,19 @@ namespace ACE_Utils /// Type definition of the node. typedef u_char Node_ID[NODE_ID_SIZE]; - /// Default constructor - UUID_Node (void); + /// Get the node id + Node_ID & node_ID (void); /** - * Copy constructor. - * - * @param[in] node Source node. + * @overload */ - UUID_Node (const UUID_Node & node); - - Node_ID &node_ID (void); - const Node_ID &node_ID (void) const; - - void node_ID (Node_ID&); - - ///// Equality Operations - bool operator == (const UUID_Node& right) const; - bool operator != (const UUID_Node& right) const; + const Node_ID & node_ID (void) const; - ///// Relational Operations - //bool operator < (const UUID_Node& right) const; + /// Test for equality. + bool operator == (const UUID_Node & right) const; - /// Assign the value of an existing node id to this object. - const UUID_Node & operator = (const UUID_Node & rhs); + /// Test for inequality. + bool operator != (const UUID_Node & right) const; private: /// The value of the node id. @@ -70,7 +63,7 @@ namespace ACE_Utils }; /** - * @class ACE_UUID + * @class ACE_UUID * * ACE_UUID represents a Universally Unique IDentifier (UUID) as * described in (the expired) INTERNET-DRAFT specification entitled @@ -90,6 +83,8 @@ namespace ACE_Utils class ACE_Export UUID { public: + /// The size of a binary UUID. + enum { BINARY_SIZE = 16 }; /// Constructor UUID (void); @@ -117,10 +112,10 @@ namespace ACE_Utils u_char clock_seq_low (void) const; void clock_seq_low (u_char); - UUID_Node* node (void); - const UUID_Node* node (void) const; + UUID_Node & node (void); + const UUID_Node & node (void) const; - void node (const UUID_Node*); + void node (const UUID_Node & node); ACE_CString* thr_id (void); void thr_id (char*); @@ -134,22 +129,23 @@ namespace ACE_Utils /// Set the value using a string void from_string (const ACE_CString& uuid_string); - static UUID NIL_UUID; + /// NIL UUID + static const UUID NIL_UUID; /// Equality Operations - bool operator== (const UUID &right) const; - bool operator!= (const UUID &right) const; + bool operator == (const UUID &right) const; + bool operator != (const UUID &right) const; - /// Relational Operations - //bool operator< (const UUID &right) const; - //bool operator> (const UUID &right) const; - //bool operator<= (const UUID &right) const; - //bool operator>= (const UUID &right) const; + /// Compute a hash value for the UUID. + unsigned long hash (void) const; /// Assign an existing UUID to this UUID. const UUID & operator = (const UUID & rhs); private: + /// Initialize the UUID + void init (void); + /** * Helper method to convert from a string UUID. * @@ -158,13 +154,26 @@ namespace ACE_Utils void from_string_i (const ACE_CString& uuid_string); /// Data Members for Class Attributes - ACE_UINT32 time_low_; - ACE_UINT16 time_mid_; - ACE_UINT16 time_hi_and_version_; - u_char clock_seq_hi_and_reserved_; - u_char clock_seq_low_; + struct data + { + /// Time low. + ACE_UINT32 time_low_; + + /// Time mid. + ACE_UINT16 time_mid_; + + /// Time high and version. + ACE_UINT16 time_hi_and_version_; + + /// Clock sequence high and reserved space. + u_char clock_seq_hi_and_reserved_; + + /// Clock sequence low. + u_char clock_seq_low_; - UUID_Node node_; + /// MAC-address within the UUID. + UUID_Node node_; + } uuid_; ACE_CString thr_id_; ACE_CString pid_; diff --git a/ACE/ace/UUID.inl b/ACE/ace/UUID.inl index bbc494197bd..e721ca738ea 100644 --- a/ACE/ace/UUID.inl +++ b/ACE/ace/UUID.inl @@ -6,84 +6,115 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL namespace ACE_Utils { + ACE_INLINE + const UUID_Node::Node_ID & UUID_Node::node_ID (void) const + { + return this->node_ID_; + } + + ACE_INLINE + UUID_Node::Node_ID & UUID_Node::node_ID (void) + { + return this->node_ID_; + } + + ACE_INLINE + UUID::UUID (void) + { + this->init (); + } + + ACE_INLINE + UUID::UUID (const ACE_CString& uuid_string) + { + this->init (); + this->from_string_i (uuid_string); + } + + ACE_INLINE + UUID::~UUID (void) + { + + } - /// Data Members for Class Attributes ACE_INLINE ACE_UINT32 UUID::time_low (void) const { - return this->time_low_; + return this->uuid_.time_low_; } ACE_INLINE void UUID::time_low (ACE_UINT32 timelow) { - this->time_low_ = timelow; + this->uuid_.time_low_ = timelow; } ACE_INLINE ACE_UINT16 UUID::time_mid (void) const { - return this->time_mid_; + return this->uuid_.time_mid_; } ACE_INLINE void UUID::time_mid (ACE_UINT16 time_mid) { - this->time_mid_ = time_mid; + this->uuid_.time_mid_ = time_mid; } ACE_INLINE ACE_UINT16 UUID::time_hi_and_version (void) const { - return this->time_hi_and_version_; + return this->uuid_.time_hi_and_version_; } ACE_INLINE void UUID::time_hi_and_version (ACE_UINT16 time_hi_and_version) { - this->time_hi_and_version_ = time_hi_and_version; + this->uuid_.time_hi_and_version_ = time_hi_and_version; } ACE_INLINE u_char UUID::clock_seq_hi_and_reserved (void) const { - return this->clock_seq_hi_and_reserved_; + return this->uuid_.clock_seq_hi_and_reserved_; } ACE_INLINE void UUID::clock_seq_hi_and_reserved (u_char clock_seq_hi_and_reserved) { - this->clock_seq_hi_and_reserved_ = clock_seq_hi_and_reserved; + this->uuid_.clock_seq_hi_and_reserved_ = clock_seq_hi_and_reserved; } ACE_INLINE u_char UUID::clock_seq_low (void) const { - return this->clock_seq_low_; + return this->uuid_.clock_seq_low_; } ACE_INLINE void UUID::clock_seq_low (u_char clock_seq_low) { - this->clock_seq_low_ = clock_seq_low; + this->uuid_.clock_seq_low_ = clock_seq_low; } - ACE_INLINE const UUID_Node* + ACE_INLINE const UUID_Node & UUID::node (void) const { - return &this->node_; + return this->uuid_.node_; } - ACE_INLINE UUID_Node* + ACE_INLINE UUID_Node & UUID::node (void) { - return &this->node_; + return this->uuid_.node_; } ACE_INLINE void - UUID::node (const UUID_Node* node) + UUID::node (const UUID_Node & node) { - this->node_ = *node; + ACE_OS::memcpy (&this->uuid_.node_, + node.node_ID (), + UUID_Node::NODE_ID_SIZE); } ACE_INLINE ACE_CString* @@ -119,58 +150,15 @@ namespace ACE_Utils ACE_INLINE bool UUID::operator == (const UUID &right) const { - if ((this->time_low_ != right.time_low ()) || - (this->time_mid_ != right.time_mid ()) || - (this->time_hi_and_version_ != right.time_hi_and_version ()) || - (this->clock_seq_hi_and_reserved_ != right.clock_seq_hi_and_reserved ()) || - (this->clock_seq_low_ != right.clock_seq_low ()) || - (this->node_ != *right.node ())) - return false; - - return true; + return 0 == ACE_OS::memcmp (&this->uuid_, &right.uuid_, BINARY_SIZE); } ACE_INLINE bool UUID::operator != (const UUID &right) const { - return !(*this == right); + return 0 != ACE_OS::memcmp (&this->uuid_, &right.uuid_, BINARY_SIZE); } -// ACE_INLINE bool -//UUID::operator < (const UUID &rt) const -// { -// UUID right (rt); -// if ((timeLow_ < right.timeLow ()) || -// (timeMid_ < right.timeMid ()) || -// (timeHiAndVersion_ < right.timeHiAndVersion ()) || -// (clockSeqHiAndReserved_ < right.clockSeqHiAndReserved ()) || -// (clockSeqLow_ < right.clockSeqLow ()) || -// (node_ < right.node ())) -// { -// return true; -// } -// -// return false; -// } -// -// ACE_INLINE bool -// UUID::operator > (const UUID &right) const -// { -// return right < *this; -// } -// -// ACE_INLINE bool -// UUID::operator <= (const UUID &right) const -// { -// return !(*this > right); -// } -// -// ACE_INLINE bool -// UUID::operator >= (const UUID &right) const -// { -// return !(*this < right); -// } -// ACE_INLINE bool UUID_Node::operator == (const UUID_Node& rt) const { diff --git a/ACE/tests/UUID_Test.cpp b/ACE/tests/UUID_Test.cpp index 7f8cf15bc74..43b2fd6f845 100644 --- a/ACE/tests/UUID_Test.cpp +++ b/ACE/tests/UUID_Test.cpp @@ -45,81 +45,94 @@ Tester::test (void) auto_ptr <ACE_Utils::UUID> uuid (ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID ()); ACE_CString uuid_str (uuid->to_string ()->c_str ()); ACE_DEBUG ((LM_DEBUG, - "Generated UUID\n %s\n", + ACE_TEXT ("Generated UUID\n %s\n"), uuid_str.c_str ())); // Construct UUID from string ACE_Utils::UUID new_uuid (uuid_str); + ACE_DEBUG ((LM_DEBUG, - "UUID Constructed from above Generated UUID\n %s\n", + ACE_TEXT ("UUID Constructed from above Generated UUID\n %s\n"), new_uuid.to_string ()->c_str ())); // Construct UUID from string by assigning it ACE_Utils::UUID new_uuid_assign; new_uuid_assign.from_string (new_uuid.to_string ()->c_str ()); ACE_DEBUG ((LM_DEBUG, - "UUID Constructed from above Generated UUID with assign\n %s\n", + ACE_TEXT ("UUID Constructed from above Generated UUID ") + ACE_TEXT ("with assign\n %s\n"), new_uuid_assign.to_string ()->c_str ())); if (new_uuid != new_uuid_assign) - { - ACE_ERROR ((LM_ERROR, "Error: UUIDs are not the same\n")); - retval = -1; - } + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error: UUIDs are not the same\n")), + -1); + + // Check the hash value of the 2 UUIDs + + if (new_uuid.hash () != new_uuid_assign.hash ()) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error: hash value of UUIDs are ") + ACE_TEXT ("not the same")), + -1); // Construct UUID using the copy constructor ACE_Utils::UUID new_uuid_copy (new_uuid); ACE_DEBUG ((LM_DEBUG, - "UUID Constructed from above Generated UUID with copy\n %s\n", + ACE_TEXT ("UUID constructed from above Generated UUID") + ACE_TEXT (" with copy\n %s\n"), new_uuid_copy.to_string ()->c_str ())); if (new_uuid != new_uuid_copy) - { - ACE_ERROR ((LM_ERROR, "Error: UUIDs are not the same with copy\n")); - retval = -1; - } + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error: UUIDs are not the same ") + ACE_TEXT ("with copy\n")), + -1); ACE_Utils::UUID nil_uuid (*ACE_Utils::UUID::NIL_UUID.to_string ()); ACE_DEBUG ((LM_DEBUG, - "UUID Constructed from NIL_UUID with string copy\n %s\n", + ACE_TEXT ("UUID Constructed from NIL_UUID with ") + ACE_TEXT ("string copy\n %s\n"), nil_uuid.to_string ()->c_str ())); if (nil_uuid != ACE_Utils::UUID::NIL_UUID) - { - ACE_ERROR ((LM_ERROR, "Error: UUIDs are not the same with NIL_UUID string copy\n")); - retval = -1; - } + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error: UUIDs are not the same with ") + ACE_TEXT ("NIL_UUID string copy\n")), + -1); - // Construct UUID using the assignment constructor + // Construct UUID using the assignment constructor ACE_Utils::UUID new_uuid_assigment; new_uuid_assigment = new_uuid; ACE_DEBUG ((LM_DEBUG, - "UUID Constructed from above Generated UUID with assignment\n %s\n", + ACE_TEXT ("UUID Constructed from above Generated UUID ") + ACE_TEXT ("with assignment\n %s\n"), new_uuid_assigment.to_string ()->c_str ())); if (new_uuid != new_uuid_assigment) - { - ACE_ERROR ((LM_ERROR, "Error: UUIDs are not the same with assignment\n")); - retval = -1; - } + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error: UUIDs are not the same " + ACE_TEXT ("with assignment\n"))), + -1); // Generate UUID with process and thread ids. - auto_ptr <ACE_Utils::UUID> uuid_with_tp_id (ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (0x0001, - 0xc0)); + auto_ptr <ACE_Utils::UUID> + uuid_with_tp_id (ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (0x0001, 0xc0)); + ACE_DEBUG ((LM_DEBUG, - "UUID with Thread and Process ID\n %s\n", + ACE_TEXT ("UUID with Thread and Process ID\n %s\n"), uuid_with_tp_id->to_string ()->c_str ())); if (new_uuid == *uuid_with_tp_id) - { - ACE_ERROR ((LM_ERROR, "Error: UUIDs are the same\n")); - retval = -1; - } + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error: UUIDs are the same\n")), + -1); // Construct UUID from string ACE_Utils::UUID new_uuid_with_tp_id (uuid_with_tp_id->to_string ()->c_str ()); ACE_DEBUG ((LM_DEBUG, - "UUID with Thread and Process ID reconstructed from above UUID \n %s\n", + ACE_TEXT ("UUID with Thread and Process ID reconstructed ") + ACE_TEXT ("from above UUID \n %s\n"), new_uuid_with_tp_id.to_string ()->c_str ())); return retval; @@ -134,7 +147,7 @@ int run_main(int, ACE_TCHAR* []) if (tester.init () == -1) { ACE_DEBUG((LM_DEBUG, - "UUIDTest: Tester::init failed\n")); + ACE_TEXT ("UUIDTest: Tester::init failed\n"))); return -1; } @@ -142,10 +155,10 @@ int run_main(int, ACE_TCHAR* []) if (result == 0) ACE_DEBUG((LM_DEBUG, - "UUID_Test succeeded\n")); + ACE_TEXT ("UUID_Test succeeded\n"))); else ACE_ERROR((LM_ERROR, - "UUID_Test failed\n")); + ACE_TEXT ("UUID_Test failed\n"))); ACE_END_TEST; |