summaryrefslogtreecommitdiff
path: root/dmagick/Exception.d
diff options
context:
space:
mode:
authorMike Wey2011-05-07 16:32:37 +0200
committerMike Wey2011-05-07 16:32:37 +0200
commit60f11f1fdd1e428f3e2203c2723cf7c7a282e561 (patch)
treeed8fed4c44941ef2d77c10500358530eb2488c77 /dmagick/Exception.d
parent4c6d40489dc87932350b856891d0aa92e2ac18ad (diff)
Use a struct/struct destructors to wrap ImageMagick Exception handling.
Diffstat (limited to 'dmagick/Exception.d')
-rw-r--r--dmagick/Exception.d60
1 files changed, 60 insertions, 0 deletions
diff --git a/dmagick/Exception.d b/dmagick/Exception.d
index 3c89d3c..da05832 100644
--- a/dmagick/Exception.d
+++ b/dmagick/Exception.d
@@ -135,3 +135,63 @@ mixin(
return exceptions;
}());
+/**
+ * This struct is used to wrap the ImageMagick exception handling.
+ * Needs dmd >= 2.053
+ * Usage:
+ * --------------------
+ * CFunctionCall(param1, param2, DExceptionInfo());
+ * --------------------
+ */
+struct DMagickExcepionInfo
+{
+ ExceptionInfo* exceptionInfo;
+
+ private bool isInitialized;
+ private size_t* refcount;
+
+ alias exceptionInfo this;
+
+ static DMagickExcepionInfo opCall()
+ {
+ DMagickExcepionInfo info;
+
+ info.exceptionInfo = AcquireExceptionInfo();
+ info.refcount = new size_t;
+
+ *(info.refcount) = 1;
+ info.isInitialized = true;
+
+ return info;
+ }
+
+ this(this)
+ {
+ if ( isInitialized )
+ (*refcount)++;
+ }
+
+ ~this()
+ {
+ if ( !isInitialized )
+ return;
+
+ (*refcount)--;
+
+ if ( *refcount == 0 )
+ {
+ DMagickException.throwException(exceptionInfo);
+ exceptionInfo = DestroyExceptionInfo(exceptionInfo);
+ }
+ }
+}
+
+unittest
+{
+ void testDMagickExcepionInfo(ExceptionInfo* info)
+ {
+ assert(info !is null);
+ }
+
+ testDMagickExcepionInfo(DMagickExceptionInfo());
+}