summaryrefslogtreecommitdiff
path: root/cpp/src/IceSSL/Util.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceSSL/Util.h')
-rw-r--r--cpp/src/IceSSL/Util.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/cpp/src/IceSSL/Util.h b/cpp/src/IceSSL/Util.h
index ed706a6973e..fc6af1020cc 100644
--- a/cpp/src/IceSSL/Util.h
+++ b/cpp/src/IceSSL/Util.h
@@ -109,6 +109,63 @@ std::string getSslErrors(bool);
#elif defined(ICE_USE_SECURE_TRANSPORT)
+template<typename T>
+class UniqueRef
+{
+public:
+
+ explicit UniqueRef(CFTypeRef ptr = 0) : _ptr((T)ptr)
+ {
+ }
+
+ ~UniqueRef()
+ {
+ if(_ptr != 0)
+ {
+ CFRelease(_ptr);
+ }
+ }
+
+ T release()
+ {
+ T r = _ptr;
+ _ptr = 0;
+ return r;
+ }
+
+ void reset(CFTypeRef ptr = 0)
+ {
+ if(_ptr == ptr)
+ {
+ return;
+ }
+ if(_ptr != 0)
+ {
+ CFRelease(_ptr);
+ }
+ _ptr = (T)ptr;
+ }
+
+ void retain(CFTypeRef ptr)
+ {
+ reset(ptr ? CFRetain(ptr) : ptr);
+ }
+
+ T get() const
+ {
+ return _ptr;
+ }
+
+ operator bool() const
+ {
+ return _ptr != 0;
+ }
+
+private:
+
+ T _ptr;
+};
+
//
// Helper functions to use by Secure Transport.
//