home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / openh323.tar.gz / openh323.tar / openh323 / include / guid.h < prev    next >
C/C++ Source or Header  |  2002-09-15  |  4KB  |  143 lines

  1. /*
  2.  * guid.h
  3.  *
  4.  * Globally Unique Identifier
  5.  *
  6.  * Open H323 Library
  7.  *
  8.  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
  9.  *
  10.  * The contents of this file are subject to the Mozilla Public License
  11.  * Version 1.0 (the "License"); you may not use this file except in
  12.  * compliance with the License. You may obtain a copy of the License at
  13.  * http://www.mozilla.org/MPL/
  14.  *
  15.  * Software distributed under the License is distributed on an "AS IS"
  16.  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  17.  * the License for the specific language governing rights and limitations
  18.  * under the License.
  19.  *
  20.  * The Original Code is Open H323 Library.
  21.  *
  22.  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
  23.  *
  24.  * Contributor(s): ______________________________________.
  25.  *
  26.  * $Log: guid.h,v $
  27.  * Revision 1.4  2002/09/16 01:14:15  robertj
  28.  * Added #define so can select if #pragma interface/implementation is used on
  29.  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
  30.  *
  31.  * Revision 1.3  2002/08/05 10:03:47  robertj
  32.  * Cosmetic changes to normalise the usage of pragma interface/implementation.
  33.  *
  34.  * Revision 1.2  2001/03/19 05:51:35  robertj
  35.  * Added ! operator to do !IsNULL(), so cannot use it accidentally.
  36.  *
  37.  * Revision 1.1  2001/03/02 06:59:57  robertj
  38.  * Enhanced the globally unique identifier class.
  39.  *
  40.  */
  41.  
  42. #ifndef __OPAL_GUID_H
  43. #define __OPAL_GUID_H
  44.  
  45. #ifdef P_USE_PRAGMA
  46. #pragma interface
  47. #endif
  48.  
  49.  
  50. class PASN_OctetString;
  51.  
  52.  
  53. ///////////////////////////////////////////////////////////////////////////////
  54.  
  55. /**Globally unique ID definition.
  56.    This implements a 128 bit globally unique ID as required by many protocols
  57.    and software systems. The value is constructed in such a way as to make a
  58.    duplicate anywhere in the world highly unlikely.
  59.  */
  60. class OpalGloballyUniqueID : public PBYTEArray
  61. {
  62.     PCLASSINFO(OpalGloballyUniqueID, PBYTEArray);
  63.  
  64.   public:
  65.   /**@name Construction */
  66.   //@{
  67.     /**Create a new ID.
  68.        The ID created with this will be initialised to a globally unique ID
  69.        as per specification.
  70.      */
  71.     OpalGloballyUniqueID();
  72.  
  73.     /**Create an ID from a C string of hex (as produced by AsString()).
  74.        A useful construct is to construct a OpalGloballyUniqueID() with
  75.        NULL which produces an all zero GUID, etectable with the isNULL()
  76.        function.
  77.      */
  78.     OpalGloballyUniqueID(
  79.       const char * cstr    /// C string to convert
  80.     );
  81.     /**Create an ID from a PString of hex (as produced by AsString()).
  82.      */
  83.     OpalGloballyUniqueID(
  84.       const PString & str  /// String of hex to convert
  85.     );
  86.     /**Create an ID from an octet string in an ASN PDU.
  87.      */
  88.     OpalGloballyUniqueID(
  89.       const PASN_OctetString & ostr  /// Octet string from ASN to convert
  90.     );
  91.   //@}
  92.  
  93.   /**@name Overrides from PObject */
  94.   //@{
  95.     /**Standard stream print function.
  96.        The PObject class has a << operator defined that calls this function
  97.        polymorphically.
  98.       */
  99.     virtual void PrintOn(
  100.       ostream & strm    /// Stream to output text representation
  101.     ) const;
  102.  
  103.     /**Standard stream read function.
  104.        The PObject class has a >> operator defined that calls this function
  105.        polymorphically.
  106.       */
  107.     virtual void ReadFrom(
  108.       istream & strm    /// Stream to output text representation
  109.     );
  110.  
  111.     /**Create a clone of the ID.
  112.        The duplicate ID has the same value as the source. Required for having
  113.        this object as a key in dictionaries.
  114.       */
  115.     virtual PObject * Clone() const;
  116.  
  117.     /**Get the hash value for the ID.
  118.        Creates a number based on the ID value for use in the hash table of
  119.        a dictionary. Required for having this object as a key in dictionaries.
  120.       */
  121.     virtual PINDEX HashFunction() const;
  122.   //@}
  123.  
  124.   /**@name Operations */
  125.   //@{
  126.     /**Convert the ID to human readable string.
  127.       */
  128.     PString AsString() const;
  129.  
  130.     /**Test if the GUID is null, ie consists of all zeros.
  131.       */
  132.     BOOL IsNULL() const;
  133.  
  134.     BOOL operator!() const { return !IsNULL(); }
  135.   //@}
  136. };
  137.  
  138.  
  139. #endif // __OPAL_GUID_H
  140.  
  141.  
  142. /////////////////////////////////////////////////////////////////////////////
  143.