Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/ 9 : 10 : #include "GuidUtils.h" 11 : #include "Util.h" 12 : #include "GuidBuilder.h" 13 : #include "SafetyProfileStreams.h" 14 : #ifndef OPENDDS_SAFETY_PROFILE 15 : # include "RestoreOutputStreamState.h" 16 : #endif 17 : 18 : #include <ace/ACE.h> 19 : #include <ace/OS_NS_string.h> 20 : 21 : #include <cstdlib> 22 : #include <cstdio> 23 : 24 : namespace { 25 : 26 : #ifndef OPENDDS_SAFETY_PROFILE 27 : inline std::ostream& 28 3 : sep(std::ostream& os) 29 : { 30 3 : return os << "."; 31 : } 32 : 33 : inline std::ostream& 34 16 : setopts(std::ostream& os) 35 : { 36 16 : return os << std::setfill('0') << std::setw(2); 37 : } 38 : #endif 39 : 40 : } // namespace 41 : 42 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 43 : 44 : namespace OpenDDS { namespace DCPS { 45 : 46 : OPENDDS_STRING 47 0 : to_string(const EntityId_t& entityId) 48 : { 49 0 : return to_hex_dds_string(&entityId.entityKey[0], sizeof(EntityKey_t)) + 50 0 : to_dds_string(unsigned(entityId.entityKind), true); 51 : } 52 : 53 : OPENDDS_STRING 54 0 : to_string(const GUID_t& guid) 55 : { 56 0 : return to_hex_dds_string(&guid.guidPrefix[0], sizeof(GuidPrefix_t), '.', 4) + 57 0 : '.' + to_string(guid.entityId); 58 : } 59 : 60 0 : void intersect(const GuidSet& a, const GuidSet& b, GuidSet& result) 61 : { 62 0 : result.clear(); 63 0 : intersect_sorted_ranges(a.begin(), a.end(), b.begin(), b.end(), 64 : std::inserter(result, result.end()), GUID_tKeyLessThan()); 65 0 : } 66 : 67 : #ifndef OPENDDS_SAFETY_PROFILE 68 : std::ostream& 69 1 : operator<<(std::ostream& os, const GUID_t& rhs) 70 : { 71 1 : RestoreOutputStreamState os_state(os); 72 : 73 1 : std::size_t len = sizeof(rhs.guidPrefix); 74 : 75 1 : os << std::hex; 76 : 77 13 : for (std::size_t i = 0; i < len; ++i) { 78 12 : os << setopts << unsigned(rhs.guidPrefix[i]); 79 : 80 12 : if ((i + 1) % 4 == 0) os << sep; 81 : } 82 : 83 1 : len = sizeof(rhs.entityId.entityKey); 84 : 85 4 : for (std::size_t i = 0; i < len; ++i) { 86 3 : os << setopts << unsigned(rhs.entityId.entityKey[i]); 87 : } 88 : 89 1 : os << setopts << unsigned(rhs.entityId.entityKind); 90 : 91 : // Reset, because hex is "sticky" 92 1 : os << std::dec; 93 : 94 1 : return os; 95 1 : } 96 : 97 : std::istream& 98 0 : operator>>(std::istream& is, GUID_t& rhs) 99 : { 100 : long word; 101 : char discard; 102 : 103 0 : GuidBuilder builder(rhs); 104 : 105 0 : is >> std::hex >> word; 106 0 : builder.guidPrefix0(word); 107 0 : is >> discard; // sep 108 : 109 0 : is >> std::hex >> word; 110 0 : builder.guidPrefix1(word); 111 0 : is >> discard; // sep 112 : 113 0 : is >> std::hex >> word; 114 0 : builder.guidPrefix2(word); 115 0 : is >> discard; // sep 116 : 117 0 : is >> std::hex >> word; 118 0 : builder.entityId(word); 119 : 120 0 : return is; 121 0 : } 122 : #endif 123 : 124 : } } 125 : 126 : OPENDDS_END_VERSIONED_NAMESPACE_DECL