diff options
Diffstat (limited to 'cpp/include/IceUtil')
-rw-r--r-- | cpp/include/IceUtil/Config.h | 4 | ||||
-rw-r--r-- | cpp/include/IceUtil/CtrlCHandler.h | 4 | ||||
-rw-r--r-- | cpp/include/IceUtil/Exception.h | 137 | ||||
-rw-r--r-- | cpp/include/IceUtil/Options.h | 7 | ||||
-rw-r--r-- | cpp/include/IceUtil/ThreadException.h | 25 | ||||
-rw-r--r-- | cpp/include/IceUtil/UniquePtr.h | 16 |
6 files changed, 147 insertions, 46 deletions
diff --git a/cpp/include/IceUtil/Config.h b/cpp/include/IceUtil/Config.h index 6e8a2ea0b0c..a53cd04abd1 100644 --- a/cpp/include/IceUtil/Config.h +++ b/cpp/include/IceUtil/Config.h @@ -375,7 +375,7 @@ typedef long long Int64; # define ICE_HEARTBEAT_CALLBACK ::std::function<void(const ::std::shared_ptr<::Ice::Connection>&)> # define ICE_IN(...) __VA_ARGS__ # define ICE_EXCEPTION_ISSET(T) T -# define ICE_RETHROW_EXCEPTION(T) ::std::rethrow_exception(T) +# define ICE_RETHROW_EXCEPTION(T) T->ice_throw() # define ICE_RESET_EXCEPTION(T, V) T = V #else // C++98 mapping # define ICE_HANDLE ::IceUtil::Handle @@ -394,7 +394,7 @@ typedef long long Int64; # define ICE_CLOSE_CALLBACK ::Ice::CloseCallbackPtr # define ICE_HEARTBEAT_CALLBACK ::Ice::HeartbeatCallbackPtr # define ICE_IN(...) const __VA_ARGS__& -# define ICE_EXCEPTION_ISSET(T) (T.get() != 0) +# define ICE_EXCEPTION_ISSET(T) T # define ICE_RETHROW_EXCEPTION(T) T->ice_throw() # define ICE_RESET_EXCEPTION(T,V) T.reset(V) #endif diff --git a/cpp/include/IceUtil/CtrlCHandler.h b/cpp/include/IceUtil/CtrlCHandler.h index e5692d96990..0659033303a 100644 --- a/cpp/include/IceUtil/CtrlCHandler.h +++ b/cpp/include/IceUtil/CtrlCHandler.h @@ -55,16 +55,16 @@ public: CtrlCHandlerCallback getCallback() const; }; -class ICE_API CtrlCHandlerException : public Exception +class ICE_API CtrlCHandlerException : public ExceptionHelper<CtrlCHandlerException> { public: CtrlCHandlerException(const char*, int); virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual CtrlCHandlerException* ice_clone() const; #endif - virtual void ice_throw() const; }; } diff --git a/cpp/include/IceUtil/Exception.h b/cpp/include/IceUtil/Exception.h index 2e9dd34af3f..e7e6a21a52f 100644 --- a/cpp/include/IceUtil/Exception.h +++ b/cpp/include/IceUtil/Exception.h @@ -25,13 +25,13 @@ public: Exception(); Exception(const char*, int); #ifndef ICE_CPP11_COMPILER - virtual ~Exception() throw(); + virtual ~Exception() throw() = 0; #endif virtual std::string ice_id() const = 0; virtual void ice_print(std::ostream&) const; virtual const char* what() const ICE_NOEXCEPT; #ifdef ICE_CPP11_MAPPING - std::exception_ptr ice_clone() const; + std::unique_ptr<Exception> ice_clone() const; #else virtual Exception* ice_clone() const = 0; ICE_DEPRECATED_API("ice_name() is deprecated, use ice_id() instead.") @@ -43,6 +43,12 @@ public: int ice_line() const; std::string ice_stackTrace() const; +protected: + +#ifdef ICE_CPP11_MAPPING + virtual Exception* ice_cloneImpl() const = 0; +#endif + private: const char* _file; @@ -53,36 +59,87 @@ private: ICE_API std::ostream& operator<<(std::ostream&, const Exception&); -class ICE_API NullHandleException : public Exception + +#ifdef ICE_CPP11_MAPPING + +template<typename E, typename B = Exception> +class ExceptionHelper : public B { public: - NullHandleException(const char*, int); -#ifndef ICE_CPP11_COMPILER - virtual ~NullHandleException() throw(); + using B::B; + + std::unique_ptr<E> ice_clone() const + { + return std::unique_ptr<E>(static_cast<E*>(ice_cloneImpl())); + } + + virtual void ice_throw() const override + { + throw static_cast<const E&>(*this); + } + +protected: + + virtual Exception* ice_cloneImpl() const override + { + return new E(static_cast<const E&>(*this)); + } +}; + +#else // C++98 mapping + +template<typename E> +class ExceptionHelper : public Exception +{ +public: + + ExceptionHelper() + { + } + + ExceptionHelper(const char* file, int line) : Exception(file, line) + { + } + + virtual void ice_throw() const + { + throw static_cast<const E&>(*this); + } +}; + #endif + + +class ICE_API NullHandleException : public ExceptionHelper<NullHandleException> +{ +public: + + NullHandleException(const char*, int); virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual NullHandleException* ice_clone() const; #endif - virtual void ice_throw() const; }; -class ICE_API IllegalArgumentException : public Exception +class ICE_API IllegalArgumentException : public ExceptionHelper<IllegalArgumentException> { public: IllegalArgumentException(const char*, int); IllegalArgumentException(const char*, int, const std::string&); + #ifndef ICE_CPP11_COMPILER virtual ~IllegalArgumentException() throw(); #endif + virtual std::string ice_id() const; virtual void ice_print(std::ostream&) const; + #ifndef ICE_CPP11_MAPPING virtual IllegalArgumentException* ice_clone() const; #endif - virtual void ice_throw() const; std::string reason() const; @@ -94,40 +151,48 @@ private: // // IllegalConversionException is raised to report a string conversion error // -class ICE_API IllegalConversionException : public Exception +class ICE_API IllegalConversionException : public ExceptionHelper<IllegalConversionException> { public: IllegalConversionException(const char*, int); IllegalConversionException(const char*, int, const std::string&); + #ifndef ICE_CPP11_COMPILER virtual ~IllegalConversionException() throw(); #endif + virtual std::string ice_id() const; virtual void ice_print(std::ostream&) const; + #ifndef ICE_CPP11_MAPPING virtual IllegalConversionException* ice_clone() const; #endif - virtual void ice_throw() const; std::string reason() const; + private: const std::string _reason; }; -class ICE_API SyscallException : public Exception +class ICE_API SyscallException : public ExceptionHelper<SyscallException> { public: SyscallException(const char*, int, int); + +#ifndef ICE_CPP11_COMPILER + virtual ~SyscallException() throw(); +#endif + virtual std::string ice_id() const; virtual void ice_print(std::ostream&) const; + #ifndef ICE_CPP11_MAPPING virtual SyscallException* ice_clone() const; #endif - virtual void ice_throw() const; int error() const; @@ -136,20 +201,49 @@ private: const int _error; }; -class ICE_API FileLockException : public Exception + +#ifdef ICE_CPP11_MAPPING + +template<typename E> +using SyscallExceptionHelper = ExceptionHelper<E, SyscallException>; + +#else // C++98 mapping + +template<typename E> +class SyscallExceptionHelper : public SyscallException +{ +public: + + SyscallExceptionHelper(const char* file, int line, int errorCode) : + SyscallException(file, line, errorCode) + { + } + + virtual void ice_throw() const + { + throw static_cast<const E&>(*this); + } +}; + +#endif + + +class ICE_API FileLockException : public ExceptionHelper<FileLockException> { public: FileLockException(const char*, int, int, const std::string&); + #ifndef ICE_CPP11_COMPILER virtual ~FileLockException() throw(); #endif + virtual std::string ice_id() const; virtual void ice_print(std::ostream&) const; + #ifndef ICE_CPP11_MAPPING virtual FileLockException* ice_clone() const; #endif - virtual void ice_throw() const; std::string path() const; int error() const; @@ -160,36 +254,35 @@ private: std::string _path; }; -class ICE_API OptionalNotSetException : public Exception +class ICE_API OptionalNotSetException : public ExceptionHelper<OptionalNotSetException> { public: OptionalNotSetException(const char*, int); -#ifndef ICE_CPP11_COMPILER - virtual ~OptionalNotSetException() throw(); -#endif virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual OptionalNotSetException* ice_clone() const; #endif - virtual void ice_throw() const; }; #ifndef _WIN32 -class ICE_API IconvInitializationException : public Exception +class ICE_API IconvInitializationException : public ExceptionHelper<IconvInitializationException> { public: IconvInitializationException(const char*, int, const std::string&); + #ifndef ICE_CPP11_COMPILER virtual ~IconvInitializationException() throw(); #endif + virtual std::string ice_id() const; virtual void ice_print(std::ostream&) const; + #ifndef ICE_CPP11_MAPPING virtual IconvInitializationException* ice_clone() const; #endif - virtual void ice_throw() const; std::string reason() const; diff --git a/cpp/include/IceUtil/Options.h b/cpp/include/IceUtil/Options.h index 63301165295..ffae862f88b 100644 --- a/cpp/include/IceUtil/Options.h +++ b/cpp/include/IceUtil/Options.h @@ -22,7 +22,7 @@ namespace IceUtilInternal { -class ICE_API APIException : public IceUtil::Exception +class ICE_API APIException : public IceUtil::ExceptionHelper<APIException> { public: @@ -35,14 +35,13 @@ public: #ifndef ICE_CPP11_MAPPING virtual APIException* ice_clone() const; #endif - virtual void ice_throw() const; ::std::string reason; }; ICE_API ::std::ostream& operator<<(::std::ostream&, const APIException&); -class ICE_API BadOptException : public IceUtil::Exception +class ICE_API BadOptException : public IceUtil::ExceptionHelper<BadOptException> { public: @@ -52,10 +51,10 @@ public: #endif virtual ::std::string ice_id() const; virtual void ice_print(std::ostream&) const; + #ifndef ICE_CPP11_MAPPING virtual BadOptException* ice_clone() const; #endif - virtual void ice_throw() const; ::std::string reason; }; diff --git a/cpp/include/IceUtil/ThreadException.h b/cpp/include/IceUtil/ThreadException.h index 8f380206d5c..2e0756938eb 100644 --- a/cpp/include/IceUtil/ThreadException.h +++ b/cpp/include/IceUtil/ThreadException.h @@ -16,77 +16,78 @@ namespace IceUtil { -class ICE_API ThreadSyscallException : public SyscallException +class ICE_API ThreadSyscallException : public SyscallExceptionHelper<ThreadSyscallException> { public: ThreadSyscallException(const char*, int, int); virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual ThreadSyscallException* ice_clone() const; #endif - virtual void ice_throw() const; }; -class ICE_API ThreadLockedException : public Exception +class ICE_API ThreadLockedException : public ExceptionHelper<ThreadLockedException> { public: ThreadLockedException(const char*, int); virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual ThreadLockedException* ice_clone() const; #endif - virtual void ice_throw() const; }; -class ICE_API ThreadStartedException : public Exception +class ICE_API ThreadStartedException : public ExceptionHelper<ThreadStartedException> { public: ThreadStartedException(const char*, int); virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual ThreadStartedException* ice_clone() const; #endif - virtual void ice_throw() const; + }; -class ICE_API ThreadNotStartedException : public Exception +class ICE_API ThreadNotStartedException : public ExceptionHelper<ThreadNotStartedException> { public: ThreadNotStartedException(const char*, int); virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual ThreadNotStartedException* ice_clone() const; #endif - virtual void ice_throw() const; }; -class ICE_API BadThreadControlException : public Exception +class ICE_API BadThreadControlException : public ExceptionHelper<BadThreadControlException> { public: BadThreadControlException(const char*, int); virtual std::string ice_id() const; + #ifndef ICE_CPP11_MAPPING virtual BadThreadControlException* ice_clone() const; #endif - virtual void ice_throw() const; }; -class ICE_API InvalidTimeoutException : public Exception +class ICE_API InvalidTimeoutException : public ExceptionHelper<InvalidTimeoutException> { public: InvalidTimeoutException(const char*, int, const Time&); virtual std::string ice_id() const; virtual void ice_print(std::ostream&) const; + #ifndef ICE_CPP11_MAPPING virtual InvalidTimeoutException* ice_clone() const; #endif - virtual void ice_throw() const; private: diff --git a/cpp/include/IceUtil/UniquePtr.h b/cpp/include/IceUtil/UniquePtr.h index e58f32fd608..0a81df47fad 100644 --- a/cpp/include/IceUtil/UniquePtr.h +++ b/cpp/include/IceUtil/UniquePtr.h @@ -15,11 +15,12 @@ namespace IceUtil { -// -// This is temporary and very partial placeholder for std::unique_ptr, -// which is not yet widely available. -// +#ifdef ICE_CPP11_MAPPING +template<typename T> +using UniquePtr = std::unique_ptr<T>; + +#else template<typename T> class UniquePtr @@ -84,6 +85,11 @@ public: return _ptr; } + operator bool() const + { + return _ptr != 0; + } + void swap(UniquePtr& a) { T* tmp = a._ptr; @@ -96,6 +102,8 @@ private: T* _ptr; }; +#endif + } // End of namespace IceUtil #endif |