From 47bff1c8a3defeabdf18453142cfb7ac5c4b2440 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 1 Aug 2021 07:07:38 -0400 Subject: ext_depends updates: d-yaml & d2sqlite3 --- src/ext_depends/D-YAML/.travis.yml | 41 ----------- src/ext_depends/D-YAML/source/dyaml/node.d | 105 +++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 46 deletions(-) delete mode 100644 src/ext_depends/D-YAML/.travis.yml (limited to 'src/ext_depends/D-YAML') diff --git a/src/ext_depends/D-YAML/.travis.yml b/src/ext_depends/D-YAML/.travis.yml deleted file mode 100644 index 7e284b6..0000000 --- a/src/ext_depends/D-YAML/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -dist: xenial -sudo: false - -language: d -os: - - linux -d: - - dmd - - ldc - -branches: - only: - - master - -before_install: - - sudo apt-get install python3-pip python3-setuptools - - pip3 install 'meson==0.48.2' - -install: - - mkdir .ntmp && curl -L https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip -o .ntmp/ninja-linux.zip - - unzip .ntmp/ninja-linux.zip -d .ntmp - -before_script: - - export PATH=$PATH:$PWD/.ntmp - -script: - - meson build && ninja -j8 -C build - - ninja -j8 -C build test -v - - dub build - - "dub build dyaml:benchmark" - - "dub build dyaml:constructor" - - "dub build dyaml:getting-started" - - "dub build dyaml:representer" - - "dub build dyaml:resolver" - - "dub build dyaml:testsuite" - - "dub build dyaml:tojson" - - "dub build dyaml:yaml_gen" - - "dub build dyaml:yaml_stats" - - dub test --build=unittest-cov -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/src/ext_depends/D-YAML/source/dyaml/node.d b/src/ext_depends/D-YAML/source/dyaml/node.d index 24a62a4..5cb318e 100644 --- a/src/ext_depends/D-YAML/source/dyaml/node.d +++ b/src/ext_depends/D-YAML/source/dyaml/node.d @@ -498,17 +498,17 @@ struct Node * the value is out of range of requested type. */ inout(T) get(T, Flag!"stringConversion" stringConversion = Yes.stringConversion)() inout - if (allowed!(Unqual!T) || hasNodeConstructor!(Unqual!T)) + if (allowed!(Unqual!T) || hasNodeConstructor!(inout(Unqual!T)) || (!hasIndirections!(Unqual!T) && hasNodeConstructor!(Unqual!T))) { if(isType!(Unqual!T)){return getValue!T;} static if(!allowed!(Unqual!T)) { - static if (hasSimpleNodeConstructor!T) + static if (hasSimpleNodeConstructor!(Unqual!T) || hasSimpleNodeConstructor!(inout(Unqual!T))) { alias params = AliasSeq!(this); } - else static if (hasExpandedNodeConstructor!T) + else static if (hasExpandedNodeConstructor!(Unqual!T) || hasExpandedNodeConstructor!(inout(Unqual!T))) { alias params = AliasSeq!(this, tag_); } @@ -592,6 +592,35 @@ struct Node ". Expected: " ~ typeid(T).toString, startMark_); } } + /// ditto + T get(T)() const + if (hasIndirections!(Unqual!T) && hasNodeConstructor!(Unqual!T) && (!hasNodeConstructor!(inout(Unqual!T)))) + { + static if (hasSimpleNodeConstructor!T) + { + alias params = AliasSeq!(this); + } + else static if (hasExpandedNodeConstructor!T) + { + alias params = AliasSeq!(this, tag_); + } + else + { + static assert(0, "Unknown Node constructor?"); + } + static if (is(T == class)) + { + return new T(params); + } + else static if (is(T == struct)) + { + return T(params); + } + else + { + static assert(0, "Unhandled user type"); + } + } /// Automatic type conversion @safe unittest { @@ -2469,7 +2498,7 @@ template hasSimpleNodeConstructor(T) } else static if (is(T == class)) { - enum hasSimpleNodeConstructor = is(typeof(new inout T(Node.init))); + enum hasSimpleNodeConstructor = is(typeof(new T(Node.init))); } else enum hasSimpleNodeConstructor = false; } @@ -2481,8 +2510,74 @@ template hasExpandedNodeConstructor(T) } else static if (is(T == class)) { - enum hasExpandedNodeConstructor = is(typeof(new inout T(Node.init, ""))); + enum hasExpandedNodeConstructor = is(typeof(new T(Node.init, ""))); } else enum hasExpandedNodeConstructor = false; } enum castableToNode(T) = (is(T == struct) || is(T == class)) && is(typeof(T.opCast!Node()) : Node); + +@safe unittest +{ + import dyaml : Loader, Node; + + static struct Foo + { + string[] bars; + + this(const Node node) + { + foreach(value; node["bars"].sequence) + { + bars ~= value.as!string; + } + } + } + + Loader.fromString(`{ bars: ["a", "b"] }`) + .load + .as!(Foo); +} +@safe unittest +{ + import dyaml : Loader, Node; + import std : split, to; + + static class MyClass + { + int x, y, z; + + this(Node node) + { + auto parts = node.as!string().split(":"); + x = parts[0].to!int; + y = parts[1].to!int; + z = parts[2].to!int; + } + } + + auto loader = Loader.fromString(`"1:2:3"`); + Node node = loader.load(); + auto mc = node.get!MyClass; +} +@safe unittest +{ + import dyaml : Loader, Node; + import std : split, to; + + static class MyClass + { + int x, y, z; + + this(Node node) + { + auto parts = node.as!string().split(":"); + x = parts[0].to!int; + y = parts[1].to!int; + z = parts[2].to!int; + } + } + + auto loader = Loader.fromString(`"1:2:3"`); + const node = loader.load(); + auto mc = node.get!MyClass; +} -- cgit v1.2.3