From 271c8e98467a1bca5a40a2ecf1fc9c6d55e551b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Zim=C3=A1nyi?= Date: Wed, 2 Sep 2026 22:48:07 +0200 Subject: [PATCH] Generate a C# enum for every enum the catalog carries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MEOS states thirteen enums beside the error codes — `interpType`, `MeosType`, `tempSubtype`, `IndexSearchOp`, `SPTreeKind`, `MeosOper`, `spatialRel`, `SkipListType`, `nullHandleType`, `MeosPixType`, `COMPRESSIONS`, `ENDIANS`, `PC_FILTERTYPE` — and the catalog carries each with its members and their values. `objectgen.py` projects them into `MEOS.NET/Enums/`, one file each, so a caller names a MEOS constant where the C API takes an int and the values come from MEOS rather than from a transcription. The names are the ones MEOS gives: the type is its catalog name with an upper-case first letter (`interpType` reads `InterpType`, `MeosType` and `ENDIANS` stand), and a member is its constant PascalCased (`INTERP_NONE` reads `InterpNone`, `T_TFLOAT` reads `TTfloat`). The generator refuses an enum whose members would collide into one C# name. Four tests hold the values to MEOS itself: `meostype_name`, `interptype_name` and `tempsubtype_name` name back what the member names, and `interptype_from_string` reads a name back as its member. A value that drifted from MEOS names something else, or nothing. Two files in the library are written by hand, both of them the runtime substrate: the MEOS session lifecycle, and the error check every wrapper makes after a call. Everything else under `MEOS.NET/` is a projection of the catalog. --- MEOS.NET.Tests/CatalogEnumTests.cs | 45 +++++ MEOS.NET/Enums/COMPRESSIONS.g.cs | 19 ++ MEOS.NET/Enums/ENDIANS.g.cs | 16 ++ MEOS.NET/Enums/IndexSearchOp.g.cs | 73 ++++++++ MEOS.NET/Enums/InterpType.g.cs | 22 +++ MEOS.NET/Enums/InterpolationType.cs | 10 - MEOS.NET/Enums/MeosOper.g.cs | 145 +++++++++++++++ MEOS.NET/Enums/MeosPixType.g.cs | 43 +++++ MEOS.NET/Enums/MeosType.g.cs | 277 ++++++++++++++++++++++++++++ MEOS.NET/Enums/NullHandleType.g.cs | 25 +++ MEOS.NET/Enums/PC_FILTERTYPE.g.cs | 22 +++ MEOS.NET/Enums/SPTreeKind.g.cs | 16 ++ MEOS.NET/Enums/SkipListType.g.cs | 16 ++ MEOS.NET/Enums/SpatialRel.g.cs | 22 +++ MEOS.NET/Enums/TempSubtype.g.cs | 22 +++ MEOS.NET/Types/TFloatSeq.g.cs | 2 +- MEOS.NET/Types/TFloatSeqSet.g.cs | 2 +- MEOS.NET/Types/TRGeometry.g.cs | 2 +- MEOS.NET/Types/Temporal.g.cs | 6 +- tools/README.md | 5 +- tools/objectgen.py | 65 ++++++- 21 files changed, 835 insertions(+), 20 deletions(-) create mode 100644 MEOS.NET.Tests/CatalogEnumTests.cs create mode 100644 MEOS.NET/Enums/COMPRESSIONS.g.cs create mode 100644 MEOS.NET/Enums/ENDIANS.g.cs create mode 100644 MEOS.NET/Enums/IndexSearchOp.g.cs create mode 100644 MEOS.NET/Enums/InterpType.g.cs delete mode 100644 MEOS.NET/Enums/InterpolationType.cs create mode 100644 MEOS.NET/Enums/MeosOper.g.cs create mode 100644 MEOS.NET/Enums/MeosPixType.g.cs create mode 100644 MEOS.NET/Enums/MeosType.g.cs create mode 100644 MEOS.NET/Enums/NullHandleType.g.cs create mode 100644 MEOS.NET/Enums/PC_FILTERTYPE.g.cs create mode 100644 MEOS.NET/Enums/SPTreeKind.g.cs create mode 100644 MEOS.NET/Enums/SkipListType.g.cs create mode 100644 MEOS.NET/Enums/SpatialRel.g.cs create mode 100644 MEOS.NET/Enums/TempSubtype.g.cs diff --git a/MEOS.NET.Tests/CatalogEnumTests.cs b/MEOS.NET.Tests/CatalogEnumTests.cs new file mode 100644 index 0000000..db73bbe --- /dev/null +++ b/MEOS.NET.Tests/CatalogEnumTests.cs @@ -0,0 +1,45 @@ +using MEOS.NET.Enums; +using MEOS.NET.Functions; + +namespace MEOS.NET.Tests +{ + /// + /// The generated enums carry MEOS's own constants, so MEOS names back the same + /// thing the enum member does. A value that drifted would name something else, + /// or nothing. + /// + [TestClass] + public class CatalogEnumTests : MeosTest + { + [TestMethod] + public void MeosNamesTheTypeTheEnumMemberDoes() + { + Assert.AreEqual("tfloat", Meos.MeostypeName((int)MeosType.TTfloat)); + Assert.AreEqual("tgeompoint", Meos.MeostypeName((int)MeosType.TTgeompoint)); + Assert.AreEqual("floatspan", Meos.MeostypeName((int)MeosType.TFloatspan)); + } + + [TestMethod] + public void MeosNamesTheInterpolationTheEnumMemberDoes() + { + Assert.AreEqual("Discrete", Meos.InterptypeName((int)InterpType.Discrete)); + Assert.AreEqual("Step", Meos.InterptypeName((int)InterpType.Step)); + Assert.AreEqual("Linear", Meos.InterptypeName((int)InterpType.Linear)); + } + + [TestMethod] + public void MeosNamesTheSubtypeTheEnumMemberDoes() + { + Assert.AreEqual("Instant", Meos.TempsubtypeName((int)TempSubtype.Tinstant)); + Assert.AreEqual("Sequence", Meos.TempsubtypeName((int)TempSubtype.Tsequence)); + Assert.AreEqual("SequenceSet", Meos.TempsubtypeName((int)TempSubtype.Tsequenceset)); + } + + [TestMethod] + public void TheInterpolationNameReadsBackAsItsMember() + { + Assert.AreEqual((int)InterpType.Linear, Meos.InterptypeFromString("Linear")); + Assert.AreEqual((int)InterpType.Step, Meos.InterptypeFromString("Step")); + } + } +} diff --git a/MEOS.NET/Enums/COMPRESSIONS.g.cs b/MEOS.NET/Enums/COMPRESSIONS.g.cs new file mode 100644 index 0000000..51e3be1 --- /dev/null +++ b/MEOS.NET/Enums/COMPRESSIONS.g.cs @@ -0,0 +1,19 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS COMPRESSIONS enum, from pc_api.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum COMPRESSIONS + { + /// PC_NONE + PcNone = 0, + + /// PC_DIMENSIONAL + PcDimensional = 1, + + /// PC_LAZPERF + PcLazperf = 2, + + } +} diff --git a/MEOS.NET/Enums/ENDIANS.g.cs b/MEOS.NET/Enums/ENDIANS.g.cs new file mode 100644 index 0000000..d393203 --- /dev/null +++ b/MEOS.NET/Enums/ENDIANS.g.cs @@ -0,0 +1,16 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS ENDIANS enum, from pc_api.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum ENDIANS + { + /// PC_XDR + PcXdr = 0, + + /// PC_NDR + PcNdr = 1, + + } +} diff --git a/MEOS.NET/Enums/IndexSearchOp.g.cs b/MEOS.NET/Enums/IndexSearchOp.g.cs new file mode 100644 index 0000000..970e8a5 --- /dev/null +++ b/MEOS.NET/Enums/IndexSearchOp.g.cs @@ -0,0 +1,73 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS IndexSearchOp enum, from meos.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum IndexSearchOp + { + /// INDEX_OVERLAPS + IndexOverlaps = 0, + + /// INDEX_CONTAINS + IndexContains = 1, + + /// INDEX_CONTAINED_BY + IndexContainedBy = 2, + + /// INDEX_LEFT + IndexLeft = 3, + + /// INDEX_OVERLEFT + IndexOverleft = 4, + + /// INDEX_RIGHT + IndexRight = 5, + + /// INDEX_OVERRIGHT + IndexOverright = 6, + + /// INDEX_BELOW + IndexBelow = 7, + + /// INDEX_OVERBELOW + IndexOverbelow = 8, + + /// INDEX_ABOVE + IndexAbove = 9, + + /// INDEX_OVERABOVE + IndexOverabove = 10, + + /// INDEX_FRONT + IndexFront = 11, + + /// INDEX_OVERFRONT + IndexOverfront = 12, + + /// INDEX_BACK + IndexBack = 13, + + /// INDEX_OVERBACK + IndexOverback = 14, + + /// INDEX_BEFORE + IndexBefore = 15, + + /// INDEX_OVERBEFORE + IndexOverbefore = 16, + + /// INDEX_AFTER + IndexAfter = 17, + + /// INDEX_OVERAFTER + IndexOverafter = 18, + + /// INDEX_SAME + IndexSame = 19, + + /// INDEX_ADJACENT + IndexAdjacent = 20, + + } +} diff --git a/MEOS.NET/Enums/InterpType.g.cs b/MEOS.NET/Enums/InterpType.g.cs new file mode 100644 index 0000000..7d8c737 --- /dev/null +++ b/MEOS.NET/Enums/InterpType.g.cs @@ -0,0 +1,22 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS interpType enum, from meos.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum InterpType + { + /// INTERP_NONE + InterpNone = 0, + + /// DISCRETE + Discrete = 1, + + /// STEP + Step = 2, + + /// LINEAR + Linear = 3, + + } +} diff --git a/MEOS.NET/Enums/InterpolationType.cs b/MEOS.NET/Enums/InterpolationType.cs deleted file mode 100644 index b09757a..0000000 --- a/MEOS.NET/Enums/InterpolationType.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace MEOS.NET.Enums -{ - public enum InterpolationType - { - None = 0, - Discrete = 1, - Stepwise = 2, - Linear = 3, - } -} diff --git a/MEOS.NET/Enums/MeosOper.g.cs b/MEOS.NET/Enums/MeosOper.g.cs new file mode 100644 index 0000000..dc2585a --- /dev/null +++ b/MEOS.NET/Enums/MeosOper.g.cs @@ -0,0 +1,145 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS MeosOper enum, from meos_catalog.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum MeosOper + { + /// UNKNOWN_OP + UnknownOp = 0, + + /// EQ_OP + EqOp = 1, + + /// NE_OP + NeOp = 2, + + /// LT_OP + LtOp = 3, + + /// LE_OP + LeOp = 4, + + /// GT_OP + GtOp = 5, + + /// GE_OP + GeOp = 6, + + /// ADJACENT_OP + AdjacentOp = 7, + + /// UNION_OP + UnionOp = 8, + + /// MINUS_OP + MinusOp = 9, + + /// INTERSECT_OP + IntersectOp = 10, + + /// OVERLAPS_OP + OverlapsOp = 11, + + /// CONTAINS_OP + ContainsOp = 12, + + /// CONTAINED_OP + ContainedOp = 13, + + /// SAME_OP + SameOp = 14, + + /// LEFT_OP + LeftOp = 15, + + /// OVERLEFT_OP + OverleftOp = 16, + + /// RIGHT_OP + RightOp = 17, + + /// OVERRIGHT_OP + OverrightOp = 18, + + /// BELOW_OP + BelowOp = 19, + + /// OVERBELOW_OP + OverbelowOp = 20, + + /// ABOVE_OP + AboveOp = 21, + + /// OVERABOVE_OP + OveraboveOp = 22, + + /// FRONT_OP + FrontOp = 23, + + /// OVERFRONT_OP + OverfrontOp = 24, + + /// BACK_OP + BackOp = 25, + + /// OVERBACK_OP + OverbackOp = 26, + + /// BEFORE_OP + BeforeOp = 27, + + /// OVERBEFORE_OP + OverbeforeOp = 28, + + /// AFTER_OP + AfterOp = 29, + + /// OVERAFTER_OP + OverafterOp = 30, + + /// EVEREQ_OP + EvereqOp = 31, + + /// EVERNE_OP + EverneOp = 32, + + /// EVERLT_OP + EverltOp = 33, + + /// EVERLE_OP + EverleOp = 34, + + /// EVERGT_OP + EvergtOp = 35, + + /// EVERGE_OP + EvergeOp = 36, + + /// ALWAYSEQ_OP + AlwayseqOp = 37, + + /// ALWAYSNE_OP + AlwaysneOp = 38, + + /// ALWAYSLT_OP + AlwaysltOp = 39, + + /// ALWAYSLE_OP + AlwaysleOp = 40, + + /// ALWAYSGT_OP + AlwaysgtOp = 41, + + /// ALWAYSGE_OP + AlwaysgeOp = 42, + + /// TEMPCONTAINS_OP + TempcontainsOp = 43, + + /// TEMPCONTAINED_OP + TempcontainedOp = 44, + + } +} diff --git a/MEOS.NET/Enums/MeosPixType.g.cs b/MEOS.NET/Enums/MeosPixType.g.cs new file mode 100644 index 0000000..b6bf40e --- /dev/null +++ b/MEOS.NET/Enums/MeosPixType.g.cs @@ -0,0 +1,43 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS MeosPixType enum, from meos_raster.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum MeosPixType + { + /// MEOS_PT_UINT8 + MeosPtUint8 = 0, + + /// MEOS_PT_INT16 + MeosPtInt16 = 1, + + /// MEOS_PT_INT32 + MeosPtInt32 = 2, + + /// MEOS_PT_FLOAT32 + MeosPtFloat32 = 3, + + /// MEOS_PT_FLOAT64 + MeosPtFloat64 = 4, + + /// MEOS_PT_INT8 + MeosPtInt8 = 5, + + /// MEOS_PT_UINT16 + MeosPtUint16 = 6, + + /// MEOS_PT_UINT32 + MeosPtUint32 = 7, + + /// MEOS_PT_INT64 + MeosPtInt64 = 8, + + /// MEOS_PT_UINT64 + MeosPtUint64 = 9, + + /// MEOS_PT_FLOAT16 + MeosPtFloat16 = 10, + + } +} diff --git a/MEOS.NET/Enums/MeosType.g.cs b/MEOS.NET/Enums/MeosType.g.cs new file mode 100644 index 0000000..42748e6 --- /dev/null +++ b/MEOS.NET/Enums/MeosType.g.cs @@ -0,0 +1,277 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS MeosType enum, from meos_catalog.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum MeosType + { + /// T_UNKNOWN + TUnknown = 0, + + /// T_BOOL + TBool = 1, + + /// T_DATE + TDate = 2, + + /// T_DATEMULTIRANGE + TDatemultirange = 3, + + /// T_DATERANGE + TDaterange = 4, + + /// T_DATESET + TDateset = 5, + + /// T_DATESPAN + TDatespan = 6, + + /// T_DATESPANSET + TDatespanset = 7, + + /// T_DOUBLE2 + TDouble2 = 8, + + /// T_DOUBLE3 + TDouble3 = 9, + + /// T_DOUBLE4 + TDouble4 = 10, + + /// T_FLOAT8 + TFloat8 = 11, + + /// T_FLOATSET + TFloatset = 12, + + /// T_FLOATSPAN + TFloatspan = 13, + + /// T_FLOATSPANSET + TFloatspanset = 14, + + /// T_INT4 + TInt4 = 15, + + /// T_INT4MULTIRANGE + TInt4multirange = 16, + + /// T_INT4RANGE + TInt4range = 17, + + /// T_INTSET + TIntset = 18, + + /// T_INTSPAN + TIntspan = 19, + + /// T_INTSPANSET + TIntspanset = 20, + + /// T_INT8 + TInt8 = 21, + + /// T_INT8MULTIRANGE + TInt8multirange = 52, + + /// T_INT8RANGE + TInt8range = 53, + + /// T_BIGINTSET + TBigintset = 22, + + /// T_BIGINTSPAN + TBigintspan = 23, + + /// T_BIGINTSPANSET + TBigintspanset = 24, + + /// T_STBOX + TStbox = 25, + + /// T_TBOOL + TTbool = 26, + + /// T_TBOX + TTbox = 27, + + /// T_TDOUBLE2 + TTdouble2 = 28, + + /// T_TDOUBLE3 + TTdouble3 = 29, + + /// T_TDOUBLE4 + TTdouble4 = 30, + + /// T_TEXT + TText = 31, + + /// T_TEXTSET + TTextset = 32, + + /// T_TFLOAT + TTfloat = 33, + + /// T_TIMESTAMPTZ + TTimestamptz = 34, + + /// T_TINT + TTint = 35, + + /// T_TSTZMULTIRANGE + TTstzmultirange = 36, + + /// T_TSTZRANGE + TTstzrange = 37, + + /// T_TSTZSET + TTstzset = 38, + + /// T_TSTZSPAN + TTstzspan = 39, + + /// T_TSTZSPANSET + TTstzspanset = 40, + + /// T_TTEXT + TTtext = 41, + + /// T_GEOMETRY + TGeometry = 42, + + /// T_GEOMSET + TGeomset = 43, + + /// T_GEOGRAPHY + TGeography = 44, + + /// T_GEOGSET + TGeogset = 45, + + /// T_TGEOMPOINT + TTgeompoint = 46, + + /// T_TGEOGPOINT + TTgeogpoint = 47, + + /// T_NPOINT + TNpoint = 48, + + /// T_NPOINTSET + TNpointset = 49, + + /// T_NSEGMENT + TNsegment = 50, + + /// T_TNPOINT + TTnpoint = 51, + + /// T_POSE + TPose = 54, + + /// T_POSESET + TPoseset = 55, + + /// T_TPOSE + TTpose = 56, + + /// T_CBUFFER + TCbuffer = 57, + + /// T_CBUFFERSET + TCbufferset = 58, + + /// T_TCBUFFER + TTcbuffer = 59, + + /// T_TGEOMETRY + TTgeometry = 60, + + /// T_TGEOGRAPHY + TTgeography = 61, + + /// T_TRGEOMETRY + TTrgeometry = 62, + + /// T_JSONB + TJsonb = 63, + + /// T_JSONPATH + TJsonpath = 64, + + /// T_JSONBSET + TJsonbset = 65, + + /// T_TJSONB + TTjsonb = 66, + + /// T_TBIGINT + TTbigint = 67, + + /// T_H3INDEX + TH3index = 68, + + /// T_H3INDEXSET + TH3indexset = 69, + + /// T_TH3INDEX + TTh3index = 70, + + /// T_QUADBIN + TQuadbin = 71, + + /// T_QUADBINSET + TQuadbinset = 72, + + /// T_TQUADBIN + TTquadbin = 73, + + /// T_PCPOINT + TPcpoint = 74, + + /// T_PCPOINTSET + TPcpointset = 75, + + /// T_TPCPOINT + TTpcpoint = 76, + + /// T_PCPATCH + TPcpatch = 77, + + /// T_PCPATCHSET + TPcpatchset = 78, + + /// T_TPCPATCH + TTpcpatch = 79, + + /// T_TPCBOX + TTpcbox = 80, + + /// T_RAQUET + TRaquet = 81, + + /// T_POSECHAIN + TPosechain = 82, + + /// T_POSECHAINSET + TPosechainset = 83, + + /// T_TPOSECHAIN + TTposechain = 84, + + /// T_S2CELL + TS2cell = 85, + + /// T_S2CELLSET + TS2cellset = 86, + + /// T_TS2CELL + TTs2cell = 87, + + /// NUM_MEOS_TYPES + NumMeosTypes = 88, + + } +} diff --git a/MEOS.NET/Enums/NullHandleType.g.cs b/MEOS.NET/Enums/NullHandleType.g.cs new file mode 100644 index 0000000..c0605a9 --- /dev/null +++ b/MEOS.NET/Enums/NullHandleType.g.cs @@ -0,0 +1,25 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS nullHandleType enum, from meos_json.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum NullHandleType + { + /// NULL_INVALID + NullInvalid = 0, + + /// NULL_ERROR + NullError = 1, + + /// NULL_JSON_NULL + NullJsonNull = 2, + + /// NULL_DELETE + NullDelete = 3, + + /// NULL_RETURN + NullReturn = 4, + + } +} diff --git a/MEOS.NET/Enums/PC_FILTERTYPE.g.cs b/MEOS.NET/Enums/PC_FILTERTYPE.g.cs new file mode 100644 index 0000000..89c994b --- /dev/null +++ b/MEOS.NET/Enums/PC_FILTERTYPE.g.cs @@ -0,0 +1,22 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS PC_FILTERTYPE enum, from pc_api.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum PC_FILTERTYPE + { + /// PC_GT + PcGt = 0, + + /// PC_LT + PcLt = 1, + + /// PC_EQUAL + PcEqual = 2, + + /// PC_BETWEEN + PcBetween = 3, + + } +} diff --git a/MEOS.NET/Enums/SPTreeKind.g.cs b/MEOS.NET/Enums/SPTreeKind.g.cs new file mode 100644 index 0000000..8accebd --- /dev/null +++ b/MEOS.NET/Enums/SPTreeKind.g.cs @@ -0,0 +1,16 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS SPTreeKind enum, from meos.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum SPTreeKind + { + /// SPTREE_QUADTREE + SptreeQuadtree = 0, + + /// SPTREE_KDTREE + SptreeKdtree = 1, + + } +} diff --git a/MEOS.NET/Enums/SkipListType.g.cs b/MEOS.NET/Enums/SkipListType.g.cs new file mode 100644 index 0000000..3cdf991 --- /dev/null +++ b/MEOS.NET/Enums/SkipListType.g.cs @@ -0,0 +1,16 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS SkipListType enum, from meos_internal.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum SkipListType + { + /// SKIPLIST_TEMPORAL + SkiplistTemporal = 0, + + /// SKIPLIST_KEYVALUE + SkiplistKeyvalue = 1, + + } +} diff --git a/MEOS.NET/Enums/SpatialRel.g.cs b/MEOS.NET/Enums/SpatialRel.g.cs new file mode 100644 index 0000000..6ac37b0 --- /dev/null +++ b/MEOS.NET/Enums/SpatialRel.g.cs @@ -0,0 +1,22 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS spatialRel enum, from meos_geo.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum SpatialRel + { + /// INTERSECTS + Intersects = 0, + + /// CONTAINS + Contains = 1, + + /// TOUCHES + Touches = 2, + + /// COVERS + Covers = 3, + + } +} diff --git a/MEOS.NET/Enums/TempSubtype.g.cs b/MEOS.NET/Enums/TempSubtype.g.cs new file mode 100644 index 0000000..67af2a0 --- /dev/null +++ b/MEOS.NET/Enums/TempSubtype.g.cs @@ -0,0 +1,22 @@ +#nullable enable + +namespace MEOS.NET.Enums +{ + /// The MEOS tempSubtype enum, from meos.h. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public enum TempSubtype + { + /// ANYTEMPSUBTYPE + Anytempsubtype = 0, + + /// TINSTANT + Tinstant = 1, + + /// TSEQUENCE + Tsequence = 2, + + /// TSEQUENCESET + Tsequenceset = 3, + + } +} diff --git a/MEOS.NET/Types/TFloatSeq.g.cs b/MEOS.NET/Types/TFloatSeq.g.cs index 22fc35c..f0860ca 100644 --- a/MEOS.NET/Types/TFloatSeq.g.cs +++ b/MEOS.NET/Types/TFloatSeq.g.cs @@ -14,7 +14,7 @@ internal TFloatSeq(IntPtr ptr) : base(ptr) { } public static Temporal? FromBaseTstzset(double d, Set s) => MEOSFactory.WrapTemporal(Meos.TfloatseqFromBaseTstzset(d, s.Ptr)); - public static Temporal? FromBaseTstzspan(double d, Span s, InterpolationType interp) + public static Temporal? FromBaseTstzspan(double d, Span s, InterpType interp) => MEOSFactory.WrapTemporal(Meos.TfloatseqFromBaseTstzspan(d, s.Ptr, (int) interp)); } diff --git a/MEOS.NET/Types/TFloatSeqSet.g.cs b/MEOS.NET/Types/TFloatSeqSet.g.cs index dd75d6f..e8b94c9 100644 --- a/MEOS.NET/Types/TFloatSeqSet.g.cs +++ b/MEOS.NET/Types/TFloatSeqSet.g.cs @@ -11,7 +11,7 @@ public class TFloatSeqSet : TFloat { internal TFloatSeqSet(IntPtr ptr) : base(ptr) { } - public static Temporal? FromBaseTstzspanset(double d, SpanSet ss, InterpolationType interp) + public static Temporal? FromBaseTstzspanset(double d, SpanSet ss, InterpType interp) => MEOSFactory.WrapTemporal(Meos.TfloatseqsetFromBaseTstzspanset(d, ss.Ptr, (int) interp)); } diff --git a/MEOS.NET/Types/TRGeometry.g.cs b/MEOS.NET/Types/TRGeometry.g.cs index b2acb04..f2875ce 100644 --- a/MEOS.NET/Types/TRGeometry.g.cs +++ b/MEOS.NET/Types/TRGeometry.g.cs @@ -149,7 +149,7 @@ public string Out() public new Temporal?[] Sequences() => MEOSFactory.WrapTemporalArray(Meos.TrgeometrySequences(this.Ptr)); - public new Temporal? SetInterp(InterpolationType interp) + public new Temporal? SetInterp(InterpType interp) => MEOSFactory.WrapTemporal(Meos.TrgeometrySetInterp(this.Ptr, (int) interp)); public Temporal? Speed() diff --git a/MEOS.NET/Types/Temporal.g.cs b/MEOS.NET/Types/Temporal.g.cs index de1f82a..c6329ef 100644 --- a/MEOS.NET/Types/Temporal.g.cs +++ b/MEOS.NET/Types/Temporal.g.cs @@ -23,10 +23,10 @@ public string AsMFJSON(bool with_bbox, int flags, int precision, string srs) public Temporal? AsTinstant() => MEOSFactory.WrapTemporal(Meos.TemporalAsTinstant(this.Ptr)); - public Temporal? AsTsequence(InterpolationType interp) + public Temporal? AsTsequence(InterpType interp) => MEOSFactory.WrapTemporal(Meos.TemporalAsTsequence(this.Ptr, (int) interp)); - public Temporal? AsTsequenceset(InterpolationType interp) + public Temporal? AsTsequenceset(InterpType interp) => MEOSFactory.WrapTemporal(Meos.TemporalAsTsequenceset(this.Ptr, (int) interp)); public Temporal? AtMax() @@ -194,7 +194,7 @@ public int NumTimestamps() public Temporal?[] Sequences() => MEOSFactory.WrapTemporalArray(Meos.TemporalSequences(this.Ptr)); - public Temporal? SetInterp(InterpolationType interp) + public Temporal? SetInterp(InterpType interp) => MEOSFactory.WrapTemporal(Meos.TemporalSetInterp(this.Ptr, (int) interp)); public Temporal? SimplifyDp(double dist, bool synchronized) diff --git a/tools/README.md b/tools/README.md index ab04148..c6c5cc6 100644 --- a/tools/README.md +++ b/tools/README.md @@ -9,8 +9,9 @@ C name in PascalCase — `tfloat_in` reads `TfloatIn`, `meos_initialize` reads ecosystem rather than a per-binding invention. `objectgen.py` regenerates `MEOS.NET/Types/*.g.cs` — the object layer — -and the error taxonomy under `MEOS.NET/Errors/` and `MEOS.NET/Exceptions/`, -from the same catalog's `objectModel`, which is the ecosystem-wide +the error taxonomy under `MEOS.NET/Errors/` and `MEOS.NET/Exceptions/`, and +one C# enum per catalog enum under `MEOS.NET/Enums/`, from the same catalog's +`objectModel` and `enums`, which is the ecosystem-wide source of truth for the class hierarchy implicit in MEOS. This replaces the previous regex-based `MEOS.NET.Builder` workflow, which diff --git a/tools/objectgen.py b/tools/objectgen.py index c5bdf83..8ca0212 100644 --- a/tools/objectgen.py +++ b/tools/objectgen.py @@ -35,6 +35,7 @@ GENERATOR_VERSION = "0.1.0" NAMESPACE = "MEOS.NET.Types" +ENUM_NAMESPACE = "MEOS.NET.Enums" ERROR_NAMESPACE = "MEOS.NET.Errors" EXCEPTION_NAMESPACE = "MEOS.NET.Exceptions" @@ -96,6 +97,19 @@ def pascal(oo_name: str) -> str: return oo_name[:1].upper() + oo_name[1:] +def enum_type_name(name: str) -> str: + """The C# name of a catalog enum: `interpType` reads `InterpType`, and a name + that already starts upper — `MeosType`, `SPTreeKind`, `ENDIANS` — stands.""" + return name[:1].upper() + name[1:] + + +def enum_member(value_name: str) -> str: + """The C# name of an enum constant: `INTERP_NONE` reads `InterpNone`, + `TSEQUENCE` reads `Tsequence` — each underscore-separated part capitalized, + the same rule the function names carry.""" + return "".join(part.capitalize() for part in value_name.lower().split("_") if part) + + def error_member(code_name: str) -> str: """The C# name of an errorCode constant: `MEOS_ERR_INVALID_ARG_VALUE` reads `InvalidArgValue`, `MEOS_ERR_MFJSON_INPUT` reads `MFJSONInput`.""" @@ -271,7 +285,7 @@ def map_param(self, c_type: str, cs_type: str, name: str) -> tuple[str, str] | N if c == "DateADT": return ("DateOnly", f"MEOSConvert.ToDateADT({name})") if c == "interpType": - return ("InterpolationType", f"(int) {name}") + return ("InterpType", f"(int) {name}") if c in PASSTHROUGH_C and cs_type != "IntPtr": return (cs_type, name) if cs_type == "string": @@ -475,6 +489,37 @@ def convert_file(self) -> str: }} ''' + # The error taxonomy has a file of its own, with an exception class per code; + # the plain enums are projected as they stand. + ENUM_EXCLUDE = ("errorCode",) + + def enum_file(self, enum: dict) -> str: + name = enum_type_name(enum["name"]) + lines = [ + "#nullable enable", + "", + f"namespace {ENUM_NAMESPACE}", + "{", + f" /// The MEOS {enum['name']} enum, from {enum.get('file', '')}.", + f' [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "{GENERATOR_VERSION}")]', + f" public enum {name}", + " {", + ] + seen: set[str] = set() + for value in enum.get("values", []): + member = enum_member(value["name"]) + if member in seen: + raise SystemExit( + f"objectgen: {enum['name']} has two values reading {member} in C#") + seen.add(member) + lines += [ + f" /// {value['name']}", + f" {member} = {value['value']},", + "", + ] + lines += [" }", "}", ""] + return "\n".join(lines) + def error_codes(self) -> list[dict]: """The error taxonomy the model carries, verbatim from MEOS's own enum.""" return self.m.om["errors"]["codes"] @@ -744,6 +789,21 @@ def run(self, out_dir: Path) -> None: (out_dir / f"{cls}.g.cs").write_text(self.emit_class(cls)) (out_dir / "MEOSFactory.g.cs").write_text(self.factory_file()) + def run_enums(self, enums_dir: Path) -> int: + """One C# enum per catalog enum, so a caller names a MEOS constant rather + than passing the int the C API takes.""" + if enums_dir.exists(): + shutil.rmtree(enums_dir) + enums_dir.mkdir(parents=True) + emitted = 0 + for enum in self.m.idl.get("enums", []): + if not enum.get("name") or enum["name"] in self.ENUM_EXCLUDE: + continue + (enums_dir / f"{enum_type_name(enum['name'])}.g.cs").write_text( + self.enum_file(enum)) + emitted += 1 + return emitted + def run_errors(self, errors_dir: Path, exceptions_dir: Path) -> None: for directory in (errors_dir, exceptions_dir): if directory.exists(): @@ -779,11 +839,12 @@ def main() -> int: gen.run(repo_root / "MEOS.NET" / "Types") gen.run_errors(repo_root / "MEOS.NET" / "Errors", repo_root / "MEOS.NET" / "Exceptions") + enums = gen.run_enums(repo_root / "MEOS.NET" / "Enums") classes = model.classes() total_deferred = sum(len(v) for v in gen.deferred.values()) print(f"objectgen: {len(classes)} classes, {gen.emitted} methods emitted, " - f"{total_deferred} deferred", file=sys.stderr) + f"{total_deferred} deferred, {enums} enums", file=sys.stderr) if args.report: for cls in classes: reasons = gen.deferred.get(cls, [])