uuid.h

Engine/source/core/util/uuid.h

More...

Classes:

class

A universally unique identifier.

Namespaces:

namespace
namespace

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _TORQUE_UUID_H_
 25#define _TORQUE_UUID_H_
 26
 27#ifndef _PLATFORM_H_
 28   #include "platform/platform.h"
 29#endif
 30#include "console/engineTypeInfo.h"
 31
 32
 33namespace Torque
 34{
 35   /// A universally unique identifier.
 36   class UUID
 37   {
 38      friend class UUIDEngineExport;
 39      public:
 40      
 41         typedef void Parent;
 42         
 43      protected:
 44
 45         U32   a;
 46         U16   b;
 47         U16   c;
 48         U8    d;
 49         U8    e;
 50         U8    f[ 6 ];
 51         
 52         static UUID smNull;
 53         
 54      public:
 55      
 56         UUID()
 57         {
 58            dMemset( this, 0, sizeof( UUID ) );
 59         }
 60         
 61         ///
 62         bool isNull() const { return ( *this == smNull ); }
 63         
 64         /// Generate a new universally unique identifier (UUID).
 65         void generate();
 66         
 67         /// Convert the given universally unique identifier to a printed string
 68         /// representation.
 69         String toString() const;
 70         
 71         /// Parse a text string generated by UUIDToString back into a
 72         /// universally unique identifier (UUID).
 73         bool fromString( const char* str );
 74
 75         /// Return a hash value for this UUID.
 76         U32 getHash() const;
 77
 78         bool operator==( const UUID& uuid ) const
 79         {
 80            return ( dMemcmp( this, &uuid, sizeof( UUID ) ) == 0 );
 81         }
 82         bool operator!=( const UUID& uuid ) const
 83         {
 84            return !( *this == uuid );
 85         }
 86   };
 87
 88   class UUIDEngineExport
 89   {
 90   public:
 91      static EngineFieldTable::Field getAField();
 92      static EngineFieldTable::Field getBField();
 93      static EngineFieldTable::Field getCField();
 94      static EngineFieldTable::Field getDField();
 95      static EngineFieldTable::Field getEField();
 96      static EngineFieldTable::Field getFField();
 97   };
 98}
 99
100namespace DictHash
101{
102   inline U32 hash( const Torque::UUID& uuid )
103   {
104      return uuid.getHash();
105   }
106}
107
108#endif // !_TORQUE_UUID_H_
109