]> git.saurik.com Git - cydget.git/commitdiff
Copy the _H template from an older substrate.h.
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 16 Feb 2013 11:38:54 +0000 (11:38 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 16 Feb 2013 11:38:54 +0000 (11:38 +0000)
Handle.hpp [new file with mode: 0644]
Tweak.mm

diff --git a/Handle.hpp b/Handle.hpp
new file mode 100644 (file)
index 0000000..fe7ed0f
--- /dev/null
@@ -0,0 +1,90 @@
+/* Cydget - open-source AwayView plugin multiplexer
+ * Copyright (C) 2009-2012  Jay Freeman (saurik)
+*/
+
+/*
+ *        Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer in the documentation
+ *    and/or other materials provided with the
+ *    distribution.
+ * 3. The name of the author may not be used to endorse
+ *    or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef HANDLE_HPP
+#define HANDLE_HPP
+
+template <typename Type_>
+class _H {
+    typedef _H<Type_> This_;
+
+  private:
+    Type_ *value_;
+
+    _finline void Retain_() {
+        if (value_ != nil)
+            CFRetain((CFTypeRef) value_);
+    }
+
+    _finline void Clear_() {
+        if (value_ != nil)
+            CFRelease((CFTypeRef) value_);
+    }
+
+  public:
+    _finline _H(const This_ &rhs) :
+        value_(rhs.value_ == nil ? nil : (Type_ *) CFRetain((CFTypeRef) rhs.value_))
+    {
+    }
+
+    _finline _H(Type_ *value = NULL, bool mended = false) :
+        value_(value)
+    {
+        if (!mended)
+            Retain_();
+    }
+
+    _finline ~_H() {
+        Clear_();
+    }
+
+    _finline operator Type_ *() const {
+        return value_;
+    }
+
+    _finline This_ &operator =(Type_ *value) {
+        if (value_ != value) {
+            Type_ *old(value_);
+            value_ = value;
+            Retain_();
+            if (old != nil)
+                CFRelease((CFTypeRef) old);
+        } return *this;
+    }
+};
+
+#endif//HANDLE_HPP
index e957efe460ad435b97157bd3609710ce91c9bc66..9c3470befee9c5e517173fe8fd84bb97ce6facf8 100644 (file)
--- a/Tweak.mm
+++ b/Tweak.mm
@@ -46,6 +46,8 @@
 #import <SpringBoard/SBAwayWindow.h>
 #import <SpringBoard/SpringBoard.h>
 
+#include "Handle.hpp"
+
 MSClassHook(SpringBoard)
 
 MSClassHook(SBAwayController)