GuidConverter.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef DCPS_GUIDCONVERTER_H
00009 #define DCPS_GUIDCONVERTER_H
00010 
00011 #include "tao/Basic_Types.h"
00012 
00013 #include "dds/DdsDcpsGuidC.h"
00014 
00015 #include "GuidUtils.h"
00016 
00017 #include "dcps_export.h"
00018 #include "dds/DCPS/Definitions.h"
00019 #include "dds/DCPS/SafetyProfileStreams.h"
00020 #include "dds/DCPS/PoolAllocator.h"
00021 
00022 namespace OpenDDS {
00023 namespace DCPS {
00024 
00025 /**
00026  * @class GuidConverter
00027  *
00028  * @brief Conversion processing and value testing utilities for RTPS
00029  *        GUID_t types.
00030  *
00031  * This class encapsulates the conversion of a GUID_t value to and from
00032  * other types used within OpenDDS.  This class handles opaque GUID_t values
00033  * only.  For specific access, the appropriate subclass must instead be used.
00034  *
00035  * Since the GUID_t type is formed of octets in network order, we do all
00036  * processing byte by byte to avoid any endian issues.
00037  *
00038  * Currently the GUID_t is mapped from various internal values.
00039  * These mappings are:
00040  *
00041  * byte  structure reference     content
00042  * ---- ---------------------    --------------------------
00043  *   0  GUID_t.guidPrefix[ 0] == VendorId_t == 0x01 for OCI (used for OpenDDS)
00044  *   1  GUID_t.guidPrefix[ 1] == VendorId_t == 0x03 for OCI (used for OpenDDS)
00045  *   2  GUID_t.guidPrefix[ 2] == 0x00
00046  *   3  GUID_t.guidPrefix[ 3] == 0x00
00047  *
00048  *   4  GUID_t.guidPrefix[ 4] == <private> (MS byte)
00049  *   5  GUID_t.guidPrefix[ 5] == <private>
00050  *   6  GUID_t.guidPrefix[ 6] == <private>
00051  *   7  GUID_t.guidPrefix[ 7] == <private> (LS byte)
00052  *
00053  *   8  GUID_t.guidPrefix[ 8] == <private> (MS byte)
00054  *   9  GUID_t.guidPrefix[ 9] == <private>
00055  *  10  GUID_t.guidPrefix[10] == <private>
00056  *  11  GUID_t.guidPrefix[11] == <private> (LS byte)
00057  *
00058  *  12  GUID_t.entityId.entityKey[ 0] == entity id[0] (MS byte)
00059  *  13  GUID_t.entityId.entityKey[ 1] == entity id[1]
00060  *  14  GUID_t.entityId.entityKey[ 2] == entity id[2] (LS byte)
00061  *  15  GUID_t.entityId.entityKind    == entity kind
00062  */
00063 class OpenDDS_Dcps_Export GuidConverter {
00064 public:
00065   /// Construct from a GUID_t.
00066   GuidConverter(const GUID_t& guid);
00067 
00068   /// Virtual destructor (this is a base class).
00069   virtual ~GuidConverter();
00070 
00071   /// Calculate the CRC32 checksum.
00072   long checksum() const;
00073 
00074   /// Extract the VendorId value.
00075   long vendorId() const;
00076 
00077   /// Extract the EntityId value.
00078   long entityId() const;
00079 
00080   /// Extract the EntityKey value.
00081   long entityKey() const;
00082 
00083   /// Extract the EntityKind value.
00084   EntityKind entityKind() const;
00085 
00086   /// Convert to diagnostic string.
00087   operator OPENDDS_STRING() const;
00088 #ifdef DDS_HAS_WCHAR
00089   operator std::wstring() const;
00090 #endif
00091 
00092   OPENDDS_STRING uniqueId() const;
00093 
00094 protected:
00095   const GUID_t guid_;
00096 };
00097 
00098 struct OpenDDS_Dcps_Export LogGuid {
00099   explicit LogGuid(const GUID_t& id)
00100     : conv_(GuidConverter(id)) {}
00101   const char* c_str() const { return conv_.c_str(); }
00102   OPENDDS_STRING conv_;
00103 };
00104 
00105 #ifndef OPENDDS_SAFETY_PROFILE
00106 OpenDDS_Dcps_Export std::ostream&
00107 operator<<(std::ostream& os, const OpenDDS::DCPS::GuidConverter& rhs);
00108 
00109 #ifdef DDS_HAS_WCHAR
00110 OpenDDS_Dcps_Export std::wostream&
00111 operator<<(std::wostream& os, const OpenDDS::DCPS::GuidConverter& rhs);
00112 #endif //DDS_HAS_WCHAR
00113 #endif //OPENDDS_SAFETY_PROFILE
00114 
00115 } // namespace
00116 } // namespace
00117 
00118 #endif /* DCPS_GUIDCONVERTER_H */

Generated on Fri Feb 12 20:05:23 2016 for OpenDDS by  doxygen 1.4.7