Skip to content
Merged
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
30 changes: 30 additions & 0 deletions MEOS.NET.Tests/MultipleAnswerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MEOS.NET.Structures;
using MEOS.NET.Types;

namespace MEOS.NET.Tests
{
/// <summary>
/// A call that answers several values answers them together, so the method
/// answers a tuple and the call is made once — the halves of one answer
/// come from one call.
/// </summary>
[TestClass]
public class MultipleAnswerTests : MeosTest
{
[TestMethod]
public void SplittingByTimeAnswersThePiecesAndTheirBins()
{
Temporal trip = TFloat.In(
"[1@2024-12-06, 2@2024-12-07, 3@2024-12-08]")!;

(Temporal?[] pieces, DateTime[] bins) = trip.TimeSplit(
Interval.In("1 day")!.Value,
new DateTime(2024, 12, 6, 0, 0, 0, DateTimeKind.Utc));

Assert.AreEqual(pieces.Length, bins.Length);
Assert.IsTrue(pieces.Length > 1);
Assert.AreEqual(new DateTime(2024, 12, 6, 0, 0, 0, DateTimeKind.Utc),
bins[0]);
}
}
}
15 changes: 13 additions & 2 deletions MEOS.NET/Functions/Meos.meos.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3136,8 +3136,19 @@ public static int[] TintValues(IntPtr temp)
finally { Marshal.FreeHGlobal(_cnt); }
}

public static IntPtr TbigintValues(IntPtr temp, IntPtr count)
=> SafeExecution<IntPtr>(() => Native.TbigintValues(temp, count));
public static long[] TbigintValues(IntPtr temp)
{
IntPtr _cnt = Marshal.AllocHGlobal(sizeof(int));
try
{
IntPtr _p = SafeExecution<IntPtr>(() => Native.TbigintValues(temp, _cnt));
int _n = Marshal.ReadInt32(_cnt);
long[] _out = new long[_n];
Marshal.Copy(_p, _out, 0, _n);
return _out;
}
finally { Marshal.FreeHGlobal(_cnt); }
}

public static double TnumberAvgValue(IntPtr temp)
=> SafeExecution<double>(() => Native.TnumberAvgValue(temp));
Expand Down
14 changes: 14 additions & 0 deletions MEOS.NET/Types/Jsonb.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ public bool Contained(Jsonb jb2)
}
}

public (Text?[], Jsonb?[]) Each()
{
var _answered = Meos.JsonbEach(this.Ptr);

return (MEOSFactory.WrapTextArray(_answered.Item1), MEOSFactory.WrapJsonbArray(_answered.Item2));
}

public (Text?[], Text?[]) EachText()
{
var _answered = Meos.JsonbEachText(this.Ptr);

return (MEOSFactory.WrapTextArray(_answered.Item1), MEOSFactory.WrapTextArray(_answered.Item2));
}

public bool Exists(Text key)
=> Meos.JsonbExists(this.Ptr, key.Ptr);

Expand Down
24 changes: 24 additions & 0 deletions MEOS.NET/Types/MEOSConvert.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ internal static int ToDateADT(DateOnly day)
=> Meos.DateIn(
day.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));

/// <summary>Each MEOS TimestampTz of an array, as a DateTime.</summary>
internal static DateTime[] ToDateTimeArray(long[] moments)
{
DateTime[] values = new DateTime[moments.Length];
for (int i = 0; i < moments.Length; i++)
{
values[i] = ToDateTime(moments[i]);
}

return values;
}

/// <summary>Each MEOS DateADT of an array, as a DateOnly.</summary>
internal static DateOnly[] ToDateOnlyArray(int[] days)
{
DateOnly[] values = new DateOnly[days.Length];
for (int i = 0; i < days.Length; i++)
{
values[i] = ToDateOnly(days[i]);
}

return values;
}

/// <summary>The struct MEOS answers through a pointer, as a value. The
/// memory behind the pointer stays MEOS's, as it does for every other
/// value the layer reads back.</summary>
Expand Down
48 changes: 48 additions & 0 deletions MEOS.NET/Types/MEOSFactory.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,30 @@ public static class MEOSFactory
return wrapped;
}

/// <summary>The value at <paramref name="ptr"/> as the RTreeNNCursor
/// class the model gives its runtime type.</summary>
public static RTreeNNCursor? WrapRTreeNNCursor(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
{
return null;
}

return new RTreeNNCursor(ptr);
}

/// <summary>Every element of a C array of RTreeNNCursor pointers, wrapped.</summary>
public static RTreeNNCursor?[] WrapRTreeNNCursorArray(IntPtr[] ptrs)
{
RTreeNNCursor?[] wrapped = new RTreeNNCursor?[ptrs.Length];
for (int i = 0; i < ptrs.Length; i++)
{
wrapped[i] = WrapRTreeNNCursor(ptrs[i]);
}

return wrapped;
}

/// <summary>The value at <paramref name="ptr"/> as the Raquet
/// class the model gives its runtime type.</summary>
public static Raquet? WrapRaquet(IntPtr ptr)
Expand All @@ -353,6 +377,30 @@ public static class MEOSFactory
return wrapped;
}

/// <summary>The value at <paramref name="ptr"/> as the SPNNCursor
/// class the model gives its runtime type.</summary>
public static SPNNCursor? WrapSPNNCursor(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
{
return null;
}

return new SPNNCursor(ptr);
}

/// <summary>Every element of a C array of SPNNCursor pointers, wrapped.</summary>
public static SPNNCursor?[] WrapSPNNCursorArray(IntPtr[] ptrs)
{
SPNNCursor?[] wrapped = new SPNNCursor?[ptrs.Length];
for (int i = 0; i < ptrs.Length; i++)
{
wrapped[i] = WrapSPNNCursor(ptrs[i]);
}

return wrapped;
}

/// <summary>The value at <paramref name="ptr"/> as the SPTree
/// class the model gives its runtime type.</summary>
public static SPTree? WrapSPTree(IntPtr ptr)
Expand Down
24 changes: 24 additions & 0 deletions MEOS.NET/Types/RTreeNNCursor.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
/// <summary>A walk over an R-tree's entries in order of distance from a query. MEOS registers it in no enum, so it names no temptype.</summary>
[System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")]
public class RTreeNNCursor : Value
{
internal RTreeNNCursor(IntPtr ptr) : base(ptr) { }

public void Close()
=> Meos.RtreeNnCursorClose(this.Ptr);

public static RTreeNNCursor? Open(RTree rtree, IntPtr query)
=> MEOSFactory.WrapRTreeNNCursor(Meos.RtreeNnCursorOpen(rtree.Ptr, query));

}
}
24 changes: 24 additions & 0 deletions MEOS.NET/Types/SPNNCursor.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
/// <summary>The SP-tree's nearest-neighbour walk, the R-tree cursor's sibling. MEOS registers it in no enum, so it names no temptype.</summary>
[System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")]
public class SPNNCursor : Value
{
internal SPNNCursor(IntPtr ptr) : base(ptr) { }

public void Close()
=> Meos.SptreeNnCursorClose(this.Ptr);

public static SPNNCursor? Open(SPTree sptree, IntPtr query)
=> MEOSFactory.WrapSPNNCursor(Meos.SptreeNnCursorOpen(sptree.Ptr, query));

}
}
3 changes: 3 additions & 0 deletions MEOS.NET/Types/TBigint.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public long StartValue()
}
}

public long[] Values()
=> Meos.TbigintValues(this.Ptr);

public static Temporal? FromBaseTemp(long i, Temporal temp)
=> MEOSFactory.WrapTemporal(Meos.TbigintFromBaseTemp(i, temp.Ptr));

Expand Down
23 changes: 23 additions & 0 deletions MEOS.NET/Types/TFloat.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ public double StartValue()
}
}

public (Temporal?[], double[]) ValueSplit(double size, double origin)
{
var _answered = Meos.TfloatValueSplit(this.Ptr, size, origin);

return (MEOSFactory.WrapTemporalArray(_answered.Item1), _answered.Item2);
}

public TBox?[] ValueTimeBoxes(double vsize, Interval duration, double vorigin, DateTime torigin)
{
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
Expand All @@ -154,6 +161,22 @@ public double StartValue()
}
}

public (Temporal?[], double[], DateTime[]) ValueTimeSplit(double vsize, Interval duration, double vorigin, DateTime torigin)
{
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
try
{
Marshal.StructureToPtr(duration, _duration, false);
var _answered = Meos.TfloatValueTimeSplit(this.Ptr, vsize, _duration, vorigin, MEOSConvert.ToTimestampTz(torigin));

return (MEOSFactory.WrapTemporalArray(_answered.Item1), _answered.Item2, MEOSConvert.ToDateTimeArray(_answered.Item3));
}
finally
{
Marshal.FreeHGlobal(_duration);
}
}

public double[] Values()
=> Meos.TfloatValues(this.Ptr);

Expand Down
23 changes: 23 additions & 0 deletions MEOS.NET/Types/TInt.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ public int StartValue()
}
}

public (Temporal?[], int[]) ValueSplit(int vsize, int vorigin)
{
var _answered = Meos.TintValueSplit(this.Ptr, vsize, vorigin);

return (MEOSFactory.WrapTemporalArray(_answered.Item1), _answered.Item2);
}

public TBox?[] ValueTimeBoxes(int vsize, Interval duration, int vorigin, DateTime torigin)
{
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
Expand All @@ -124,6 +131,22 @@ public int StartValue()
}
}

public (Temporal?[], int[], DateTime[]) ValueTimeSplit(int size, Interval duration, int vorigin, DateTime torigin)
{
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
try
{
Marshal.StructureToPtr(duration, _duration, false);
var _answered = Meos.TintValueTimeSplit(this.Ptr, size, _duration, vorigin, MEOSConvert.ToTimestampTz(torigin));

return (MEOSFactory.WrapTemporalArray(_answered.Item1), _answered.Item2, MEOSConvert.ToDateTimeArray(_answered.Item3));
}
finally
{
Marshal.FreeHGlobal(_duration);
}
}

public int[] Values()
=> Meos.TintValues(this.Ptr);

Expand Down
22 changes: 22 additions & 0 deletions MEOS.NET/Types/TRGeometrySeqSet.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,27 @@ internal TRGeometrySeqSet(IntPtr ptr) : base(ptr) { }
}
}

public Temporal? MakeGaps(Temporal[] instants, InterpType interp, Interval maxt, double maxdist)
{
IntPtr _maxt = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
IntPtr[] _instantsValues = new IntPtr[instants.Length];
for (int i = 0; i < instants.Length; i++)
{
_instantsValues[i] = instants[i].Ptr;
}

GCHandle _instants = GCHandle.Alloc(_instantsValues, GCHandleType.Pinned);
try
{
Marshal.StructureToPtr(maxt, _maxt, false);
return MEOSFactory.WrapTemporal(Meos.TrgeometryseqsetMakeGaps(this.Ptr, _instants.AddrOfPinnedObject(), instants.Length, (int) interp, _maxt, maxdist));
}
finally
{
Marshal.FreeHGlobal(_maxt);
_instants.Free();
}
}

}
}
22 changes: 22 additions & 0 deletions MEOS.NET/Types/TSequenceSet.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,27 @@ internal TSequenceSet(IntPtr ptr) : base(ptr) { }
}
}

public static Temporal? MakeGaps(Temporal[] instants, InterpType interp, Interval maxt, double maxdist)
{
IntPtr _maxt = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
IntPtr[] _instantsValues = new IntPtr[instants.Length];
for (int i = 0; i < instants.Length; i++)
{
_instantsValues[i] = instants[i].Ptr;
}

GCHandle _instants = GCHandle.Alloc(_instantsValues, GCHandleType.Pinned);
try
{
Marshal.StructureToPtr(maxt, _maxt, false);
return MEOSFactory.WrapTemporal(Meos.TsequencesetMakeGaps(_instants.AddrOfPinnedObject(), instants.Length, (int) interp, _maxt, maxdist));
}
finally
{
Marshal.FreeHGlobal(_maxt);
_instants.Free();
}
}

}
}
16 changes: 16 additions & 0 deletions MEOS.NET/Types/Temporal.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,22 @@ public DateTime StartTimestamptz()
}
}

public (Temporal?[], DateTime[]) TimeSplit(Interval duration, DateTime torigin)
{
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
try
{
Marshal.StructureToPtr(duration, _duration, false);
var _answered = Meos.TemporalTimeSplit(this.Ptr, _duration, MEOSConvert.ToTimestampTz(torigin));

return (MEOSFactory.WrapTemporalArray(_answered.Item1), MEOSConvert.ToDateTimeArray(_answered.Item2));
}
finally
{
Marshal.FreeHGlobal(_duration);
}
}

public long[] Timestamps()
=> Meos.TemporalTimestamps(this.Ptr);

Expand Down
Loading
Loading