diff options
author | Jose <jose@zeroc.com> | 2017-10-13 18:41:38 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2017-10-13 18:41:38 +0200 |
commit | d46f067bb9efca15b3fc69ed81d54dbe59d6686e (patch) | |
tree | 5f5fab14cbf919c64a272a25944bbcefb324726a | |
parent | Remove extra ICE_MATLAB_API macros (diff) | |
download | ice-d46f067bb9efca15b3fc69ed81d54dbe59d6686e.tar.bz2 ice-d46f067bb9efca15b3fc69ed81d54dbe59d6686e.tar.xz ice-d46f067bb9efca15b3fc69ed81d54dbe59d6686e.zip |
Replace SELF/DEREF macros with deref template function
-rw-r--r-- | matlab/src/Communicator.cpp | 44 | ||||
-rw-r--r-- | matlab/src/Communicator.h | 17 | ||||
-rw-r--r-- | matlab/src/Connection.cpp | 41 | ||||
-rw-r--r-- | matlab/src/Endpoint.cpp | 18 | ||||
-rw-r--r-- | matlab/src/Endpoint.h | 1 | ||||
-rw-r--r-- | matlab/src/Future.cpp | 21 | ||||
-rw-r--r-- | matlab/src/Init.cpp | 8 | ||||
-rw-r--r-- | matlab/src/Logger.cpp | 22 | ||||
-rw-r--r-- | matlab/src/ObjectPrx.cpp | 268 | ||||
-rw-r--r-- | matlab/src/Properties.cpp | 33 | ||||
-rw-r--r-- | matlab/src/Util.h | 6 |
11 files changed, 225 insertions, 254 deletions
diff --git a/matlab/src/Communicator.cpp b/matlab/src/Communicator.cpp index e30e4375d5e..20249c20574 100644 --- a/matlab/src/Communicator.cpp +++ b/matlab/src/Communicator.cpp @@ -10,31 +10,21 @@ #include <Ice/Communicator.h> #include <Ice/Proxy.h> #include "ice.h" -#include "Communicator.h" #include "Future.h" #include "Logger.h" #include "ObjectPrx.h" #include "Util.h" -#define DEREF(x) (*(reinterpret_cast<shared_ptr<Ice::Communicator>*>(x))) -#define SELF DEREF(self) - using namespace std; using namespace IceMatlab; -shared_ptr<Ice::Communicator> -IceMatlab::getCommunicator(void* p) -{ - return DEREF(p); -} - extern "C" { mxArray* Ice_Communicator_unref(void* self) { - delete &SELF; + delete reinterpret_cast<shared_ptr<Ice::Communicator>*>(self); return 0; } @@ -43,7 +33,7 @@ Ice_Communicator_destroy(void* self) { try { - SELF->destroy(); + deref<Ice::Communicator>(self)->destroy(); } catch(const std::exception& ex) { @@ -56,7 +46,7 @@ mxArray* Ice_Communicator_destroyAsync(void* self, void** future) { *future = 0; - auto c = SELF; + auto c = deref<Ice::Communicator>(self); auto f = make_shared<SimpleFuture>(); thread t([c, f] @@ -72,7 +62,7 @@ Ice_Communicator_destroyAsync(void* self, void** future) } }); t.detach(); - *future = new shared_ptr<SimpleFuture>(f); + *future = new shared_ptr<SimpleFuture>(move(f)); return 0; } @@ -81,7 +71,7 @@ Ice_Communicator_stringToProxy(void* self, const char* s, void** proxy) { try { - auto p = SELF->stringToProxy(s); + auto p = deref<Ice::Communicator>(self)->stringToProxy(s); if(p) { *proxy = createProxy(p); @@ -105,7 +95,7 @@ Ice_Communicator_proxyToString(void* self, void* proxy) try { auto p = getProxy(proxy); - return createResultValue(createStringFromUTF8(SELF->proxyToString(p))); + return createResultValue(createStringFromUTF8(deref<Ice::Communicator>(self)->proxyToString(p))); } catch(const std::exception& ex) { @@ -119,7 +109,7 @@ Ice_Communicator_propertyToProxy(void* self, const char* prop, void** proxy) { try { - auto p = SELF->propertyToProxy(prop); + auto p = deref<Ice::Communicator>(self)->propertyToProxy(prop); if(p) { *proxy = createProxy(p); @@ -143,7 +133,7 @@ Ice_Communicator_proxyToProperty(void* self, void* proxy, const char* prop) try { auto p = getProxy(proxy); - auto d = SELF->proxyToProperty(p, prop); + auto d = deref<Ice::Communicator>(self)->proxyToProperty(p, prop); return createResultValue(createStringMap(d)); } catch(const std::exception& ex) @@ -160,7 +150,7 @@ Ice_Communicator_identityToString(void* self, mxArray* id) { Ice::Identity ident; getIdentity(id, ident); - return createResultValue(createStringFromUTF8(SELF->identityToString(ident))); + return createResultValue(createStringFromUTF8(deref<Ice::Communicator>(self)->identityToString(ident))); } catch(const std::exception& ex) { @@ -174,7 +164,7 @@ Ice_Communicator_getProperties(void* self, void** props) { try { - auto p = SELF->getProperties(); + auto p = deref<Ice::Communicator>(self)->getProperties(); *props = new shared_ptr<Ice::Properties>(move(p)); } catch(const std::exception& ex) @@ -189,7 +179,7 @@ Ice_Communicator_getLogger(void* self, void** logger) { try { - auto l = SELF->getLogger(); + auto l = deref<Ice::Communicator>(self)->getLogger(); *logger = createLogger(l); } catch(const std::exception& ex) @@ -204,7 +194,7 @@ Ice_Communicator_getDefaultRouter(void* self, void** proxy) { try { - auto p = SELF->getDefaultRouter(); + auto p = deref<Ice::Communicator>(self)->getDefaultRouter(); if(p) { *proxy = createProxy(p); @@ -231,7 +221,7 @@ Ice_Communicator_setDefaultRouter(void* self, void* proxy) { p = Ice::uncheckedCast<Ice::RouterPrx>(getProxy(proxy)); } - SELF->setDefaultRouter(p); + deref<Ice::Communicator>(self)->setDefaultRouter(p); } catch(const std::exception& ex) { @@ -245,7 +235,7 @@ Ice_Communicator_getDefaultLocator(void* self, void** proxy) { try { - auto p = SELF->getDefaultLocator(); + auto p = deref<Ice::Communicator>(self)->getDefaultLocator(); if(p) { *proxy = createProxy(p); @@ -272,7 +262,7 @@ Ice_Communicator_setDefaultLocator(void* self, void* proxy) { p = Ice::uncheckedCast<Ice::LocatorPrx>(getProxy(proxy)); } - SELF->setDefaultLocator(p); + deref<Ice::Communicator>(self)->setDefaultLocator(p); } catch(const std::exception& ex) { @@ -287,7 +277,7 @@ Ice_Communicator_flushBatchRequests(void* self, mxArray* mode) try { auto m = static_cast<Ice::CompressBatch>(getEnumerator(mode, "Ice.CompressBatch")); - SELF->flushBatchRequests(m); + deref<Ice::Communicator>(self)->flushBatchRequests(m); } catch(const std::exception& ex) { @@ -305,7 +295,7 @@ Ice_Communicator_flushBatchRequestsAsync(void* self, mxArray* mode, void** futur try { auto m = static_cast<Ice::CompressBatch>(getEnumerator(mode, "Ice.CompressBatch")); - function<void()> token = SELF->flushBatchRequestsAsync( + function<void()> token = deref<Ice::Communicator>(self)->flushBatchRequestsAsync( m, [f](exception_ptr e) { diff --git a/matlab/src/Communicator.h b/matlab/src/Communicator.h deleted file mode 100644 index 7fb22cb51e1..00000000000 --- a/matlab/src/Communicator.h +++ /dev/null @@ -1,17 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Ice/Communicator.h> - -namespace IceMatlab -{ - -std::shared_ptr<Ice::Communicator> getCommunicator(void*); - -} diff --git a/matlab/src/Connection.cpp b/matlab/src/Connection.cpp index c0ab9c2e3c6..6efebf390eb 100644 --- a/matlab/src/Connection.cpp +++ b/matlab/src/Connection.cpp @@ -13,9 +13,6 @@ #include "Future.h" #include "Util.h" -#define DEREF(x) (*(reinterpret_cast<shared_ptr<Ice::Connection>*>(x))) -#define SELF DEREF(self) - using namespace std; using namespace IceMatlab; @@ -136,7 +133,7 @@ extern "C" mxArray* Ice_Connection_unref(void* self) { - delete &SELF; + delete reinterpret_cast<shared_ptr<Ice::Connection>*>(self); return 0; } @@ -146,7 +143,7 @@ Ice_Connection_equals(void* self, void* other) assert(other); // Wrapper only calls this function for non-nil arguments. try { - return createResultValue(createBool(SELF == DEREF(other))); + return createResultValue(createBool(deref<Ice::Connection>(self) == deref<Ice::Connection>(other))); } catch(const std::exception& ex) { @@ -161,7 +158,7 @@ Ice_Connection_close(void* self, mxArray* m) try { auto mode = static_cast<Ice::ConnectionClose>(getEnumerator(m, "Ice.ConnectionClose")); - SELF->close(mode); + deref<Ice::Connection>(self)->close(mode); } catch(const std::exception& ex) { @@ -174,7 +171,7 @@ mxArray* Ice_Connection_closeAsync(void* self, mxArray* m, void** future) { *future = 0; - auto c = SELF; + auto c = deref<Ice::Connection>(self); auto f = make_shared<SimpleFuture>(); thread t([m, c, f] @@ -191,7 +188,7 @@ Ice_Connection_closeAsync(void* self, mxArray* m, void** future) } }); t.detach(); - *future = new shared_ptr<SimpleFuture>(f); + *future = new shared_ptr<SimpleFuture>(move(f)); return 0; } @@ -202,7 +199,7 @@ Ice_Connection_createProxy(void* self, mxArray* id, void** r) { Ice::Identity ident; getIdentity(id, ident); - auto proxy = SELF->createProxy(ident); + auto proxy = deref<Ice::Connection>(self)->createProxy(ident); *r = new shared_ptr<Ice::ObjectPrx>(move(proxy)); } catch(const std::exception& ex) @@ -218,7 +215,7 @@ Ice_Connection_flushBatchRequests(void* self, mxArray* c) try { auto mode = static_cast<Ice::CompressBatch>(getEnumerator(c, "Ice.CompressBatch")); - SELF->flushBatchRequests(mode); + deref<Ice::Connection>(self)->flushBatchRequests(mode); } catch(const std::exception& ex) { @@ -236,7 +233,7 @@ Ice_Connection_flushBatchRequestsAsync(void* self, mxArray* c, void** future) try { auto mode = static_cast<Ice::CompressBatch>(getEnumerator(c, "Ice.CompressBatch")); - function<void()> token = SELF->flushBatchRequestsAsync( + function<void()> token = deref<Ice::Connection>(self)->flushBatchRequestsAsync( mode, [f](exception_ptr e) { @@ -261,7 +258,7 @@ Ice_Connection_getEndpoint(void* self, void** endpoint) { try { - *endpoint = createEndpoint(SELF->getEndpoint()); + *endpoint = createEndpoint(deref<Ice::Connection>(self)->getEndpoint()); } catch(const std::exception& ex) { @@ -275,7 +272,7 @@ Ice_Connection_heartbeat(void* self) { try { - SELF->heartbeat(); + deref<Ice::Connection>(self)->heartbeat(); } catch(const std::exception& ex) { @@ -292,7 +289,7 @@ Ice_Connection_heartbeatAsync(void* self, void** future) try { - function<void()> token = SELF->heartbeatAsync( + function<void()> token = deref<Ice::Connection>(self)->heartbeatAsync( [f](exception_ptr e) { f->exception(e); @@ -340,7 +337,7 @@ Ice_Connection_setACM(void* self, mxArray* t, mxArray* c, mxArray* h) { heartbeat = static_cast<Ice::ACMHeartbeat>(getEnumerator(h, "Ice.ACMHeartbeat")); } - SELF->setACM(timeout, close, heartbeat); + deref<Ice::Connection>(self)->setACM(timeout, close, heartbeat); } catch(const std::exception& ex) { @@ -354,7 +351,7 @@ Ice_Connection_getACM(void* self) { try { - auto acm = SELF->getACM(); + auto acm = deref<Ice::Connection>(self)->getACM(); mxArray* params[3]; params[0] = createInt(acm.timeout); params[1] = createInt(static_cast<int>(acm.close)); // The integer is converted to the enumerator. @@ -375,7 +372,7 @@ Ice_Connection_type(void* self) { try { - return createResultValue(createStringFromUTF8(SELF->type())); + return createResultValue(createStringFromUTF8(deref<Ice::Connection>(self)->type())); } catch(const std::exception& ex) { @@ -389,7 +386,7 @@ Ice_Connection_timeout(void* self) { try { - return createResultValue(createInt(SELF->timeout())); + return createResultValue(createInt(deref<Ice::Connection>(self)->timeout())); } catch(const std::exception& ex) { @@ -403,7 +400,7 @@ Ice_Connection_toString(void* self) { try { - return createResultValue(createStringFromUTF8(SELF->toString())); + return createResultValue(createStringFromUTF8(deref<Ice::Connection>(self)->toString())); } catch(const std::exception& ex) { @@ -417,7 +414,7 @@ Ice_Connection_getInfo(void* self) { try { - shared_ptr<Ice::ConnectionInfo> info = SELF->getInfo(); + shared_ptr<Ice::ConnectionInfo> info = deref<Ice::Connection>(self)->getInfo(); return createResultValue(createInfo(info)); } catch(const std::exception& ex) @@ -431,7 +428,7 @@ Ice_Connection_setBufferSize(void* self, int rcvSize, int sndSize) { try { - SELF->setBufferSize(rcvSize, sndSize); + deref<Ice::Connection>(self)->setBufferSize(rcvSize, sndSize); } catch(const std::exception& ex) { @@ -445,7 +442,7 @@ Ice_Connection_throwException(void* self) { try { - SELF->throwException(); + deref<Ice::Connection>(self)->throwException(); } catch(const std::exception& ex) { diff --git a/matlab/src/Endpoint.cpp b/matlab/src/Endpoint.cpp index 5ae253c8ee3..f18d4824433 100644 --- a/matlab/src/Endpoint.cpp +++ b/matlab/src/Endpoint.cpp @@ -12,9 +12,6 @@ #include "Endpoint.h" #include "Util.h" -#define DEREF(x) (*(reinterpret_cast<shared_ptr<Ice::Endpoint>*>(x))) -#define SELF DEREF(self) - using namespace std; using namespace IceMatlab; @@ -24,12 +21,6 @@ IceMatlab::createEndpoint(shared_ptr<Ice::Endpoint> p) return new shared_ptr<Ice::Endpoint>(move(p)); } -shared_ptr<Ice::Endpoint> -IceMatlab::getEndpoint(void* p) -{ - return DEREF(p); -} - namespace { @@ -151,7 +142,7 @@ extern "C" mxArray* Ice_Endpoint_unref(void* self) { - delete &SELF; + delete reinterpret_cast<shared_ptr<Ice::Endpoint>*>(self); return 0; } @@ -161,7 +152,8 @@ Ice_Endpoint_equals(void* self, void* other) assert(other); // Wrapper only calls this function for non-nil arguments. try { - return createResultValue(createBool(Ice::targetEqualTo(SELF, DEREF(other)))); + return createResultValue(createBool(Ice::targetEqualTo(deref<Ice::Endpoint>(self), + deref<Ice::Endpoint>(other)))); } catch(const std::exception& ex) { @@ -174,7 +166,7 @@ Ice_Endpoint_toString(void* self) { try { - return createResultValue(createStringFromUTF8(SELF->toString())); + return createResultValue(createStringFromUTF8(deref<Ice::Endpoint>(self)->toString())); } catch(const std::exception& ex) { @@ -187,7 +179,7 @@ Ice_Endpoint_getInfo(void* self) { try { - shared_ptr<Ice::EndpointInfo> info = SELF->getInfo(); + shared_ptr<Ice::EndpointInfo> info = deref<Ice::Endpoint>(self)->getInfo(); return createResultValue(createInfo(info)); } catch(const std::exception& ex) diff --git a/matlab/src/Endpoint.h b/matlab/src/Endpoint.h index f3c6a4b41ed..f63088d0ea0 100644 --- a/matlab/src/Endpoint.h +++ b/matlab/src/Endpoint.h @@ -13,6 +13,5 @@ namespace IceMatlab { void* createEndpoint(std::shared_ptr<Ice::Endpoint>); -std::shared_ptr<Ice::Endpoint> getEndpoint(void*); } diff --git a/matlab/src/Future.cpp b/matlab/src/Future.cpp index ba53f5b7878..e6568e19789 100644 --- a/matlab/src/Future.cpp +++ b/matlab/src/Future.cpp @@ -100,15 +100,13 @@ IceMatlab::SimpleFuture::isFinished() const return _done || _exception; } -#define SFSELF (*(reinterpret_cast<shared_ptr<SimpleFuture>*>(self))) - extern "C" { mxArray* Ice_SimpleFuture_unref(void* self) { - delete &SFSELF; + delete reinterpret_cast<shared_ptr<SimpleFuture>*>(self); return 0; } @@ -117,7 +115,7 @@ Ice_SimpleFuture_wait(void* self, unsigned char* ok) { // TBD: Timeout? - bool b = SFSELF->waitUntilFinished(); + bool b = deref<SimpleFuture>(self)->waitUntilFinished(); *ok = b ? 1 : 0; return 0; } @@ -125,32 +123,33 @@ Ice_SimpleFuture_wait(void* self, unsigned char* ok) mxArray* Ice_SimpleFuture_state(void* self) { - return createResultValue(createStringFromUTF8(SFSELF->state())); + return createResultValue(createStringFromUTF8(deref<SimpleFuture>(self)->state())); } mxArray* Ice_SimpleFuture_cancel(void* self) { - SFSELF->cancel(); + deref<SimpleFuture>(self)->cancel(); return 0; } mxArray* Ice_SimpleFuture_check(void* self) { - if(!SFSELF->waitUntilFinished()) + auto f = deref<SimpleFuture>(self); + if(!f->waitUntilFinished()) { - assert(SFSELF->getException()); + assert(f->getException()); try { - rethrow_exception(SFSELF->getException()); + rethrow_exception(f->getException()); } catch(const std::exception& ex) { // // The C++ object won't be used after this. // - delete &SFSELF; + delete reinterpret_cast<shared_ptr<SimpleFuture>*>(self); return convertException(ex); } } @@ -158,7 +157,7 @@ Ice_SimpleFuture_check(void* self) // // The C++ object won't be used after this. // - delete &SFSELF; + delete reinterpret_cast<shared_ptr<SimpleFuture>*>(self); return 0; } diff --git a/matlab/src/Init.cpp b/matlab/src/Init.cpp index 3b3a6552ace..9a61f77e7af 100644 --- a/matlab/src/Init.cpp +++ b/matlab/src/Init.cpp @@ -37,11 +37,10 @@ Ice_initialize(mxArray* args, void* propsImpl, void** r) // if(propsImpl) { - id.properties = *(reinterpret_cast<shared_ptr<Ice::Properties>*>(propsImpl)); + id.properties = deref<Ice::Properties>(propsImpl); } - shared_ptr<Ice::Communicator> c = Ice::initialize(a, id); - *r = new shared_ptr<Ice::Communicator>(move(c)); + *r = new shared_ptr<Ice::Communicator>(Ice::initialize(a, id)); return createResultValue(createStringList(a)); } catch(const std::exception& ex) @@ -56,8 +55,7 @@ Ice_stringToIdentity(mxArray* s) { try { - Ice::Identity id = Ice::stringToIdentity(getStringFromUTF16(s)); - return createResultValue(createIdentity(id)); + return createResultValue(createIdentity(Ice::stringToIdentity(getStringFromUTF16(s)))); } catch(const std::exception& ex) { diff --git a/matlab/src/Logger.cpp b/matlab/src/Logger.cpp index 7e7421231c6..104b1789248 100644 --- a/matlab/src/Logger.cpp +++ b/matlab/src/Logger.cpp @@ -11,9 +11,6 @@ #include "Logger.h" #include "Util.h" -#define DEREF(x) (*(reinterpret_cast<shared_ptr<Ice::Logger>*>(x))) -#define SELF DEREF(self) - using namespace std; using namespace IceMatlab; @@ -29,7 +26,7 @@ extern "C" mxArray* Ice_Logger_unref(void* self) { - delete &SELF; + delete reinterpret_cast<shared_ptr<Ice::Logger>*>(self); return 0; } @@ -38,7 +35,7 @@ Ice_Logger_print(void* self, mxArray* message) { try { - SELF->print(getStringFromUTF16(message)); + deref<Ice::Logger>(self)->print(getStringFromUTF16(message)); } catch(const std::exception& ex) { @@ -52,7 +49,7 @@ Ice_Logger_trace(void* self, mxArray* category, mxArray* message) { try { - SELF->trace(getStringFromUTF16(category), getStringFromUTF16(message)); + deref<Ice::Logger>(self)->trace(getStringFromUTF16(category), getStringFromUTF16(message)); } catch(const std::exception& ex) { @@ -66,7 +63,7 @@ Ice_Logger_warning(void* self, mxArray* message) { try { - SELF->warning(getStringFromUTF16(message)); + deref<Ice::Logger>(self)->warning(getStringFromUTF16(message)); } catch(const std::exception& ex) { @@ -80,7 +77,7 @@ Ice_Logger_error(void* self, mxArray* message) { try { - SELF->error(getStringFromUTF16(message)); + deref<Ice::Logger>(self)->error(getStringFromUTF16(message)); } catch(const std::exception& ex) { @@ -94,7 +91,7 @@ Ice_Logger_getPrefix(void* self) { try { - return createResultValue(createStringFromUTF8(SELF->getPrefix())); + return createResultValue(createStringFromUTF8(deref<Ice::Logger>(self)->getPrefix())); } catch(const std::exception& ex) { @@ -104,12 +101,13 @@ Ice_Logger_getPrefix(void* self) } mxArray* -Ice_Logger_cloneWithPrefix(void* self, mxArray* prefix, void** newLogger) +Ice_Logger_cloneWithPrefix(void* self, mxArray* prefix, void** r) { try { - shared_ptr<Ice::Logger> l = SELF->cloneWithPrefix(getStringFromUTF16(prefix)); - *newLogger = l.get() == SELF.get() ? 0 : new shared_ptr<Ice::Logger>(move(l)); + auto logger = deref<Ice::Logger>(self); + auto newLogger = logger->cloneWithPrefix(getStringFromUTF16(prefix)); + *r = newLogger == logger ? 0 : new shared_ptr<Ice::Logger>(move(newLogger)); } catch(const std::exception& ex) { diff --git a/matlab/src/ObjectPrx.cpp b/matlab/src/ObjectPrx.cpp index 65c806b7dab..db6ebb65c0e 100644 --- a/matlab/src/ObjectPrx.cpp +++ b/matlab/src/ObjectPrx.cpp @@ -9,15 +9,11 @@ #include <Ice/Ice.h> #include "ice.h" -#include "Communicator.h" #include "Endpoint.h" #include "Future.h" #include "ObjectPrx.h" #include "Util.h" -#define DEREF(x) (*(reinterpret_cast<shared_ptr<Ice::ObjectPrx>*>(x))) -#define SELF DEREF(self) - using namespace std; using namespace IceMatlab; @@ -51,8 +47,6 @@ private: vector<Ice::Byte> _data; }; -#define IFSELF (*(reinterpret_cast<shared_ptr<InvocationFuture>*>(self))) - InvocationFuture::InvocationFuture(bool twoway, bool batch) : _twoway(twoway), _state(batch ? State::Finished : State::Running), @@ -157,8 +151,6 @@ private: shared_ptr<Ice::Connection> _connection; }; -#define GCFSELF (*(reinterpret_cast<shared_ptr<GetConnectionFuture>*>(self))) - string GetConnectionFuture::state() const { @@ -218,7 +210,7 @@ IceMatlab::createProxy(shared_ptr<Ice::ObjectPrx> p) shared_ptr<Ice::ObjectPrx> IceMatlab::getProxy(void* p) { - return DEREF(p); + return deref<Ice::ObjectPrx>(p); } extern "C" @@ -227,7 +219,7 @@ extern "C" mxArray* Ice_ObjectPrx_unref(void* self) { - delete &SELF; + delete &deref<Ice::ObjectPrx>(self); return 0; } @@ -237,7 +229,8 @@ Ice_ObjectPrx_equals(void* self, void* other) assert(other); // Wrapper only calls this function for non-nil arguments. try { - return createResultValue(createBool(Ice::targetEqualTo(SELF, DEREF(other)))); + return createResultValue(createBool(Ice::targetEqualTo(deref<Ice::ObjectPrx>(self), + deref<Ice::ObjectPrx>(other)))); } catch(const std::exception& ex) { @@ -260,7 +253,7 @@ Ice_ObjectPrx_read(void* communicator, mxArray* encoding, mxArray* buf, int star Ice::EncodingVersion ev; getEncodingVersion(encoding, ev); - Ice::InputStream in(getCommunicator(communicator), ev, p); + Ice::InputStream in(deref<Ice::Communicator>(communicator), ev, p); shared_ptr<Ice::ObjectPrx> proxy; in.read(proxy); if(proxy) @@ -290,11 +283,11 @@ Ice_ObjectPrx_write(void* proxy, void* communicator, mxArray* encoding) shared_ptr<Ice::ObjectPrx> prx; if(proxy) { - prx = DEREF(proxy); + prx = deref<Ice::ObjectPrx>(proxy); } assert(communicator); - shared_ptr<Ice::Communicator> comm = getCommunicator(communicator); + auto comm = deref<Ice::Communicator>(communicator); Ice::EncodingVersion enc; getEncodingVersion(encoding, enc); @@ -329,7 +322,7 @@ Ice_ObjectPrx_ice_invoke(void* self, const char* op, int m, mxArray* inParams, u { Ice::Context ctx; getStringMap(context, ctx); - auto ok = SELF->ice_invoke(op, mode, params, v, ctx); + auto ok = deref<Ice::ObjectPrx>(self)->ice_invoke(op, mode, params, v, ctx); mxArray* results = 0; if(!v.empty()) { @@ -358,7 +351,7 @@ Ice_ObjectPrx_ice_invokeNC(void* self, const char* op, int m, mxArray* inParams, try { - auto ok = SELF->ice_invoke(op, mode, params, v); + auto ok = deref<Ice::ObjectPrx>(self)->ice_invoke(op, mode, params, v); mxArray* results = 0; if(!v.empty()) { @@ -377,7 +370,7 @@ mxArray* Ice_ObjectPrx_ice_invokeAsync(void* self, const char* op, int m, mxArray* inParams, unsigned int size, mxArray* context, void** future) { - const shared_ptr<Ice::ObjectPrx> proxy = SELF; + const auto proxy = deref<Ice::ObjectPrx>(self); pair<const Ice::Byte*, const Ice::Byte*> params(0, 0); if(!mxIsEmpty(inParams)) { @@ -422,7 +415,7 @@ Ice_ObjectPrx_ice_invokeAsync(void* self, const char* op, int m, mxArray* inPara mxArray* Ice_ObjectPrx_ice_invokeAsyncNC(void* self, const char* op, int m, mxArray* inParams, unsigned int size, void** future) { - const shared_ptr<Ice::ObjectPrx> proxy = SELF; + const auto proxy = deref<Ice::ObjectPrx>(self); pair<const Ice::Byte*, const Ice::Byte*> params(0, 0); if(!mxIsEmpty(inParams)) { @@ -465,13 +458,13 @@ Ice_ObjectPrx_ice_invokeAsyncNC(void* self, const char* op, int m, mxArray* inPa mxArray* Ice_ObjectPrx_ice_toString(void* self) { - return createResultValue(createStringFromUTF8(SELF->ice_toString())); + return createResultValue(createStringFromUTF8(deref<Ice::ObjectPrx>(self)->ice_toString())); } mxArray* Ice_ObjectPrx_ice_getIdentity(void* self) { - return createResultValue(createIdentity(SELF->ice_getIdentity())); + return createResultValue(createIdentity(deref<Ice::ObjectPrx>(self)->ice_getIdentity())); } mxArray* @@ -481,8 +474,9 @@ Ice_ObjectPrx_ice_identity(void* self, void** r, mxArray* id) { Ice::Identity ident; getIdentity(id, ident); - auto newProxy = SELF->ice_identity(ident); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_identity(ident); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -494,7 +488,7 @@ Ice_ObjectPrx_ice_identity(void* self, void** r, mxArray* id) mxArray* Ice_ObjectPrx_ice_getContext(void* self) { - return createResultValue(createStringMap(SELF->ice_getContext())); + return createResultValue(createStringMap(deref<Ice::ObjectPrx>(self)->ice_getContext())); } mxArray* @@ -504,8 +498,9 @@ Ice_ObjectPrx_ice_context(void* self, void** r, mxArray* c) { Ice::Context ctx; getStringMap(c, ctx); - auto newProxy = SELF->ice_context(ctx); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_context(ctx); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -517,8 +512,7 @@ Ice_ObjectPrx_ice_context(void* self, void** r, mxArray* c) mxArray* Ice_ObjectPrx_ice_getFacet(void* self) { - auto s = SELF->ice_getFacet(); - return createResultValue(createStringFromUTF8(s)); + return createResultValue(createStringFromUTF8(deref<Ice::ObjectPrx>(self)->ice_getFacet())); } mxArray* @@ -526,8 +520,9 @@ Ice_ObjectPrx_ice_facet(void* self, void** r, const char* f) { try { - auto newProxy = SELF->ice_facet(f); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_facet(f); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -539,8 +534,7 @@ Ice_ObjectPrx_ice_facet(void* self, void** r, const char* f) mxArray* Ice_ObjectPrx_ice_getAdapterId(void* self) { - auto s = SELF->ice_getAdapterId(); - return createResultValue(createStringFromUTF8(s)); + return createResultValue(createStringFromUTF8(deref<Ice::ObjectPrx>(self)->ice_getAdapterId())); } mxArray* @@ -548,8 +542,9 @@ Ice_ObjectPrx_ice_adapterId(void* self, void** r, const char* id) { try { - auto newProxy = SELF->ice_adapterId(id); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_adapterId(id); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -563,7 +558,7 @@ Ice_ObjectPrx_ice_getNumEndpoints(void* self) { try { - return createResultValue(createInt(static_cast<int>(SELF->ice_getEndpoints().size()))); + return createResultValue(createInt(static_cast<int>(deref<Ice::ObjectPrx>(self)->ice_getEndpoints().size()))); } catch(const std::exception& ex) { @@ -576,7 +571,7 @@ Ice_ObjectPrx_ice_getEndpoint(void* self, unsigned int idx, void** r) { try { - auto endpoints = SELF->ice_getEndpoints(); + auto endpoints = deref<Ice::ObjectPrx>(self)->ice_getEndpoints(); if(idx > endpoints.size()) { throw std::invalid_argument("index outside range"); @@ -611,7 +606,7 @@ Ice_ObjectPrx_ice_setEndpoint(void* self, void* arr, unsigned int idx, void* e) { throw std::invalid_argument("index outside range"); } - (*v)[idx] = getEndpoint(e); + (*v)[idx] = deref<Ice::Endpoint>(e); } catch(const std::exception& ex) { @@ -632,8 +627,9 @@ Ice_ObjectPrx_ice_endpoints(void* self, void** r, void* arr) vector<shared_ptr<Ice::Endpoint>>* v = reinterpret_cast<vector<shared_ptr<Ice::Endpoint>>*>(arr); vector<shared_ptr<Ice::Endpoint>> tmp = *v; delete v; - auto newProxy = SELF->ice_endpoints(tmp); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_endpoints(tmp); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -645,7 +641,7 @@ Ice_ObjectPrx_ice_endpoints(void* self, void** r, void* arr) mxArray* Ice_ObjectPrx_ice_getLocatorCacheTimeout(void* self) { - return createResultValue(createInt(SELF->ice_getLocatorCacheTimeout())); + return createResultValue(createInt(deref<Ice::ObjectPrx>(self)->ice_getLocatorCacheTimeout())); } mxArray* @@ -653,8 +649,9 @@ Ice_ObjectPrx_ice_locatorCacheTimeout(void* self, void** r, int t) { try { - auto newProxy = SELF->ice_locatorCacheTimeout(t); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_locatorCacheTimeout(t); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -666,7 +663,7 @@ Ice_ObjectPrx_ice_locatorCacheTimeout(void* self, void** r, int t) mxArray* Ice_ObjectPrx_ice_getInvocationTimeout(void* self) { - return createResultValue(createInt(SELF->ice_getInvocationTimeout())); + return createResultValue(createInt(deref<Ice::ObjectPrx>(self)->ice_getInvocationTimeout())); } mxArray* @@ -674,8 +671,9 @@ Ice_ObjectPrx_ice_invocationTimeout(void* self, void** r, int t) { try { - auto newProxy = SELF->ice_invocationTimeout(t); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_invocationTimeout(t); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -687,7 +685,7 @@ Ice_ObjectPrx_ice_invocationTimeout(void* self, void** r, int t) mxArray* Ice_ObjectPrx_ice_getConnectionId(void* self) { - auto s = SELF->ice_getConnectionId(); + auto s = deref<Ice::ObjectPrx>(self)->ice_getConnectionId(); return createResultValue(createStringFromUTF8(s)); } @@ -696,8 +694,9 @@ Ice_ObjectPrx_ice_connectionId(void* self, void** r, const char* id) { try { - auto newProxy = SELF->ice_connectionId(id); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_connectionId(id); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -709,7 +708,7 @@ Ice_ObjectPrx_ice_connectionId(void* self, void** r, const char* id) mxArray* Ice_ObjectPrx_ice_isConnectionCached(void* self) { - return createResultValue(createBool(SELF->ice_isConnectionCached())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isConnectionCached())); } mxArray* @@ -717,8 +716,9 @@ Ice_ObjectPrx_ice_connectionCached(void* self, void** r, unsigned char v) { try { - auto newProxy = SELF->ice_connectionCached(v == 1); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_connectionCached(v == 1); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -732,8 +732,7 @@ Ice_ObjectPrx_ice_getEndpointSelection(void* self) { try { - auto type = SELF->ice_getEndpointSelection(); - return createResultValue(createInt(static_cast<int>(type))); + return createResultValue(createInt(static_cast<int>(deref<Ice::ObjectPrx>(self)->ice_getEndpointSelection()))); } catch(const std::exception& ex) { @@ -747,9 +746,10 @@ Ice_ObjectPrx_ice_endpointSelection(void* self, void** r, mxArray* type) { try { - auto t = static_cast<Ice::EndpointSelectionType>(getEnumerator(type, "Ice.EndpointSelectionType")); - auto newProxy = SELF->ice_endpointSelection(t); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_endpointSelection( + static_cast<Ice::EndpointSelectionType>(getEnumerator(type, "Ice.EndpointSelectionType"))); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -761,7 +761,7 @@ Ice_ObjectPrx_ice_endpointSelection(void* self, void** r, mxArray* type) mxArray* Ice_ObjectPrx_ice_getEncodingVersion(void* self) { - return createResultValue(createEncodingVersion(SELF->ice_getEncodingVersion())); + return createResultValue(createEncodingVersion(deref<Ice::ObjectPrx>(self)->ice_getEncodingVersion())); } mxArray* @@ -771,8 +771,9 @@ Ice_ObjectPrx_ice_encodingVersion(void* self, void** r, mxArray* v) { Ice::EncodingVersion ev; getEncodingVersion(v, ev); - auto newProxy = SELF->ice_encodingVersion(ev); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_encodingVersion(ev); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -784,7 +785,7 @@ Ice_ObjectPrx_ice_encodingVersion(void* self, void** r, mxArray* v) mxArray* Ice_ObjectPrx_ice_getRouter(void* self, void** r) { - auto router = SELF->ice_getRouter(); + auto router = deref<Ice::ObjectPrx>(self)->ice_getRouter(); *r = router ? new shared_ptr<Ice::ObjectPrx>(move(router)) : 0; return 0; } @@ -797,10 +798,11 @@ Ice_ObjectPrx_ice_router(void* self, void** r, void* rtr) shared_ptr<Ice::ObjectPrx> router; if(rtr) { - router = *(reinterpret_cast<shared_ptr<Ice::ObjectPrx>*>(rtr)); + router = deref<Ice::ObjectPrx>(rtr); } - auto newProxy = SELF->ice_router(Ice::uncheckedCast<Ice::RouterPrx>(router)); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_router(Ice::uncheckedCast<Ice::RouterPrx>(router)); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -812,7 +814,7 @@ Ice_ObjectPrx_ice_router(void* self, void** r, void* rtr) mxArray* Ice_ObjectPrx_ice_getLocator(void* self, void** r) { - auto locator = SELF->ice_getLocator(); + auto locator = deref<Ice::ObjectPrx>(self)->ice_getLocator(); *r = locator ? new shared_ptr<Ice::ObjectPrx>(move(locator)) : 0; return 0; } @@ -825,10 +827,11 @@ Ice_ObjectPrx_ice_locator(void* self, void** r, void* loc) shared_ptr<Ice::ObjectPrx> locator; if(loc) { - locator = *(reinterpret_cast<shared_ptr<Ice::ObjectPrx>*>(loc)); + locator = deref<Ice::ObjectPrx>(loc); } - auto newProxy = SELF->ice_locator(Ice::uncheckedCast<Ice::LocatorPrx>(locator)); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_locator(Ice::uncheckedCast<Ice::LocatorPrx>(locator)); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -840,7 +843,7 @@ Ice_ObjectPrx_ice_locator(void* self, void** r, void* loc) mxArray* Ice_ObjectPrx_ice_isSecure(void* self) { - return createResultValue(createBool(SELF->ice_isSecure())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isSecure())); } mxArray* @@ -848,8 +851,9 @@ Ice_ObjectPrx_ice_secure(void* self, void** r, unsigned char b) { try { - auto newProxy = SELF->ice_secure(b == 1); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_secure(b == 1); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -861,7 +865,7 @@ Ice_ObjectPrx_ice_secure(void* self, void** r, unsigned char b) mxArray* Ice_ObjectPrx_ice_isPreferSecure(void* self) { - return createResultValue(createBool(SELF->ice_isPreferSecure())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isPreferSecure())); } mxArray* @@ -869,8 +873,9 @@ Ice_ObjectPrx_ice_preferSecure(void* self, void** r, unsigned char b) { try { - auto newProxy = SELF->ice_preferSecure(b == 1); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_preferSecure(b == 1); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -882,7 +887,7 @@ Ice_ObjectPrx_ice_preferSecure(void* self, void** r, unsigned char b) mxArray* Ice_ObjectPrx_ice_isTwoway(void* self) { - return createResultValue(createBool(SELF->ice_isTwoway())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isTwoway())); } mxArray* @@ -890,8 +895,9 @@ Ice_ObjectPrx_ice_twoway(void* self, void** r) { try { - auto newProxy = SELF->ice_twoway(); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_twoway(); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -903,7 +909,7 @@ Ice_ObjectPrx_ice_twoway(void* self, void** r) mxArray* Ice_ObjectPrx_ice_isOneway(void* self) { - return createResultValue(createBool(SELF->ice_isOneway())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isOneway())); } mxArray* @@ -911,8 +917,9 @@ Ice_ObjectPrx_ice_oneway(void* self, void** r) { try { - auto newProxy = SELF->ice_oneway(); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_oneway(); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -924,7 +931,7 @@ Ice_ObjectPrx_ice_oneway(void* self, void** r) mxArray* Ice_ObjectPrx_ice_isBatchOneway(void* self) { - return createResultValue(createBool(SELF->ice_isBatchOneway())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isBatchOneway())); } mxArray* @@ -932,8 +939,9 @@ Ice_ObjectPrx_ice_batchOneway(void* self, void** r) { try { - auto newProxy = SELF->ice_batchOneway(); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_batchOneway(); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -945,7 +953,7 @@ Ice_ObjectPrx_ice_batchOneway(void* self, void** r) mxArray* Ice_ObjectPrx_ice_isDatagram(void* self) { - return createResultValue(createBool(SELF->ice_isDatagram())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isDatagram())); } mxArray* @@ -953,8 +961,9 @@ Ice_ObjectPrx_ice_datagram(void* self, void** r) { try { - auto newProxy = SELF->ice_datagram(); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_datagram(); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -966,7 +975,7 @@ Ice_ObjectPrx_ice_datagram(void* self, void** r) mxArray* Ice_ObjectPrx_ice_isBatchDatagram(void* self) { - return createResultValue(createBool(SELF->ice_isBatchDatagram())); + return createResultValue(createBool(deref<Ice::ObjectPrx>(self)->ice_isBatchDatagram())); } mxArray* @@ -974,8 +983,9 @@ Ice_ObjectPrx_ice_batchDatagram(void* self, void** r) { try { - auto newProxy = SELF->ice_batchDatagram(); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_batchDatagram(); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -989,8 +999,9 @@ Ice_ObjectPrx_ice_compress(void* self, void** r, unsigned char b) { try { - auto newProxy = SELF->ice_compress(b == 1); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_compress(b == 1); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -1004,8 +1015,9 @@ Ice_ObjectPrx_ice_timeout(void* self, void** r, int t) { try { - auto newProxy = SELF->ice_timeout(t); - *r = newProxy.get() == SELF.get() ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); + auto proxy = deref<Ice::ObjectPrx>(self); + auto newProxy = proxy->ice_timeout(t); + *r = newProxy == proxy ? 0 : new shared_ptr<Ice::ObjectPrx>(move(newProxy)); } catch(const std::exception& ex) { @@ -1020,7 +1032,7 @@ Ice_ObjectPrx_ice_getConnection(void* self, void** r) *r = 0; try { - auto conn = SELF->ice_getConnection(); + auto conn = deref<Ice::ObjectPrx>(self)->ice_getConnection(); if(conn) { *r = new shared_ptr<Ice::Connection>(move(conn)); @@ -1041,7 +1053,7 @@ Ice_ObjectPrx_ice_getConnectionAsync(void* self, void** future) try { - function<void()> token = SELF->ice_getConnectionAsync( + function<void()> token = deref<Ice::ObjectPrx>(self)->ice_getConnectionAsync( [f](shared_ptr<Ice::Connection> con) { f->finished(con); @@ -1067,7 +1079,7 @@ Ice_ObjectPrx_ice_getCachedConnection(void* self, void** r) *r = 0; try { - auto conn = SELF->ice_getCachedConnection(); + auto conn = deref<Ice::ObjectPrx>(self)->ice_getCachedConnection(); if(conn) { *r = new shared_ptr<Ice::Connection>(move(conn)); @@ -1085,7 +1097,7 @@ Ice_ObjectPrx_ice_flushBatchRequests(void* self) { try { - SELF->ice_flushBatchRequests(); + deref<Ice::ObjectPrx>(self)->ice_flushBatchRequests(); } catch(const std::exception& ex) { @@ -1102,7 +1114,7 @@ Ice_ObjectPrx_ice_flushBatchRequestsAsync(void* self, void** future) try { - function<void()> token = SELF->ice_flushBatchRequestsAsync( + function<void()> token = deref<Ice::ObjectPrx>(self)->ice_flushBatchRequestsAsync( [f](exception_ptr e) { f->exception(e); @@ -1124,15 +1136,14 @@ Ice_ObjectPrx_ice_flushBatchRequestsAsync(void* self, void** future) mxArray* Ice_ObjectPrx_clone(void* self, void** r) { - auto p = SELF; - *r = new shared_ptr<Ice::ObjectPrx>(move(p)); + *r = new shared_ptr<Ice::ObjectPrx>(deref<Ice::ObjectPrx>(self)); return 0; } mxArray* Ice_InvocationFuture_unref(void* self) { - delete &IFSELF; + delete reinterpret_cast<shared_ptr<InvocationFuture>*>(self); return 0; } @@ -1148,7 +1159,7 @@ Ice_InvocationFuture_wait(void* self, unsigned char* ok) { // TBD: Timeout? - bool b = IFSELF->waitUntilFinished(); + bool b = deref<InvocationFuture>(self)->waitUntilFinished(); *ok = b ? 1 : 0; return 0; } @@ -1157,27 +1168,27 @@ mxArray* Ice_InvocationFuture_results(void* self) { // TBD: Timeout? - - if(!IFSELF->waitUntilFinished()) + auto f = deref<InvocationFuture>(self); + if(!f->waitUntilFinished()) { - assert(IFSELF->getException()); + assert(f->getException()); try { - rethrow_exception(IFSELF->getException()); + rethrow_exception(f->getException()); } catch(const std::exception& ex) { // // The C++ object won't be used after this. // - delete &IFSELF; + delete reinterpret_cast<shared_ptr<InvocationFuture>*>(self); return createResultException(convertException(ex)); } } bool ok; pair<const Ice::Byte*, const Ice::Byte*> p; - IFSELF->getResults(ok, p); + f->getResults(ok, p); mxArray* params = 0; if(p.second > p.first) { @@ -1187,7 +1198,7 @@ Ice_InvocationFuture_results(void* self) // // The C++ object won't be used after this. // - delete &IFSELF; + delete reinterpret_cast<shared_ptr<InvocationFuture>*>(self); return createResultValue(createInvokeResultValue(createBool(ok), params)); } @@ -1195,32 +1206,33 @@ Ice_InvocationFuture_results(void* self) mxArray* Ice_InvocationFuture_state(void* self) { - return createResultValue(createStringFromUTF8(IFSELF->state())); + return createResultValue(createStringFromUTF8(deref<InvocationFuture>(self)->state())); } mxArray* Ice_InvocationFuture_cancel(void* self) { - IFSELF->cancel(); + deref<InvocationFuture>(self)->cancel(); return 0; } mxArray* Ice_InvocationFuture_check(void* self) { - if(!IFSELF->waitUntilFinished()) + auto f = deref<InvocationFuture>(self); + if(!f->waitUntilFinished()) { - assert(IFSELF->getException()); + assert(f->getException()); try { - // - // The C++ object won't be used after this. - // - delete &IFSELF; - rethrow_exception(IFSELF->getException()); + rethrow_exception(f->getException()); } catch(const std::exception& ex) { + // + // The C++ object won't be used after this. + // + delete reinterpret_cast<shared_ptr<InvocationFuture>*>(self); return convertException(ex); } } @@ -1228,7 +1240,7 @@ Ice_InvocationFuture_check(void* self) // // The C++ object won't be used after this. // - delete &IFSELF; + delete reinterpret_cast<shared_ptr<InvocationFuture>*>(self); return 0; } @@ -1236,7 +1248,7 @@ Ice_InvocationFuture_check(void* self) mxArray* Ice_GetConnectionFuture_unref(void* self) { - delete &GCFSELF; + delete reinterpret_cast<shared_ptr<GetConnectionFuture>*>(self); return 0; } @@ -1252,7 +1264,7 @@ Ice_GetConnectionFuture_wait(void* self, unsigned char* ok) { // TBD: Timeout? - bool b = GCFSELF->waitUntilFinished(); + bool b = deref<GetConnectionFuture>(self)->waitUntilFinished(); *ok = b ? 1 : 0; return 0; } @@ -1261,32 +1273,32 @@ mxArray* Ice_GetConnectionFuture_fetch(void* self, void** con) { // TBD: Timeout? - - if(!GCFSELF->waitUntilFinished()) + auto f = deref<GetConnectionFuture>(self); + if(!f->waitUntilFinished()) { - assert(GCFSELF->getException()); + assert(f->getException()); try { - rethrow_exception(GCFSELF->getException()); + rethrow_exception(f->getException()); } catch(const std::exception& ex) { // // The C++ object won't be used after this. // - delete &IFSELF; + delete reinterpret_cast<shared_ptr<GetConnectionFuture>*>(self); return convertException(ex); } } - auto c = GCFSELF->getConnection(); + auto c = f->getConnection(); assert(c); *con = new shared_ptr<Ice::Connection>(move(c)); // // The C++ object won't be used after this. // - delete &IFSELF; + delete reinterpret_cast<shared_ptr<GetConnectionFuture>*>(self); return 0; } @@ -1294,13 +1306,13 @@ Ice_GetConnectionFuture_fetch(void* self, void** con) mxArray* Ice_GetConnectionFuture_state(void* self) { - return createResultValue(createStringFromUTF8(GCFSELF->state())); + return createResultValue(createStringFromUTF8(deref<GetConnectionFuture>(self)->state())); } mxArray* Ice_GetConnectionFuture_cancel(void* self) { - GCFSELF->cancel(); + deref<GetConnectionFuture>(self)->cancel(); return 0; } diff --git a/matlab/src/Properties.cpp b/matlab/src/Properties.cpp index d1e923df49a..39b76f58d81 100644 --- a/matlab/src/Properties.cpp +++ b/matlab/src/Properties.cpp @@ -12,8 +12,6 @@ #include "ice.h" #include "Util.h" -#define SELF (*(reinterpret_cast<shared_ptr<Ice::Properties>*>(self))) - using namespace std; using namespace IceMatlab; @@ -34,7 +32,7 @@ Ice_createProperties(mxArray* args, void* defaultsImpl, void** r) shared_ptr<Ice::Properties> def; if(defaultsImpl) { - def = *(reinterpret_cast<shared_ptr<Ice::Properties>*>(defaultsImpl)); + def = deref<Ice::Properties>(defaultsImpl); } auto props = Ice::createProperties(a, def); *r = new shared_ptr<Ice::Properties>(move(props)); @@ -50,7 +48,7 @@ Ice_createProperties(mxArray* args, void* defaultsImpl, void** r) mxArray* Ice_Properties_unref(void* self) { - delete &SELF; + delete reinterpret_cast<shared_ptr<Ice::Properties>*>(self); return 0; } @@ -59,7 +57,7 @@ Ice_Properties_getProperty(void* self, const char* key) { try { - return createResultValue(createStringFromUTF8(SELF->getProperty(key))); + return createResultValue(createStringFromUTF8(deref<Ice::Properties>(self)->getProperty(key))); } catch(const std::exception& ex) { @@ -73,7 +71,7 @@ Ice_Properties_getPropertyWithDefault(void* self, const char* key, const char* d { try { - return createResultValue(createStringFromUTF8(SELF->getPropertyWithDefault(key, dflt))); + return createResultValue(createStringFromUTF8(deref<Ice::Properties>(self)->getPropertyWithDefault(key, dflt))); } catch(const std::exception& ex) { @@ -87,7 +85,7 @@ Ice_Properties_getPropertyAsInt(void* self, const char* key, int* r) { try { - *r = SELF->getPropertyAsInt(key); + *r = deref<Ice::Properties>(self)->getPropertyAsInt(key); } catch(const std::exception& ex) { @@ -101,7 +99,7 @@ Ice_Properties_getPropertyAsIntWithDefault(void* self, const char* key, int dflt { try { - *r = SELF->getPropertyAsIntWithDefault(key, dflt); + *r = deref<Ice::Properties>(self)->getPropertyAsIntWithDefault(key, dflt); } catch(const std::exception& ex) { @@ -115,7 +113,7 @@ Ice_Properties_getPropertyAsList(void* self, const char* key) { try { - auto l = SELF->getPropertyAsList(key); + auto l = deref<Ice::Properties>(self)->getPropertyAsList(key); return createResultValue(createStringList(l)); } catch(const std::exception& ex) @@ -132,7 +130,7 @@ Ice_Properties_getPropertyAsListWithDefault(void* self, const char* key, mxArray { Ice::StringSeq d; getStringList(dflt, d); - Ice::StringSeq l = SELF->getPropertyAsListWithDefault(key, d); + Ice::StringSeq l = deref<Ice::Properties>(self)->getPropertyAsListWithDefault(key, d); return createResultValue(createStringList(l)); } catch(const std::exception& ex) @@ -147,7 +145,7 @@ Ice_Properties_getPropertiesForPrefix(void* self, const char* prefix) { try { - auto d = SELF->getPropertiesForPrefix(prefix); + auto d = deref<Ice::Properties>(self)->getPropertiesForPrefix(prefix); return createResultValue(createStringMap(d)); } catch(const std::exception& ex) @@ -162,7 +160,7 @@ Ice_Properties_setProperty(void* self, const char* key, const char* value) { try { - SELF->setProperty(key, value); + deref<Ice::Properties>(self)->setProperty(key, value); } catch(const std::exception& ex) { @@ -176,7 +174,7 @@ Ice_Properties_getCommandLineOptions(void* self) { try { - auto opts = SELF->getCommandLineOptions(); + auto opts = deref<Ice::Properties>(self)->getCommandLineOptions(); return createResultValue(createStringList(opts)); } catch(const std::exception& ex) @@ -193,7 +191,7 @@ Ice_Properties_parseCommandLineOptions(void* self, const char* prefix, mxArray* { Ice::StringSeq opts; getStringList(options, opts); - Ice::StringSeq rem = SELF->parseCommandLineOptions(prefix, opts); + Ice::StringSeq rem = deref<Ice::Properties>(self)->parseCommandLineOptions(prefix, opts); return createResultValue(createStringList(rem)); } catch(const std::exception& ex) @@ -210,7 +208,7 @@ Ice_Properties_parseIceCommandLineOptions(void* self, mxArray* options) { Ice::StringSeq opts; getStringList(options, opts); - Ice::StringSeq rem = SELF->parseIceCommandLineOptions(opts); + Ice::StringSeq rem = deref<Ice::Properties>(self)->parseIceCommandLineOptions(opts); return createResultValue(createStringList(rem)); } catch(const std::exception& ex) @@ -225,7 +223,7 @@ Ice_Properties_load(void* self, const char* file) { try { - SELF->load(file); + deref<Ice::Properties>(self)->load(file); } catch(const std::exception& ex) { @@ -239,8 +237,7 @@ Ice_Properties_clone(void* self, void** r) { try { - auto c = SELF->clone(); - *r = new shared_ptr<Ice::Properties>(move(c)); + *r = new shared_ptr<Ice::Properties>(deref<Ice::Properties>(self)); } catch(const std::exception& ex) { diff --git a/matlab/src/Util.h b/matlab/src/Util.h index 73e942dd896..836cd4aec38 100644 --- a/matlab/src/Util.h +++ b/matlab/src/Util.h @@ -45,4 +45,10 @@ mxArray* createByteArray(const Ice::Byte*, const Ice::Byte*); std::string idToClass(const std::string&); +template<typename T> +std::shared_ptr<T> deref(void* p) +{ + return *reinterpret_cast<std::shared_ptr<T>*>(p); +} + } |