From 2846637f95cb757529aaff43f2df889f632a18ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 24 Oct 2016 00:12:35 +0200 Subject: [PATCH] Add AlgebraicChoppedVector as the future base for the event drivers FD map. --- dub.sdl | 2 + source/eventcore/internal/consumablequeue.d | 2 +- source/eventcore/internal/utils.d | 41 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/dub.sdl b/dub.sdl index c50b3a0..97dea66 100644 --- a/dub.sdl +++ b/dub.sdl @@ -8,6 +8,8 @@ targetType "library" libs "anl" platform="linux" libs "ws2_32" platform="windows" +dependency "taggedalgebraic" version="~>0.10.4" + configuration "epoll" { platforms "linux" versions "EventcoreEpollDriver" diff --git a/source/eventcore/internal/consumablequeue.d b/source/eventcore/internal/consumablequeue.d index 808d5c3..95289b9 100644 --- a/source/eventcore/internal/consumablequeue.d +++ b/source/eventcore/internal/consumablequeue.d @@ -2,7 +2,7 @@ module eventcore.internal.consumablequeue; /** FIFO queue with support for chunk-wise consumption. */ -class ConsumableQueue(T) +final class ConsumableQueue(T) { @safe: nothrow: diff --git a/source/eventcore/internal/utils.d b/source/eventcore/internal/utils.d index 0ae0245..352edca 100644 --- a/source/eventcore/internal/utils.d +++ b/source/eventcore/internal/utils.d @@ -1,4 +1,8 @@ module eventcore.internal.utils; + +import taggedalgebraic; + + void print(ARGS...)(string str, ARGS args) @trusted @nogc nothrow { import std.format : formattedWrite; @@ -120,6 +124,43 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { } } +struct AlgebraicChoppedVector(TCommon, TSpecific...) +{ + import std.conv : to; + import std.meta : AliasSeq; + + union U { mixin fields!0; } + alias FieldType = TaggedAlgebraic!U; + static struct FullField { + TCommon common; + FieldType specific; + mixin(accessors()); + } + + ChoppedVector!(FullField) items; + + alias items this; + + private static string accessors() + { + import std.format : format; + string ret; + foreach (i, U; TSpecific) + ret ~= "@property ref TSpecific[%s] %s() nothrow @safe { return this.specific.get!(TSpecific[%s]); }\n" + .format(i, U.Handle.name, i); + return ret; + } + + private mixin template fields(size_t i) { + static if (i < TSpecific.length) { + mixin("TSpecific["~i.to!string~"] "~TSpecific[i].Handle.name~";"); + mixin fields!(i+1); + } + } +} + + + /** Efficient bit set of dynamic size. */ struct SmallIntegerSet(V : uint)