1 module xlld.any; 2 3 4 struct Any { 5 import xlld.xlcall: XLOPER12; 6 7 XLOPER12 _impl; 8 alias _impl this; 9 10 version(unittest) { 11 12 bool opEquals(Any other) @trusted const { 13 import xlld.xlcall: XlType; 14 import xlld.wrap: fromXlOper; 15 16 switch(_impl.xltype) { 17 18 default: 19 return _impl == other._impl; 20 21 case XlType.xltypeStr: 22 23 import std.experimental.allocator.gc_allocator: GCAllocator; 24 return _impl.fromXlOper!(string)(GCAllocator.instance) == 25 other._impl.fromXlOper!(string)(GCAllocator.instance); 26 27 case XlType.xltypeMulti: 28 29 if(_impl.val.array.rows != other._impl.val.array.rows) return false; 30 if(_impl.val.array.columns != other._impl.val.array.columns) return false; 31 32 int i; 33 foreach(r; 0 .. _impl.val.array.rows) { 34 foreach(c; 0 .. _impl.val.array.columns) { 35 if(Any(cast(XLOPER12)_impl.val.array.lparray[i]) != 36 Any(cast(XLOPER12)other._impl.val.array.lparray[i])) 37 return false; 38 ++i; 39 } 40 } 41 42 return true; 43 } 44 } 45 } 46 47 48 string toString() @safe const { 49 import std.conv: text, to; 50 import xlld.xlcall: XlType; 51 import xlld.wrap: fromXlOper; 52 import xlld.xlcall: xlbitXLFree, xlbitDLLFree; 53 import std.experimental.allocator.gc_allocator: GCAllocator; 54 55 alias allocator = GCAllocator.instance; 56 57 string ret = text("Any(", ); 58 const type = _impl.xltype & ~(xlbitXLFree | xlbitDLLFree); 59 switch(type) { 60 default: 61 ret ~= type.to!string; 62 break; 63 case XlType.xltypeStr: 64 ret ~= () @trusted { return text(`"`, _impl.fromXlOper!string(allocator), `"`); }(); 65 break; 66 case XlType.xltypeNum: 67 ret ~= () @trusted { return _impl.fromXlOper!double(allocator).to!string; }(); 68 break; 69 case XlType.xltypeMulti: 70 int i; 71 ret ~= `[`; 72 const rows = () @trusted { return _impl.val.array.rows; }(); 73 const cols = () @trusted { return _impl.val.array.columns; }(); 74 foreach(r; 0 .. rows) { 75 ret ~= `[`; 76 foreach(c; 0 .. cols) { 77 auto oper = () @trusted { return _impl.val.array.lparray[i++]; }(); 78 ret ~= text(Any(cast(XLOPER12)oper), `, `); 79 } 80 ret ~= `]`; 81 } 82 ret ~= `]`; 83 break; 84 } 85 return ret ~ ")"; 86 } 87 } 88 89 90 auto any(T, A)(auto ref T value, auto ref A allocator) @trusted { 91 import xlld.wrap: toXlOper; 92 return Any(value.toXlOper(allocator)); 93 }