activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r560993 - in /activemq/activemq-cpp/trunk/src/decaf/src/main: Makefile.am decaf/util/UUID.cpp decaf/util/UUID.h
Date Mon, 30 Jul 2007 14:11:11 GMT
Author: tabish
Date: Mon Jul 30 07:11:09 2007
New Revision: 560993

URL: http://svn.apache.org/viewvc?view=rev&rev=560993
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Implementing the UUID object

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am?view=diff&rev=560993&r1=560992&r2=560993
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am Mon Jul 30 07:11:09 2007
@@ -45,6 +45,7 @@
    decaf/util/concurrent/ThreadPool.cpp \
    decaf/util/Date.cpp \
    decaf/util/Guid.cpp \
+   decaf/util/UUID.cpp \
    decaf/util/StringTokenizer.cpp \
    decaf/util/Random.cpp \
    decaf/util/logging/LoggerHierarchy.cpp \
@@ -115,6 +116,7 @@
    decaf/util/concurrent/ThreadPool.h \
    decaf/util/Date.h \
    decaf/util/Guid.h \
+   decaf/util/UUID.h \
    decaf/util/Iterator.h \
    decaf/util/Collection.h \
    decaf/util/Comparator.h \

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.cpp?view=diff&rev=560993&r1=560992&r2=560993
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.cpp Mon Jul 30 07:11:09
2007
@@ -16,27 +16,104 @@
  */
 
 #include "UUID.h"
+#include <apr_strings.h>
 
 using namespace std;
 using namespace decaf;
 using namespace decaf::util;
+using namespace decaf::lang;
 
 ////////////////////////////////////////////////////////////////////////////////
-Uuid::Uuid() {
+UUID::UUID( long long mostSigBits, long long leastSigBits ) {
+
+    memcpy( &apr_uuid.data[0], &leastSigBits, sizeof( long long ) );
+    memcpy( &apr_uuid.data[sizeof(long long)], &mostSigBits, sizeof(long long ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+UUID::~UUID() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int UUID::compareTo( const UUID& value ) const {
+    return apr_strnatcmp( (const char*)this->apr_uuid.data,
+                          (const char*)value.apr_uuid.data );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool UUID::equals( const UUID& value ) const {
+    return apr_strnatcmp( (const char*)this->apr_uuid.data,
+                          (const char*)value.apr_uuid.data ) == 0 ? true : false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string UUID::toString() const {
+    char buffer[APR_UUID_FORMATTED_LENGTH+1] = {0};
+    apr_uuid_format( &buffer[0], &apr_uuid );
+    return &buffer[0];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long UUID::getLeastSignificantBits() const {
+    long long result = 0;
+    memcpy( &result, &this->apr_uuid.data[0], sizeof(long long) );
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long UUID::getMostSignificantBits() const {
+    long long result = 0;
+    memcpy( &result, &this->apr_uuid.data[sizeof(long long)], sizeof(long long)
);
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long UUID::node() throw ( lang::exceptions::UnsupportedOperationException ) {
+    return 0; //TODO
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Uuid::~Uuid() {
+long long UUID::timestamp() throw ( lang::exceptions::UnsupportedOperationException ) {
+    return 0; //TODO
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Uuid::compareTo( const UUID& value ) {
+long long UUID::clockSequence() throw ( lang::exceptions::UnsupportedOperationException )
{
+    return 0; //TODO
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-long Uuid::getLeastSignificantBits() const {
+long long UUID::variant() throw ( lang::exceptions::UnsupportedOperationException ) {
+    return 0; //TODO
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-long Uuid::getMostSignificantBits() const {
+long long UUID::version() throw ( lang::exceptions::UnsupportedOperationException ) {
+    return 0; //TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+UUID UUID::randomUUID() {
+    return UUID( 0, 0); //TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+UUID UUID::nameUUIDFromBytes( const char* name DECAF_UNUSED ) {
+    return UUID( 0, 0); //TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+UUID UUID::fromString( const std::string& name )
+    throw ( lang::exceptions::IllegalArgumentException ){
+
+    UUID result( 0, 0 );
+
+    if( apr_uuid_parse( &(result.apr_uuid), name.c_str() ) != APR_SUCCESS ) {
+        throw lang::exceptions::IllegalArgumentException(
+            __FILE__, __LINE__,
+            "UUID::fromString - Invalid UUID String: ",
+            name.c_str() );
+    }
+
+    return result;
 }

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.h?view=diff&rev=560993&r1=560992&r2=560993
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/UUID.h Mon Jul 30 07:11:09 2007
@@ -19,9 +19,11 @@
 #define _DECAF_UTIL_UUID_H_
 
 #include <decaf/util/Config.h>
-#include <decaf/util/Comparable.h>
-#include <apr_pools.h>
+#include <decaf/lang/Comparable.h>
+#include <decaf/lang/exceptions/UnsupportedOperationException.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
 #include <apr_uuid.h>
+#include <string>
 
 namespace decaf{
 namespace util{
@@ -29,15 +31,43 @@
     /**
      * A class that represents an immutable universally unique identifier (UUID).
      * A UUID represents a 128-bit value.
+     *
+     * There exist different variants of these global identifiers. The methods of
+     * this class are for manipulating the Leach-Salz variant, although the
+     * constructors allow the creation of any variant of UUID (described below).
+     *
+     * The layout of a variant 2 (Leach-Salz) UUID is as follows: The most
+     * significant long consists of the following unsigned fields:
+     *
+     *  0xFFFFFFFF00000000 time_low
+     *  0x00000000FFFF0000 time_mid
+     *  0x000000000000F000 version
+     *  0x0000000000000FFF time_hi
+     *
+     * The least significant long consists of the following unsigned fields:
+     *
+     *  0xC000000000000000 variant
+     *  0x3FFF000000000000 clock_seq
+     *  0x0000FFFFFFFFFFFF node
+     *
+     * The variant field contains a value which identifies the layout of the UUID.
+     * The bit layout described above is valid only for a UUID with a variant value
+     * of 2, which indicates the Leach-Salz variant.
+     *
+     * The version field holds a value that describes the type of this UUID. There
+     * are four different basic types of UUIDs: time-based, DCE security, name-based,
+     * and randomly generated UUIDs. These types have a version value of 1, 2, 3 and
+     * 4, respectively.
+     *
+     * For more information including algorithms used to create UUIDs, see the
+     * Internet-Draft UUIDs and GUIDs or the standards body definition at
+     * ISO/IEC 11578:1996.
      */
-    class UUID : public Comparable<UUID> {
+    class UUID : public lang::Comparable<UUID> {
     private:
 
-        // APR Pool to allocate from
-        apr_pool_t* pool;
-
         // APR Uuid Type
-        apr_uuid_t* uuid;
+        apr_uuid_t apr_uuid;
 
     public:
 
@@ -63,7 +93,8 @@
          * @param name - a string to be used to construct a UUID.
          * @return type 3 UUID
          */
-        static UUID fromString( const std::string& name );
+        static UUID fromString( const std::string& name )
+            throw ( lang::exceptions::IllegalArgumentException );
 
     public:
 
@@ -74,7 +105,7 @@
          * @param mostSigBits
          * @param leastSigBits
          */
-        UUID( long mostSigBits, long leastSigBits );
+        UUID( long long mostSigBits, long long leastSigBits );
 
         virtual ~UUID();
 
@@ -82,17 +113,110 @@
          * Compare the given UUID to this one
          * @param value - the UUID to compare to
          */
-        virtual int compareTo( const UUID& value );
+        virtual int compareTo( const UUID& value ) const;
+
+        /**
+         * Compares this UUID to the one given, returns true if they are
+         * equal
+         * @param value - the UUID to compare to.
+         * @return true if UUIDs are the same.
+         */
+        virtual bool equals( const UUID& value ) const;
+
+        /**
+         * Returns a String object representing this UUID.  UUID's are formatted
+         * as: 00112233-4455-6677-8899-AABBCCDDEEFF whose length is 36.
+         * @returns formatted string for this UUID
+         */
+        virtual std::string toString() const;
 
         /**
          * @returns the most significant 64 bits of this UUID's 128 bit value.
          */
-        virtual long getLeastSignificantBits() const;
+        virtual long long getLeastSignificantBits() const;
 
         /**
          * @returns the most significant 64 bits of this UUID's 128 bit value.
          */
-        virtual long getMostSignificantBits() const;
+        virtual long long getMostSignificantBits() const;
+
+        /**
+         * The node value associated with this UUID.
+         *
+         * The 48 bit node value is constructed from the node field of this UUID.
+         * This field is intended to hold the IEEE 802 address of the machine that
+         * generated this UUID to guarantee spatial uniqueness.
+         *
+         * The node value is only meaningful in a time-based UUID, which has
+         * version type 1. If this UUID is not a time-based UUID then this method
+         * throws UnsupportedOperationException.
+         * @returns the node value of this UUID
+         * @throws UnsupportedOperationException
+         */
+        virtual long long node()
+            throw ( lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * The timestamp value associated with this UUID.
+         *
+         * The 60 bit timestamp value is constructed from the time_low, time_mid,
+         * and time_hi fields of this UUID. The resulting timestamp is measured in
+         * 100-nanosecond units since midnight, October 15, 1582 UTC.
+         *
+         * The timestamp value is only meaningful in a time-based UUID, which has
+         * version type 1. If this UUID is not a time-based UUID then this method
+         * throws UnsupportedOperationException.
+         * @returns the timestamp associated with a V1 UUID
+         * @throws UnsupportedOperationException
+         */
+        virtual long long timestamp()
+            throw ( lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * The clock sequence value associated with this UUID.
+         *
+         * The 14 bit clock sequence value is constructed from the clock sequence
+         * field of this UUID. The clock sequence field is used to guarantee temporal
+         * uniqueness in a time-based UUID.
+         *
+         * The clockSequence value is only meaningful in a time-based UUID, which
+         * has version type 1. If this UUID is not a time-based UUID then this
+         * method throws UnsupportedOperationException.
+         * @returns the clockSequeunce associated with a V1 UUID
+         * @throws UnsupportedOperationException
+         */
+        virtual long long clockSequence()
+            throw ( lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * The variant number associated with this UUID. The variant number describes
+         * the layout of the UUID. The variant number has the following meaning:
+         *
+         *     * 0 Reserved for NCS backward compatibility
+         *     * 2 The Leach-Salz variant (used by this class)
+         *     * 6 Reserved, Microsoft Corporation backward compatibility
+         *     * 7 Reserved for future definition
+         *
+         * @returns the clockSequeunce associated with a V1 UUID
+         * @throws UnsupportedOperationException
+         */
+        virtual long long variant()
+            throw ( lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * The version number associated with this UUID. The version number describes
+         * how this UUID was generated. The version number has the following meaning:
+         *
+         *     * 1 Time-based UUID
+         *     * 2 DCE security UUID
+         *     * 3 Name-based UUID
+         *     * 4 Randomly generated UUID
+         *
+         * @returns the clockSequeunce associated with a V1 UUID
+         * @throws UnsupportedOperationException
+         */
+        virtual long long version()
+            throw ( lang::exceptions::UnsupportedOperationException );
 
     };
 



Mime
View raw message