forked from CyberShadow/ae
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from FeepingCreature/xml
pull up to origin, add some xml functionality
- Loading branch information
Showing
15 changed files
with
552 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
install: | ||
# cinst dmd --version=2.071.0 | ||
- ps: Start-FileDownload 'http://downloads.dlang.org/releases/2.x/2.071.0/dmd.2.071.0.windows.7z' -FileName 'dmd2.7z' | ||
- ps: Start-FileDownload 'http://downloads.dlang.org/releases/2.x/2.073.1/dmd.2.073.1.windows.7z' -FileName 'dmd2.7z' | ||
- 7z x dmd2.7z > nul | ||
- set PATH=%CD%\dmd2\windows\bin;%CD%\dmd2\windows\bin64;%PATH% | ||
- dmd.exe --version | ||
# Dub | ||
- cinst dub | ||
- dub.exe --version | ||
build_script: | ||
- dub test --arch=x86 | ||
- call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64 | ||
- dub test --arch=x86_64 | ||
- call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86 | ||
- set DFLAGS=-m32mscoff | ||
- dub test --arch=x86 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
if [ $# -eq 0 ] | ||
then | ||
echo "Please specify the ae folder name." | ||
exit | ||
fi | ||
|
||
rm ae.zip || true | ||
rm -rf "$1"|| true | ||
mkdir -p "$1"/src/ae | ||
cp .travis.yml appveyor.yml dub.json README.md "$1" | ||
cp -r utils "$1"/src/ae/ | ||
zip -r "$1".zip "$1" | ||
rm -rf "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,7 @@ public import ae.utils.meta.binding; | |
|
||
// ************************************************************************ | ||
|
||
import std.algorithm; | ||
import std.range; | ||
import std.string; | ||
import std.traits; | ||
import std.typetuple; | ||
|
||
/** | ||
* Same as TypeTuple, but meant to be used with values. | ||
|
@@ -79,6 +75,8 @@ unittest | |
template expand(alias arr, size_t offset = 0) | ||
if (isStaticArray!(typeof(arr))) | ||
{ | ||
import std.typetuple : AliasSeq; | ||
|
||
static if (arr.length == offset) | ||
alias expand = AliasSeq!(); | ||
else | ||
|
@@ -206,10 +204,15 @@ template enumLength(T) | |
deprecated alias EnumLength = enumLength; | ||
|
||
/// A range that iterates over all members of an enum. | ||
@property auto enumIota(T)() { return iota(T.init, enumLength!T); } | ||
@property auto enumIota(T)() | ||
{ | ||
import std.range : iota; | ||
return iota(T.init, enumLength!T); | ||
} | ||
|
||
unittest | ||
{ | ||
import std.algorithm.comparison : equal; | ||
enum E { a, b, c } | ||
static assert(equal(enumIota!E, [E.a, E.b, E.c])); | ||
} | ||
|
@@ -233,24 +236,44 @@ static template stringofArray(Args...) | |
/// "names" can contain multiple names separated by slashes. | ||
static size_t findParameter(alias fun, string names)() | ||
{ | ||
import std.array : split; | ||
|
||
foreach (name; names.split("/")) | ||
foreach (i, param; ParameterIdentifierTuple!fun) | ||
if (param == name) | ||
return i; | ||
assert(false, "Function " ~ __traits(identifier, fun) ~ " doesn't have a parameter called " ~ name); | ||
assert(false, "Function " ~ __traits(identifier, fun) ~ " doesn't have a parameter called " ~ names); | ||
} | ||
|
||
/// ditto | ||
// Workaround for no "static alias" template parameters | ||
static size_t findParameter()(string[] searchedNames, string soughtNames, string funName) | ||
{ | ||
import std.array : split; | ||
|
||
foreach (soughtName; soughtNames.split("/")) | ||
{ | ||
import std.algorithm.searching : countUntil; | ||
|
||
auto targetIndex = searchedNames.countUntil(soughtName); | ||
if (targetIndex >= 0) | ||
return targetIndex; | ||
} | ||
assert(false, "No argument %s in %s's parameters (%s)".format(soughtNames, funName, searchedNames).idup); | ||
|
||
{ | ||
import std.format : format; | ||
|
||
assert(false, "No argument %s in %s's parameters (%s)" | ||
.format(soughtNames, funName, searchedNames).idup); | ||
} | ||
} | ||
|
||
unittest | ||
{ | ||
static void fun(int a, int b, int c) {} | ||
|
||
static assert(findParameter!(fun, "x/c") == 2); | ||
assert(findParameter(["a", "b", "c"], "x/c", "fun") == 2); | ||
} | ||
|
||
/// Generates a function which passes its arguments to a struct, which is | ||
|
@@ -259,6 +282,12 @@ template structFun(S) | |
{ | ||
string gen() | ||
{ | ||
import std.algorithm.iteration : map; | ||
import std.array : join; | ||
import std.format : format; | ||
import std.meta : staticMap; | ||
import std.range : iota; | ||
|
||
enum identifierAt(int n) = __traits(identifier, S.tupleof[n]); | ||
enum names = [staticMap!(identifierAt, RangeTuple!(S.tupleof.length))]; | ||
|
||
|
@@ -286,6 +315,52 @@ unittest | |
assert(test.b == 42); | ||
} | ||
|
||
/// Evaluate all arguments and return the last argument. | ||
/// Can be used instead of the comma operator. | ||
/// Inspired by http://clhs.lisp.se/Body/s_progn.htm | ||
Args[$-1] progn(Args...)(lazy Args args) | ||
{ | ||
foreach (n; RangeTuple!(Args.length-1)) | ||
cast(void)args[n]; | ||
return args[$-1]; | ||
} | ||
|
||
unittest | ||
{ | ||
// Test that expressions are correctly evaluated exactly once. | ||
int a, b, c, d; | ||
d = progn(a++, b++, c++); | ||
assert(a==1 && b==1 && c == 1 && d == 0); | ||
d = progn(a++, b++, ++c); | ||
assert(a==2 && b==2 && c == 2 && d == 2); | ||
} | ||
|
||
unittest | ||
{ | ||
// Test void expressions. | ||
int a, b; | ||
void incA() { a++; } | ||
void incB() { b++; } | ||
progn(incA(), incB()); | ||
assert(a == 1 && b == 1); | ||
} | ||
|
||
/// Like progn, but return the first argument instead. | ||
Args[0] prog1(Args...)(lazy Args args) | ||
{ | ||
auto result = args[0]; | ||
foreach (n; RangeTuple!(Args.length-1)) | ||
cast(void)args[1+n]; | ||
return result; | ||
} | ||
|
||
unittest | ||
{ | ||
int a = 10, b = 20, c = 30; | ||
int d = prog1(a++, b++, c++); | ||
assert(a==11 && b==21 && c == 31 && d == 10); | ||
} | ||
|
||
// ************************************************************************ | ||
|
||
// Using a compiler with UDA support? | ||
|
@@ -371,7 +446,7 @@ else | |
|
||
/// Generate constructors that simply call the parent class constructors. | ||
/// Based on http://forum.dlang.org/post/[email protected] | ||
mixin template GenerateContructorProxies() | ||
mixin template GenerateConstructorProxies() | ||
{ | ||
mixin(() { | ||
import std.conv : text; | ||
|
@@ -397,6 +472,8 @@ mixin template GenerateContructorProxies() | |
} ()); | ||
} | ||
|
||
deprecated alias GenerateContructorProxies = GenerateConstructorProxies; | ||
|
||
unittest | ||
{ | ||
class A | ||
|
@@ -409,7 +486,7 @@ unittest | |
|
||
class B : A | ||
{ | ||
mixin GenerateContructorProxies; | ||
mixin GenerateConstructorProxies; | ||
} | ||
|
||
A a; | ||
|
@@ -552,6 +629,26 @@ static assert(is(ResizeNumericType!(float, double.mant_dig) == double)); | |
alias ExpandNumericType(T, uint additionalBits) = | ||
ResizeNumericType!(T, valueBits!T + additionalBits); | ||
|
||
/// Like ExpandNumericType, but do not error if the resulting type is | ||
/// too large to fit any native D type - just expand to the largest | ||
/// type of the same kind instead. | ||
template TryExpandNumericType(T, uint additionalBits) | ||
{ | ||
static if (is(typeof(ExpandNumericType!(T, additionalBits)))) | ||
alias TryExpandNumericType = ExpandNumericType!(T, additionalBits); | ||
else | ||
static if (is(T : ulong)) | ||
static if (isSigned!T) | ||
alias TryExpandNumericType = long; | ||
else | ||
alias TryExpandNumericType = ulong; | ||
else | ||
static if (is(T : real)) | ||
alias TryExpandNumericType = real; | ||
else | ||
static assert(false, "Don't know how to expand type: " ~ T.stringof); | ||
} | ||
|
||
/// Unsigned integer type big enough to fit N bits of precision. | ||
template UnsignedBitsType(uint bits) | ||
{ | ||
|
@@ -590,3 +687,31 @@ template SignedBitsType(uint bits) | |
} | ||
return fields; | ||
} | ||
|
||
/// Create a functor value type (bound struct) from an alias. | ||
template functor(alias fun) | ||
{ | ||
struct Functor | ||
{ | ||
//alias opCall = fun; | ||
auto opCall(T...)(auto ref T args) { return fun(args); } | ||
} | ||
|
||
Functor functor() | ||
{ | ||
Functor f; | ||
return f; | ||
} | ||
} | ||
|
||
unittest | ||
{ | ||
static void caller(F)(F fun) | ||
{ | ||
fun(42); | ||
} | ||
|
||
int result; | ||
caller(functor!((int i) => result = i)); | ||
assert(result == 42); | ||
} |
Oops, something went wrong.