1 /** 2 Wraps calls to xlXXX "functions" via the Excel4/Excel12 functions 3 */ 4 module xlld.func.xl; 5 6 import xlld.sdk.xlcall: XLOPER12, LPXLOPER12; 7 8 9 /// 10 XLOPER12 coerce(in LPXLOPER12 oper) nothrow @nogc @trusted { 11 import xlld.sdk.framework: Excel12f; 12 import xlld.sdk.xlcall: xlCoerce; 13 14 XLOPER12 coerced; 15 Excel12f(xlCoerce, &coerced, oper); 16 return coerced; 17 } 18 19 /// 20 void free(scope ref const(XLOPER12) oper) nothrow @nogc @trusted { 21 free(&oper); 22 } 23 24 /// 25 void free(scope const(XLOPER12)* oper) nothrow @nogc @trusted { 26 import xlld.sdk.framework: Excel12f; 27 import xlld.sdk.xlcall: xlFree; 28 29 const(XLOPER12)*[1] arg = [oper]; 30 Excel12f(xlFree, null, arg); 31 } 32 33 34 /// 35 struct Coerced { 36 XLOPER12 oper; 37 private bool coerced; 38 39 alias oper this; 40 41 this(inout(XLOPER12)* oper) @safe @nogc nothrow inout { 42 this.oper = coerce(oper); 43 this.coerced = true; 44 } 45 46 this(inout(XLOPER12) oper) @safe @nogc nothrow inout { 47 this.oper = () @trusted { return coerce(&oper); }(); 48 this.coerced = true; 49 } 50 51 ~this() @safe @nogc nothrow { 52 if(coerced) free(oper); 53 } 54 } 55 56 /** 57 Automatically calls xlfFree when destroyed 58 */ 59 struct ScopedOper { 60 XLOPER12 oper; 61 private bool _free; 62 63 alias oper this; 64 65 this(inout(XLOPER12) oper) @safe @nogc nothrow inout { 66 this.oper = oper; 67 _free = true; 68 } 69 70 this(inout(XLOPER12*) oper) @safe @nogc nothrow inout { 71 this.oper = *oper; 72 _free = true; 73 } 74 75 ~this() @safe @nogc nothrow { 76 if(_free) free(oper); 77 } 78 }