SetDatatypePropertyEx
The value of card gives the actual card of the values list.
The list values of undefined (void) items is a list of booleans, chars, integers
or doubles, this list has a length as given in the values card. The actual used type
is given by the definition of the dataTypeProperty.
The return value always should be 0, if not something is wrong in the way this property is called.
This call has the same behavior as SetDatatypeProperty, however needs to be
used in case properties are exchanged as a successive series of integers.
Note: the client application needs to make sure the cardinality of
the property is within the boundaries.
Syntax
public const string enginedll = @"engine.dll"; [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref byte values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref byte values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref byte values, Int64 card) { if (IntPtr.Size == 4) { byte _values = (byte)values; var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref _values, card); values = _values; return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref values, card); } } [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, byte[] values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, byte[] values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, byte[] values, Int64 card) { if (IntPtr.Size == 4) { var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); } } [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref Int64 values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref Int64 values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref Int64 values, Int64 card) { if (IntPtr.Size == 4) { Int64 _values = (Int64)values; var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref _values, card); values = _values; return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref values, card); } } [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, Int64[] values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, Int64[] values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, Int64[] values, Int64 card) { if (IntPtr.Size == 4) { var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); } } [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref double values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref double values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref double values, Int64 card) { if (IntPtr.Size == 4) { double _values = (double)values; var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref _values, card); values = _values; return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref values, card); } } [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, double[] values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, double[] values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, double[] values, Int64 card) { if (IntPtr.Size == 4) { var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); } } [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref string values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref string values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, ref string values, Int64 card) { if (IntPtr.Size == 4) { string _values = (string)values; var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref _values, card); values = _values; return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, ref values, card); } } [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x86_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, string[] values, Int64 card); [DllImport(enginedll, EntryPoint = "SetDatatypePropertyEx")] public static extern Int64 x64_SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, string[] values, Int64 card); public static Int64 SetDatatypePropertyEx(Int64 model, Int64 rdfsResource, Int64 owlDatatypeProperty, string[] values, Int64 card) { if (IntPtr.Size == 4) { var _result = x86_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); return _result; } else { return x64_SetDatatypePropertyEx(model, rdfsResource, owlDatatypeProperty, values, card); } }
Property model
Size: 64 bit / 8 byte (value)Property rdfsResource
Size: 64 bit / 8 byte (value)???.
Property owlDatatypeProperty
Size: 64 bit / 8 byte (value)Property values
Size: 32 bit / 4 byte (reference)Property card
Size: 64 bit / 8 byte (value)
Example (based on pure API calls)
Here you can find code snippits that show how the API call SetDatatypePropertyEx can be used.
using RDF; // include at least engine.cs within your solution static void Main(string[] args) { Int64 model = RDF.engine.CreateModel(); if (model != 0) { // // The following setting makes sure all instance handles are in an ordered list // In certain cases where several models are open or in case of conversion // between formats this can be handy and / or time efficient. // Int64 instanceCnt = 0; Engine.x86_64.OrderedHandles(model, (IntPtr) 0, (IntPtr) 0, out instanceCnt, 4, 4); System.Diagnostics.Debug.Assert(instanceCnt == 0); // // Classes // Int64 classAbcd = RDF.engine.CreateClass(model, "ABCD"); // // Datatype Properties (attributes) // Int64 propertyAb = RDF.engine.CreateProperty(model, RDF.engine.DATATYPEPROPERTY_TYPE_BOOLEAN, "Ab"), propertyCd = RDF.engine.CreateProperty(model, RDF.engine.DATATYPEPROPERTY_TYPE_CHAR, "Cd"), propertyEf = RDF.engine.CreateProperty(model, RDF.engine.DATATYPEPROPERTY_TYPE_INTEGER, "Ef"), propertyGh = RDF.engine.CreateProperty(model, RDF.engine.DATATYPEPROPERTY_TYPE_DOUBLE, "Gh"); // // Instances // Int64 instanceAbcd = RDF.engine.CreateInstance(classAbcd, (string) null); System.Diagnostics.Debug.Assert(instanceAbcd == instanceCnt + 1); // // Set Properties // { bool[] valuesAb = { true, false }; byte[] valuesAb_inByte = valuesAb.Select((v) => { return v ? (byte) 1 : (byte) 0; }).ToArray(); RDF.engine.SetDatatypePropertyEx(model, instanceAbcd, propertyAb, valuesAb_inByte, 2); string[] valuesCd = { "First Line", "Second Line" }; RDF.engine.SetDatatypePropertyEx(model, instanceAbcd, propertyCd, valuesCd, 2); Int64[] valuesEf = { 1234, 5678 }; RDF.engine.SetDatatypePropertyEx(model, instanceAbcd, propertyEf, valuesEf, 2); double[] valuesGh = { 12.34, 56.78 }; RDF.engine.SetDatatypePropertyEx(model, instanceAbcd, propertyGh, valuesGh, 2); } // // Get Properties // { Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; RDF.engine.GetDatatypePropertyEx(model, instanceAbcd, propertyAb, out valuesPtr, out card); System.Diagnostics.Debug.Assert(card == 2); if (card > 0) { byte[] values_inByte = new byte[card]; System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values_inByte, 0, (int)card); bool[] values = values_inByte.Select((v) => { return v != 0; }).ToArray(); System.Diagnostics.Debug.Assert(values[0] == true && values[1] == false); } } { Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; RDF.engine.GetDatatypePropertyEx(model, instanceAbcd, propertyCd, out valuesPtr, out card); System.Diagnostics.Debug.Assert(card == 2); if (card > 0) { IntPtr[] valuesRef = new IntPtr[card]; System.Runtime.InteropServices.Marshal.Copy(valuesPtr, valuesRef, 0, (int) card); string[] values = new string[card]; for (int i = 0; i < (int) card; i++) { values[i] = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(valuesRef[i]); } System.Diagnostics.Debug.Assert(values[0].Equals("First Line") && values[1].Equals("Second Line")); } } { Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; RDF.engine.GetDatatypePropertyEx(model, instanceAbcd, propertyEf, out valuesPtr, out card); System.Diagnostics.Debug.Assert(card == 2); if (card > 0) { Int64[] values = new Int64[card]; System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card); System.Diagnostics.Debug.Assert(values[0] == 1234 && values[1] == 5678); } } { Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; RDF.engine.GetDatatypePropertyEx(model, instanceAbcd, propertyGh, out valuesPtr, out card); System.Diagnostics.Debug.Assert(card == 2); if (card > 0) { double[] values = new double[card]; System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card); System.Diagnostics.Debug.Assert(values[0] == 12.34 && values[1] == 56.78); } } // // The same can be applied to existing classes and properties // // // Classes // Int64 classCylinder = RDF.engine.GetClassByName(model, "Cylinder"); // // Datatype Properties (attributes) // Int64 propertyClosed = RDF.engine.GetPropertyByName(model, "closed"), propertyLength = RDF.engine.GetPropertyByName(model, "length"), propertyName = RDF.engine.GetPropertyByName(model, "name"), propertyRadius = RDF.engine.GetPropertyByName(model, "radius"), propertySegmentationParts = RDF.engine.GetPropertyByName(model, "segmentationParts"); // // Instances (creating) // Int64 myInstanceCylinder = RDF.engine.CreateInstance(classCylinder, (string) null); System.Diagnostics.Debug.Assert(myInstanceCylinder == instanceCnt + 2); double length = 1.8, radius = 1.3; Int64 segmentationParts = 36; RDF.engine.SetDatatypePropertyEx(model, myInstanceCylinder, propertyLength, ref length, 1); RDF.engine.SetDatatypePropertyEx(model, myInstanceCylinder, propertyRadius, ref radius, 1); RDF.engine.SetDatatypePropertyEx(model, myInstanceCylinder, propertySegmentationParts, ref segmentationParts, 1); // // non related / restricted properties (user defined and pre defined) can be connected in any quantity // bool closed = true; string name = "Example text added"; byte closed_inByte = closed ? (byte) 1 : (byte) 0; RDF.engine.SetDatatypePropertyEx(model, myInstanceCylinder, propertyClosed, ref closed_inByte, 1); RDF.engine.SetDatatypePropertyEx(model, myInstanceCylinder, propertyName, ref name, 1); // // The resulting model can be viewed in 3D-Editor.exe // RDF.engine.SaveModel(model, "c:\\created\\myFile.bin"); RDF.engine.CloseModel(model); } }