diff options
author | Marc Laukien <marc@zeroc.com> | 2001-10-22 21:23:48 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-10-22 21:23:48 +0000 |
commit | a5074c07a75bc7b6debd20fbc886103831d489dd (patch) | |
tree | 2eb80e71dcc528a86d481880b6d42702fb3cbeb4 | |
parent | fixes (diff) | |
download | ice-a5074c07a75bc7b6debd20fbc886103831d489dd.tar.bz2 ice-a5074c07a75bc7b6debd20fbc886103831d489dd.tar.xz ice-a5074c07a75bc7b6debd20fbc886103831d489dd.zip |
more objects demo stuff
-rw-r--r-- | cpp/include/Ice/Handle.h | 48 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyHandle.h | 48 | ||||
-rw-r--r-- | cpp/include/IceUtil/Handle.h | 84 | ||||
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 63 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.cpp | 212 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.h | 6 | ||||
-rw-r--r-- | cpp/test/Ice/objects/AllTests.cpp | 29 | ||||
-rw-r--r-- | cpp/test/Ice/objects/Client.cpp | 32 | ||||
-rw-r--r-- | cpp/test/Ice/objects/TestI.cpp | 13 |
9 files changed, 260 insertions, 275 deletions
diff --git a/cpp/include/Ice/Handle.h b/cpp/include/Ice/Handle.h index b94cd81e079..83f72cb77bc 100644 --- a/cpp/include/Ice/Handle.h +++ b/cpp/include/Ice/Handle.h @@ -185,54 +185,6 @@ public: } }; -template<typename T, typename U> -inline bool operator==(const Handle<T>& a, const Handle<U>& b) -{ - T* ap = a.get(); - U* bp = b.get(); - if (ap == bp) - { - return true; - } - else if (!ap) - { - assert(bp); - return false; - } - else - { - return *ap == *bp; - } -} - -template<typename T, typename U> -inline bool operator!=(const Handle<T>& a, const Handle<U>& b) -{ - return !operator==(a, b); -} - -template<typename T, typename U> -inline bool operator<(const Handle<T>& a, const Handle<U>& b) -{ - T* ap = a.get(); - U* bp = b.get(); - if (!ap || !bp) - { - if (!ap && bp) - { - return true; - } - else - { - return false; - } - } - else - { - return *a.get() < *b.get(); - } -} - } #endif diff --git a/cpp/include/Ice/ProxyHandle.h b/cpp/include/Ice/ProxyHandle.h index 4b5e2055f0f..5b529ab6d56 100644 --- a/cpp/include/Ice/ProxyHandle.h +++ b/cpp/include/Ice/ProxyHandle.h @@ -182,54 +182,6 @@ public: } }; -template<typename T, typename U> -inline bool operator==(const ProxyHandle<T>& a, const ProxyHandle<U>& b) -{ - T* ap = a.get(); - U* bp = b.get(); - if (ap == bp) - { - return true; - } - else if (!ap) - { - assert(bp); - return false; - } - else - { - return *ap == *bp; - } -} - -template<typename T, typename U> -inline bool operator!=(const ProxyHandle<T>& a, const ProxyHandle<U>& b) -{ - return !operator==(a, b); -} - -template<typename T, typename U> -inline bool operator<(const ProxyHandle<T>& a, const ProxyHandle<U>& b) -{ - T* ap = a.get(); - U* bp = b.get(); - if (!ap || !bp) - { - if (!ap && bp) - { - return true; - } - else - { - return false; - } - } - else - { - return *a.get() < *b.get(); - } -} - } #endif diff --git a/cpp/include/IceUtil/Handle.h b/cpp/include/IceUtil/Handle.h index 2254eb7430a..aa0c5156256 100644 --- a/cpp/include/IceUtil/Handle.h +++ b/cpp/include/IceUtil/Handle.h @@ -56,6 +56,42 @@ public: T* _ptr; }; +template<typename T, typename U> +inline bool operator==(const HandleBase<T>& a, const HandleBase<U>& b) +{ + T* ap = a.get(); + U* bp = b.get(); + if (ap && bp) + { + return *ap == *bp; + } + else + { + return !ap && !bp; + } +} + +template<typename T, typename U> +inline bool operator!=(const HandleBase<T>& a, const HandleBase<U>& b) +{ + return !operator==(a, b); +} + +template<typename T, typename U> +inline bool operator<(const HandleBase<T>& a, const HandleBase<U>& b) +{ + T* ap = a.get(); + U* bp = b.get(); + if (ap && bp) + { + return *ap < *bp; + } + else + { + return !ap && bp; + } +} + template<typename T> class Handle : public HandleBase<T> { @@ -181,54 +217,6 @@ public: } }; -template<typename T, typename U> -inline bool operator==(const Handle<T>& a, const Handle<U>& b) -{ - T* ap = a.get(); - U* bp = b.get(); - if (ap == bp) - { - return true; - } - else if (!ap) - { - assert(bp); - return false; - } - else - { - return *ap == *bp; - } -} - -template<typename T, typename U> -inline bool operator!=(const Handle<T>& a, const Handle<U>& b) -{ - return !operator==(a, b); -} - -template<typename T, typename U> -inline bool operator<(const Handle<T>& a, const Handle<U>& b) -{ - T* ap = a.get(); - U* bp = b.get(); - if (!ap || !bp) - { - if (!ap && bp) - { - return true; - } - else - { - return false; - } - } - else - { - return *a.get() < *b.get(); - } -} - } #endif diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index ad1ce577113..ebeb1c685bf 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -617,11 +617,11 @@ IceInternal::BasicStream::write(const string& v) write(len); if (len > 0) { + Int num = _encapsStack.back().stringsWritten.size(); + _encapsStack.back().stringsWritten[v] = -(num + 1); int pos = b.size(); resize(pos + len); copy(v.begin(), v.end(), b.begin() + pos); - Int num = _encapsStack.back().stringsWritten.size(); - _encapsStack.back().stringsWritten[v] = -(num + 1); } } } @@ -710,13 +710,13 @@ IceInternal::BasicStream::write(const wstring& v) write(len); if (len > 0) { + Int num = _encapsStack.back().wstringsWritten.size(); + _encapsStack.back().wstringsWritten[v] = -(num + 1); wstring::const_iterator p; for (p = v.begin(); p != v.end(); ++p) { write(static_cast<Short>(*p)); } - Int num = _encapsStack.back().wstringsWritten.size(); - _encapsStack.back().wstringsWritten[v] = -(num + 1); } } } @@ -809,10 +809,18 @@ IceInternal::BasicStream::write(const ObjectPtr& v) else { write(Int(-1)); - write(v->__getClassIds()[0]); - v->__write(this); - Int num = _encapsStack.back().objectsWritten.size(); - _encapsStack.back().objectsWritten[v] = num; + + if (v) + { + Int num = _encapsStack.back().objectsWritten.size(); + _encapsStack.back().objectsWritten[v] = num; + write(v->__getClassIds()[0]); + v->__write(this); + } + else + { + write(""); + } } } @@ -835,24 +843,35 @@ IceInternal::BasicStream::read(const char* signatureType, ObjectPtr& v) { string id; read(id); - ObjectFactoryPtr factory = _instance->servantFactoryManager()->find(id); - - if (factory) + + if (id.empty()) { - v = factory->create(id); - if (v) - { - v->__read(this); - return true; - } + v = 0; + return true; } - - if (id == signatureType) + else { - return false; + ObjectFactoryPtr factory = _instance->servantFactoryManager()->find(id); + + if (factory) + { + v = factory->create(id); + if (v) + { + _encapsStack.back().objectsRead.push_back(v); + v->__read(this); + return true; + } + } + + if (id == signatureType) + { + _encapsStack.back().objectsRead.push_back(v); + return false; + } + + throw NoObjectFactoryException(__FILE__, __LINE__); } - - throw NoObjectFactoryException(__FILE__, __LINE__); } } diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 172ff995567..8cc024bb607 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -299,6 +299,112 @@ IceInternal::Reference::Reference(const string& ident, BasicStream* s) : calcHashValue(); } +bool +IceInternal::Reference::operator==(const Reference& r) const +{ + if (this == &r) + { + return true; + } + + if (identity != r.identity) + { + return false; + } + + if (facet != r.facet) + { + return false; + } + + if (mode != r.mode) + { + return false; + } + + if (secure != r.secure) + { + return false; + } + + if (origEndpoints != r.origEndpoints) + { + return false; + } + + if (endpoints != r.endpoints) + { + return false; + } + + return true; +} + +bool +IceInternal::Reference::operator<(const Reference& r) const +{ + if (this == &r) + { + return false; + } + + if (identity < r.identity) + { + return true; + } + else if (identity != r.identity) + { + return false; + } + + if (facet < r.facet) + { + return true; + } + else if (facet != r.facet) + { + return false; + } + + if (mode < r.mode) + { + return true; + } + else if (mode != r.mode) + { + return false; + } + + if (!secure && r.secure) + { + return true; + } + else if (secure != r.secure) + { + return false; + } + + if (origEndpoints < r.origEndpoints) + { + return true; + } + else if (origEndpoints != r.origEndpoints) + { + return false; + } + + if (endpoints < r.endpoints) + { + return true; + } + else if (endpoints != r.endpoints) + { + return false; + } + + return false; +} + void IceInternal::Reference::streamWrite(BasicStream* s) const { @@ -453,112 +559,6 @@ IceInternal::Reference::changeEndpoints(const std::vector<EndpointPtr>& newEndpo } } -bool -IceInternal::Reference::operator==(const Reference& r) const -{ - if (this == &r) - { - return true; - } - - if (identity != r.identity) - { - return false; - } - - if (facet != r.facet) - { - return false; - } - - if (mode != r.mode) - { - return false; - } - - if (secure != r.secure) - { - return false; - } - - if (origEndpoints != r.origEndpoints) - { - return false; - } - - if (endpoints != r.endpoints) - { - return false; - } - - return true; -} - -bool -IceInternal::Reference::operator<(const Reference& r) const -{ - if (this == &r) - { - return false; - } - - if (identity < r.identity) - { - return true; - } - else if (identity != r.identity) - { - return false; - } - - if (facet < r.facet) - { - return true; - } - else if (facet != r.facet) - { - return false; - } - - if (mode < r.mode) - { - return true; - } - else if (mode != r.mode) - { - return false; - } - - if (!secure && r.secure) - { - return true; - } - else if (secure != r.secure) - { - return false; - } - - if (origEndpoints < r.origEndpoints) - { - return true; - } - else if (origEndpoints != r.origEndpoints) - { - return false; - } - - if (endpoints < r.endpoints) - { - return true; - } - else if (endpoints != r.endpoints) - { - return false; - } - - return false; -} - void IceInternal::Reference::calcHashValue() { diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index f6f1cc1a3e0..f60ae3171b5 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -40,6 +40,9 @@ public: Reference(const InstancePtr&, const std::string&); Reference(const std::string&, BasicStream*); + bool operator==(const Reference&) const; + bool operator<(const Reference&) const; + // // Marshal the reference // @@ -73,9 +76,6 @@ public: ReferencePtr changeSecure(bool) const; ReferencePtr changeEndpoints(const std::vector<EndpointPtr>&) const; - bool operator==(const Reference&) const; - bool operator<(const Reference&) const; - private: void calcHashValue(); diff --git a/cpp/test/Ice/objects/AllTests.cpp b/cpp/test/Ice/objects/AllTests.cpp index 3636834c6c7..7934e8cdc47 100644 --- a/cpp/test/Ice/objects/AllTests.cpp +++ b/cpp/test/Ice/objects/AllTests.cpp @@ -29,5 +29,34 @@ allTests(const Ice::CommunicatorPtr& communicator) test(initial == base); cout << "ok" << endl; + cout << "getting first B... " << flush; + BPtr b1 = initial->getB1(); + test(b1); + cout << "ok" << endl; + + cout << "getting second B... " << flush; + BPtr b2 = initial->getB2(); + test(b2); + cout << "ok" << endl; + + cout << "getting C... " << flush; + CPtr c = initial->getC(); + test(c); + cout << "ok" << endl; + + cout << "getting D... " << flush; + DPtr d = initial->getD(); + test(d); + cout << "ok" << endl; + + cout << "checking consistency... " << flush; + test(b1 != b2); + test(b1 != c); + test(b1 != d); + test(b2 != c); + test(b2 != d); + test(c != d); + cout << "ok" << endl; + return initial; } diff --git a/cpp/test/Ice/objects/Client.cpp b/cpp/test/Ice/objects/Client.cpp index c61fa56625c..d9a019848cd 100644 --- a/cpp/test/Ice/objects/Client.cpp +++ b/cpp/test/Ice/objects/Client.cpp @@ -14,9 +14,41 @@ using namespace std; +class MyObjectFactory : public Ice::ObjectFactory +{ +public: + + virtual Ice::ObjectPtr create(const string& type) + { + if (type == "::B") + { + return new B; + } + else if (type == "::C") + { + return new C; + } + else if (type == "::D") + { + return new D; + } + assert(false); // Should never be reached + } + + virtual void destroy() + { + // Nothing to do + } +}; + int run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) { + Ice::ObjectFactoryPtr factory = new MyObjectFactory; + communicator->addObjectFactory(factory, "::B"); + communicator->addObjectFactory(factory, "::C"); + communicator->addObjectFactory(factory, "::D"); + InitialPrx allTests(const Ice::CommunicatorPtr&); InitialPrx initial = allTests(communicator); initial->shutdown(); diff --git a/cpp/test/Ice/objects/TestI.cpp b/cpp/test/Ice/objects/TestI.cpp index b4170877378..267e389be21 100644 --- a/cpp/test/Ice/objects/TestI.cpp +++ b/cpp/test/Ice/objects/TestI.cpp @@ -18,6 +18,19 @@ InitialI::InitialI(const Ice::ObjectAdapterPtr& adapter) : _c(new C), _d(new D) { + _b1->a = _b2; // Cyclic reference to another B + _b1->b = _b1; // Self reference. + _b1->c = 0; // Null reference. + + _b2->a = _b2; // Self reference, using base. + _b2->b = _b1; // Cyclic reference to another B + _b2->c = _c; // Cyclic reference to a C. + + _c->b = _b2; // Cyclic reference to a B. + + _d->a = _b1; // Reference to a B. + _d->b = _b2; // Reference to a B. + _d->c = 0; // Reference to a C. } void |