-registering same system multiple times only replace pointer for callback
-added export attributes (required by windows to make DLL library, not work at now due to DMD bugs) -interface D files to import
This commit is contained in:
parent
cb0f56b0fb
commit
d0fcdba6cd
20 changed files with 1322 additions and 105 deletions
|
|
@ -7,7 +7,7 @@ import std.algorithm : swap;
|
|||
import std.conv : emplace;
|
||||
import std.traits : hasMember, isCopyable, TemplateOf, Unqual;
|
||||
|
||||
@nogc @safe nothrow pure size_t nextPow2(size_t num) {
|
||||
export @nogc @safe nothrow pure size_t nextPow2(size_t num) {
|
||||
return 1 << bsr(num) + 1;
|
||||
}
|
||||
|
||||
|
|
@ -19,17 +19,17 @@ struct Vector(T) {
|
|||
size_t used;
|
||||
public:
|
||||
|
||||
this()(T t) {
|
||||
export this()(T t) {
|
||||
add(t);
|
||||
}
|
||||
|
||||
this(X)(X[] t) if (is(Unqual!X == Unqual!T)) {
|
||||
export this(X)(X[] t) if (is(Unqual!X == Unqual!T)) {
|
||||
add(t);
|
||||
|
||||
}
|
||||
|
||||
static if (isCopyable!T) {
|
||||
this(this) {
|
||||
export this(this) {
|
||||
T[] tmp = array[0 .. used];
|
||||
array = null;
|
||||
used = 0;
|
||||
|
|
@ -39,15 +39,15 @@ public:
|
|||
@disable this(this);
|
||||
}
|
||||
|
||||
~this() {
|
||||
export ~this() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
export void clear() {
|
||||
removeAll();
|
||||
}
|
||||
|
||||
void removeAll() {
|
||||
export void removeAll() {
|
||||
if (array !is null) {
|
||||
foreach (ref el; array[0 .. used]) {
|
||||
destroy(el);
|
||||
|
|
@ -59,15 +59,15 @@ public:
|
|||
used = 0;
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
export bool empty() {
|
||||
return (used == 0);
|
||||
}
|
||||
|
||||
size_t length() {
|
||||
export size_t length() {
|
||||
return used;
|
||||
}
|
||||
|
||||
void length(size_t newLength) {
|
||||
export void length(size_t newLength) {
|
||||
if (newLength > used) {
|
||||
reserve(newLength);
|
||||
foreach (ref el; array[used .. newLength]) {
|
||||
|
|
@ -81,34 +81,34 @@ public:
|
|||
used = newLength;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
export void reset() {
|
||||
used = 0;
|
||||
}
|
||||
|
||||
void reserve(size_t numElements) {
|
||||
export void reserve(size_t numElements) {
|
||||
if (numElements > array.length) {
|
||||
extend(numElements);
|
||||
}
|
||||
}
|
||||
|
||||
size_t capacity() {
|
||||
export size_t capacity() {
|
||||
return array.length - used;
|
||||
}
|
||||
|
||||
void extend(size_t newNumOfElements) {
|
||||
export void extend(size_t newNumOfElements) {
|
||||
auto oldArray = manualExtend(array, newNumOfElements);
|
||||
if (oldArray !is null) {
|
||||
freeData(oldArray);
|
||||
}
|
||||
}
|
||||
|
||||
@nogc void freeData(void[] data) {
|
||||
export @nogc void freeData(void[] data) {
|
||||
// 0x0F probably invalid value for pointers and other types
|
||||
memset(data.ptr, 0x0F, data.length); // Makes bugs show up xD
|
||||
free(data.ptr);
|
||||
}
|
||||
|
||||
static void[] manualExtend(ref T[] array, size_t newNumOfElements = 0) {
|
||||
export static void[] manualExtend(ref T[] array, size_t newNumOfElements = 0) {
|
||||
if (newNumOfElements == 0)
|
||||
newNumOfElements = 2;
|
||||
if (array.length == 0)
|
||||
|
|
@ -122,18 +122,18 @@ public:
|
|||
return cast(void[]) oldArray;
|
||||
}
|
||||
|
||||
Vector!T copy()() {
|
||||
export Vector!T copy()() {
|
||||
Vector!T duplicate;
|
||||
duplicate.reserve(used);
|
||||
duplicate ~= array[0 .. used];
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
bool canAddWithoutRealloc(uint elemNum = 1) {
|
||||
export bool canAddWithoutRealloc(uint elemNum = 1) {
|
||||
return used + elemNum <= array.length;
|
||||
}
|
||||
|
||||
void add()(T t) {
|
||||
export void add()(T t) {
|
||||
if (used >= array.length) {
|
||||
extend(nextPow2(used + 1));
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ public:
|
|||
}
|
||||
|
||||
/// Add element at given position moving others
|
||||
void add()(T t, size_t pos) {
|
||||
export void add()(T t, size_t pos) {
|
||||
assert(pos <= used);
|
||||
if (used >= array.length) {
|
||||
extend(array.length * 2);
|
||||
|
|
@ -155,7 +155,7 @@ public:
|
|||
used++;
|
||||
}
|
||||
|
||||
void add(X)(X[] t) if (is(Unqual!X == Unqual!T)) {
|
||||
export void add(X)(X[] t) if (is(Unqual!X == Unqual!T)) {
|
||||
if (used + t.length > array.length) {
|
||||
extend(nextPow2(used + t.length));
|
||||
}
|
||||
|
|
@ -165,20 +165,20 @@ public:
|
|||
used += t.length;
|
||||
}
|
||||
|
||||
void remove(size_t elemNum) {
|
||||
export void remove(size_t elemNum) {
|
||||
destroy(array[elemNum]);
|
||||
swap(array[elemNum], array[used - 1]);
|
||||
used--;
|
||||
}
|
||||
|
||||
void removeStable()(size_t elemNum) {
|
||||
export void removeStable()(size_t elemNum) {
|
||||
used--;
|
||||
foreach (i; 0 .. used) {
|
||||
array[i] = array[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
bool tryRemoveElement()(T elem) {
|
||||
export bool tryRemoveElement()(T elem) {
|
||||
foreach (i, ref el; array[0 .. used]) {
|
||||
if (el == elem) {
|
||||
remove(i);
|
||||
|
|
@ -188,59 +188,59 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
void removeElement()(T elem) {
|
||||
export void removeElement()(T elem) {
|
||||
bool ok = tryRemoveElement(elem);
|
||||
assert(ok, "There is no such an element in vector");
|
||||
}
|
||||
|
||||
ref T opIndex(size_t elemNum) {
|
||||
export ref T opIndex(size_t elemNum) {
|
||||
assert(elemNum < used, "Range violation [index]");
|
||||
return array.ptr[elemNum];
|
||||
}
|
||||
|
||||
auto opSlice() {
|
||||
export auto opSlice() {
|
||||
return array.ptr[0 .. used];
|
||||
}
|
||||
|
||||
T[] opSlice(size_t x, size_t y) {
|
||||
export T[] opSlice(size_t x, size_t y) {
|
||||
assert(y <= used);
|
||||
return array.ptr[x .. y];
|
||||
}
|
||||
|
||||
size_t opDollar() {
|
||||
export size_t opDollar() {
|
||||
return used;
|
||||
}
|
||||
|
||||
void opAssign(X)(X[] slice) {
|
||||
export void opAssign(X)(X[] slice) {
|
||||
reset();
|
||||
this ~= slice;
|
||||
}
|
||||
|
||||
void opOpAssign(string op)(T obj) {
|
||||
export void opOpAssign(string op)(T obj) {
|
||||
static assert(op == "~");
|
||||
add(obj);
|
||||
}
|
||||
|
||||
void opOpAssign(string op, X)(X[] obj) {
|
||||
export void opOpAssign(string op, X)(X[] obj) {
|
||||
static assert(op == "~");
|
||||
add(obj);
|
||||
}
|
||||
|
||||
void opIndexAssign()(T obj, size_t elemNum) {
|
||||
export void opIndexAssign()(T obj, size_t elemNum) {
|
||||
assert(elemNum < used, "Range viloation");
|
||||
array[elemNum] = obj;
|
||||
}
|
||||
|
||||
void opSliceAssign()(T[] obj, size_t a, size_t b) {
|
||||
export void opSliceAssign()(T[] obj, size_t a, size_t b) {
|
||||
assert(b <= used && a <= b, "Range viloation");
|
||||
array.ptr[a .. b] = obj;
|
||||
}
|
||||
|
||||
bool opEquals()(auto ref const Vector!(T) r) const {
|
||||
export bool opEquals()(auto ref const Vector!(T) r) const {
|
||||
return used == r.used && array.ptr[0 .. used] == r.array.ptr[0 .. r.used];
|
||||
}
|
||||
|
||||
size_t toHash() const nothrow @trusted {
|
||||
export size_t toHash() const nothrow @trusted {
|
||||
return hashOf(cast(Unqual!(T)[]) array.ptr[0 .. used]);
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ public:
|
|||
/**
|
||||
* Preety print
|
||||
*/
|
||||
void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) {
|
||||
export void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) {
|
||||
static if (__traits(compiles, formatValue(sink, array[0 .. used], fmt))) {
|
||||
formatValue(sink, array[0 .. used], fmt);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue