Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MEOS.NET.Builder/Models/CFunctionDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ internal class CFunctionDeclaration : FunctionDeclaration
{
internal string? Arguments { get; init; } = string.Empty;

// Empty argument list is a valid C declaration (e.g. `int foo();`).
internal bool HasUndefinedElements()
=> string.IsNullOrEmpty(this.ReturnType) ||
string.IsNullOrEmpty(this.FunctionName) ||
string.IsNullOrEmpty(this.Arguments);
string.IsNullOrEmpty(this.FunctionName);
}
}

11,323 changes: 7,469 additions & 3,854 deletions MEOS.NET/Internal/MEOSExposedFunctions.cs

Large diffs are not rendered by default.

12,204 changes: 7,849 additions & 4,355 deletions MEOS.NET/Internal/MEOSExternalFunctions.cs

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions MEOS.NET/Lifecycle/MEOSLifecycle.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
using MEOS.NET.Errors;
using System.Runtime.InteropServices;

using MEOS.NET.Errors;
using MEOS.NET.Internal;

namespace MEOS.NET.Lifecycle
{
public static class MEOSLifecycle
{
// Hold a managed reference to the error-handler delegate for the lifetime
// of the process so the GC does not free it while MEOS holds the
// function pointer. MEOS 1.3 `meos_initialize_error_handler` takes a
// raw `error_handler_fn` (function pointer / nint) rather than a P/Invoke
// delegate, so the call site marshals the delegate explicitly.
private static MEOSExposedFunctions.ErrorHandlingMethod? errorHandlerDelegate;

public static void Initialize(string timeZone)
=> MEOSExposedFunctions.meos_initialize(timeZone, MEOSErrorHandling.InternalErrorHandler);
{
MEOSExposedFunctions.meos_initialize();
MEOSExposedFunctions.meos_initialize_timezone(timeZone);
errorHandlerDelegate = MEOSErrorHandling.InternalErrorHandler;
var fnPtr = Marshal.GetFunctionPointerForDelegate(errorHandlerDelegate);
MEOSExposedFunctions.meos_initialize_error_handler(fnPtr);
}

public static void Terminate()
=> MEOSExposedFunctions.meos_finalize();
=> MEOSExposedFunctions.meos_finalize();
}
}
102 changes: 51 additions & 51 deletions MEOS.NET/Types/Boxes/TemporalBox.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MEOS.NET.Helpers;
using MEOS.NET.Internal;
using MEOS.NET.Structures;
using MEOS.NET.Helpers;
using MEOS.NET.Internal;
using MEOS.NET.Structures;
using MEOS.NET.Types.Collections;
using MEOS.NET.Types.Collections.Float;
using MEOS.NET.Types.Collections.Integer;
Expand All @@ -22,10 +22,10 @@ public static TemporalBox FromString(string input)
}

public static TemporalBox FromBytes(byte[] bytes)
{
var tBoxPtr = AllocHelper.AllocateArrayPointer<byte, IntPtr>(bytes, (bytesPtr) =>
{
return MEOSExposedFunctions.tbox_from_wkb(bytesPtr, (ulong)bytes.Length);
{
var tBoxPtr = AllocHelper.AllocateArrayPointer<byte, IntPtr>(bytes, (bytesPtr) =>
{
return MEOSExposedFunctions.tbox_from_wkb(bytesPtr, bytes.Length);
});

return new TemporalBox(tBoxPtr);
Expand Down Expand Up @@ -67,19 +67,19 @@ public static TemporalBox FromTime(DateTime timestamp)

public static TemporalBox FromTime(TimestampTzSet set)
{
var res = MEOSExposedFunctions.tstzset_to_tbox(set._ptr);
var res = MEOSExposedFunctions.set_to_tbox(set._ptr);
return new TemporalBox(res);
}

public static TemporalBox FromTime(TimestampTzSpan span)
{
var res = MEOSExposedFunctions.tstzspan_to_tbox(span._ptr);
var res = MEOSExposedFunctions.span_to_tbox(span._ptr);
return new TemporalBox(res);
}

public static TemporalBox FromTime(TimestampTzSpanSet spanSet)
{
var res = MEOSExposedFunctions.tstzspanset_to_tbox(spanSet._ptr);
var res = MEOSExposedFunctions.spanset_to_tbox(spanSet._ptr);
return new TemporalBox(res);
}

Expand Down Expand Up @@ -150,23 +150,23 @@ public override string ToString()
=> this.Format();

public byte[] ToBytes()
{
{
int arrSize = 0;
var arr = AllocHelper.AllocatePointer<IntPtr>(sizeof(int), (countPtr) =>
{
var arr = AllocHelper.AllocatePointer<IntPtr>(sizeof(int), (countPtr) =>
{
var res = MEOSExposedFunctions.tbox_as_wkb(this._ptr, variant: 4, countPtr);
arrSize = countPtr.ToStructure<int>();
return res;
});
arrSize = countPtr.ToStructure<int>();

return res;
});

return arr.ToArrayOfType<byte>(arrSize);
}

public string ToHexWKB()
{
return AllocHelper.AllocatePointer<string>(sizeof(int), (sizePtr) =>
{
return AllocHelper.AllocatePointer<string>(sizeof(int), (sizePtr) =>
{
return MEOSExposedFunctions.tbox_as_hexwkb(this._ptr, 0, sizePtr);
});
}
Expand All @@ -184,70 +184,70 @@ public TimestampTzSpan ToTimestampTzSpan()
}

public bool HasX()
=> MEOSExposedFunctions.tbox_hasx(this._ptr);
=> (MEOSExposedFunctions.tbox_hasx(this._ptr) != 0);

public bool HasT()
=> MEOSExposedFunctions.tbox_hast(this._ptr);
=> (MEOSExposedFunctions.tbox_hast(this._ptr) != 0);

public bool IsMinXInclusive()
{
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_xmin_inc(this._ptr, resultPtr);
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_xmin_inc(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<bool>() : false;
});
}

public bool IsMaxXInclusive()
{
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_xmax_inc(this._ptr, resultPtr);
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_xmax_inc(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<bool>() : false;
});
}

public bool IsMinTInclusive()
{
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_tmin_inc(this._ptr, resultPtr);
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_tmin_inc(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<bool>() : false;
});
}

public bool IsMaxTInclusive()
{
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_tmax_inc(this._ptr, resultPtr);
return AllocHelper.AllocatePointer<bool>(sizeof(bool), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_tmax_inc(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<bool>() : false;
});
}

public double MinX()
{
return AllocHelper.AllocatePointer<double>(sizeof(double), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_xmin(this._ptr, resultPtr);
{
return AllocHelper.AllocatePointer<double>(sizeof(double), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_xmin(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<double>() : throw new InvalidOperationException("No X Min available");
});
}

public double MaxX()
{
return AllocHelper.AllocatePointer<double>(sizeof(double), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_xmax(this._ptr, resultPtr);
return AllocHelper.AllocatePointer<double>(sizeof(double), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_xmax(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<double>() : throw new InvalidOperationException("No X Max available");
});
}

public DateTime MinT()
{
var timestamp = AllocHelper.AllocatePointer<TimestampTz>(sizeof(long), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_tmin(this._ptr, resultPtr);
var timestamp = AllocHelper.AllocatePointer<TimestampTz>(sizeof(long), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_tmin(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<TimestampTz>() : throw new InvalidOperationException("No T Min available");
});

Expand All @@ -256,35 +256,35 @@ public DateTime MinT()

public DateTime MaxT()
{
var timestamp = AllocHelper.AllocatePointer<TimestampTz>(sizeof(long), (resultPtr) =>
{
var successful = MEOSExposedFunctions.tbox_tmax(this._ptr, resultPtr);
var timestamp = AllocHelper.AllocatePointer<TimestampTz>(sizeof(long), (resultPtr) =>
{
var successful = (MEOSExposedFunctions.tbox_tmax(this._ptr, resultPtr) != 0);
return successful ? resultPtr.ToStructure<TimestampTz>() : throw new InvalidOperationException("No T Max available");
});

return timestamp.ToDateTime();
}

public bool IsLeftOf(TemporalBox other)
=> MEOSExposedFunctions.left_tbox_tbox(this._ptr, other._ptr);
=> (MEOSExposedFunctions.left_tbox_tbox(this._ptr, other._ptr) != 0);

public bool IsLeftOf(TemporalNumber other)
=> this.IsLeftOf(other.BoundingBox());

public bool IsOverOrLeftOf(TemporalBox other)
=> MEOSExposedFunctions.overleft_tbox_tbox(this._ptr, other._ptr);
=> (MEOSExposedFunctions.overleft_tbox_tbox(this._ptr, other._ptr) != 0);

public bool IsOverOrLeftOf(TemporalNumber other)
=> this.IsOverOrLeftOf(other.BoundingBox());

public bool IsRightOf(TemporalBox other)
=> MEOSExposedFunctions.right_tbox_tbox(this._ptr, other._ptr);
=> (MEOSExposedFunctions.right_tbox_tbox(this._ptr, other._ptr) != 0);

public bool IsRightOf(TemporalNumber other)
=> this.IsRightOf(other.BoundingBox());

public bool IsOverOrRightOf(TemporalBox other)
=> MEOSExposedFunctions.overright_tbox_tbox(this._ptr, other._ptr);
=> (MEOSExposedFunctions.overright_tbox_tbox(this._ptr, other._ptr) != 0);

public bool IsOverOrRightOf(TemporalNumber other)
=> this.IsOverOrRightOf(other.BoundingBox());
Expand Down
Loading