diff options
author | Marc Laukien <marc@zeroc.com> | 2001-10-16 18:06:37 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-10-16 18:06:37 +0000 |
commit | fc646735c001a1f286c2ff4175bef1dfc3a67f42 (patch) | |
tree | c35bd7e20e836da1f9de2393d064b872e4316a6c /cpp/src/Ice/Reference.cpp | |
parent | fixed memory leak (diff) | |
download | ice-fc646735c001a1f286c2ff4175bef1dfc3a67f42.tar.bz2 ice-fc646735c001a1f286c2ff4175bef1dfc3a67f42.tar.xz ice-fc646735c001a1f286c2ff4175bef1dfc3a67f42.zip |
_hash, fixes to proxy equivalence/compare operations
Diffstat (limited to 'cpp/src/Ice/Reference.cpp')
-rw-r--r-- | cpp/src/Ice/Reference.cpp | 140 |
1 files changed, 132 insertions, 8 deletions
diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index b19f6b7a578..63cd658b101 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -20,15 +20,17 @@ using namespace IceInternal; void IceInternal::incRef(Reference* p) { p->__incRef(); } void IceInternal::decRef(Reference* p) { p->__decRef(); } -IceInternal::Reference::Reference(const InstancePtr& inst, const string& ident, Mode md, bool sec, +IceInternal::Reference::Reference(const InstancePtr& inst, const string& ident, const string& fac, Mode md, bool sec, const vector<EndpointPtr>& origEndpts, const vector<EndpointPtr>& endpts) : instance(inst), identity(ident), + facet(facet), mode(md), secure(sec), origEndpoints(origEndpts), endpoints(endpts) { + calcHashValue(); } IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : @@ -61,8 +63,6 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : const_cast<string&>(identity) = s.substr(beg, end - beg); - transform(s.begin(), s.end(), s.begin(), tolower); - while (true) { beg = s.find_first_not_of(delim, end); @@ -87,47 +87,106 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : { throw ReferenceParseException(__FILE__, __LINE__); } + + string argument; + string::size_type argumentBeg = str.find_first_not_of(delim, end); + if (argumentBeg != string::npos && str[argumentBeg] != '-') + { + beg = argumentBeg; + end = str.find_first_of(delim, beg); + if (end == string::npos) + { + end = str.length(); + } + argument = str.substr(beg, end - beg); + } switch (option[1]) { + case 'f': + { + if (argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + + const_cast<std::string&>(facet) = argument; + break; + } + case 't': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeTwoway; break; } case 'o': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeOneway; break; } case 'O': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeBatchOneway; break; } case 'd': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeDatagram; break; } case 'D': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<Mode&>(mode) = ModeBatchDatagram; break; } case 's': { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + const_cast<bool&>(secure) = true; break; } default: { + if (!argument.empty()) + { + throw EndpointParseException(__FILE__, __LINE__); + } + throw ReferenceParseException(__FILE__, __LINE__); } } @@ -177,6 +236,8 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const string& str) : { throw ReferenceParseException(__FILE__, __LINE__); } + + calcHashValue(); } IceInternal::Reference::Reference(const string& ident, BasicStream* s) : @@ -190,6 +251,8 @@ IceInternal::Reference::Reference(const string& ident, BasicStream* s) : // constructor read the identity, and pass it as a parameter. // + s->read(const_cast<string&>(facet)); + vector<EndpointPtr>::const_iterator p; Ice::Int sz; @@ -215,6 +278,8 @@ IceInternal::Reference::Reference(const string& ident, BasicStream* s) : Endpoint::streamRead(s, const_cast<EndpointPtr&>(*p)); } } + + calcHashValue(); } void @@ -225,6 +290,8 @@ IceInternal::Reference::streamWrite(BasicStream* s) const // write the identity. // + s->write(facet); + vector<EndpointPtr>::const_iterator p; s->write(Ice::Int(origEndpoints.size())); @@ -281,7 +348,20 @@ IceInternal::Reference::changeIdentity(const string& newIdentity) const } else { - return new Reference(instance, newIdentity, mode, secure, origEndpoints, endpoints); + return new Reference(instance, newIdentity, facet, mode, secure, origEndpoints, endpoints); + } +} + +ReferencePtr +IceInternal::Reference::changeFacet(const string& newFacet) const +{ + if (newFacet == facet) + { + return ReferencePtr(const_cast<Reference*>(this)); + } + else + { + return new Reference(instance, identity, newFacet, mode, secure, origEndpoints, endpoints); } } @@ -302,7 +382,7 @@ IceInternal::Reference::changeTimeout(int timeout) const newEndpoints.push_back((*p)->timeout(timeout)); } - ReferencePtr ref(new Reference(instance, identity, mode, secure, newOrigEndpoints, newEndpoints)); + ReferencePtr ref(new Reference(instance, identity, facet, mode, secure, newOrigEndpoints, newEndpoints)); if (*ref.get() == *this) { @@ -321,7 +401,7 @@ IceInternal::Reference::changeMode(Mode newMode) const } else { - return new Reference(instance, identity, newMode, secure, origEndpoints, endpoints); + return new Reference(instance, identity, facet, newMode, secure, origEndpoints, endpoints); } } @@ -334,7 +414,7 @@ IceInternal::Reference::changeSecure(bool newSecure) const } else { - return new Reference(instance, identity, mode, newSecure, origEndpoints, endpoints); + return new Reference(instance, identity, facet, mode, newSecure, origEndpoints, endpoints); } } @@ -347,7 +427,7 @@ IceInternal::Reference::changeEndpoints(const std::vector<EndpointPtr>& newEndpo } else { - return new Reference(instance, identity, mode, secure, origEndpoints, newEndpoints); + return new Reference(instance, identity, facet, mode, secure, origEndpoints, newEndpoints); } } @@ -364,6 +444,11 @@ IceInternal::Reference::operator==(const Reference& r) const return false; } + if (facet != r.facet) + { + return false; + } + if (mode != r.mode) { return false; @@ -404,6 +489,15 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } + if (facet < r.facet) + { + return true; + } + else if (facet != r.facet) + { + return false; + } + if (mode < r.mode) { return true; @@ -442,3 +536,33 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } + +void +IceInternal::Reference::calcHashValue() +{ + Int h = 0; + + string::const_iterator p; + + for (p = identity.begin(); p != identity.end(); ++p) + { + h = 5 * h + *p; + } + + for (p = facet.begin(); p != facet.end(); ++p) + { + h = 5 * h + *p; + } + + h = 5 * h + static_cast<Int>(mode); + + h = 5 * h + static_cast<Int>(secure); + + // + // TODO: Should we also take the endpoints into account for hash + // calculation? Perhaps not, the code above should be good enough + // for a good hash value. + // + + const_cast<Int&>(hashValue) = h; +} |