import "Prelude" import "Random" /// Datatype /// "A data type component with component name and data type" @JavaType "org.simantics.databoard.type.Component" @FieldNames [name, "type"] data DatatypeComponent = DatatypeComponent String Datatype """A data type that represents the data types supported by the Simantics Databoard plugin.""" @JavaType "org.simantics.databoard.type.Datatype" data Datatype = @JavaType "org.simantics.databoard.type.BooleanType" BooleanType | @JavaType "org.simantics.databoard.type.ByteType" ByteType | @JavaType "org.simantics.databoard.type.IntegerType" IntegerType | @JavaType "org.simantics.databoard.type.LongType" LongType | @JavaType "org.simantics.databoard.type.FloatType" FloatType | @JavaType "org.simantics.databoard.type.DoubleType" DoubleType | @JavaType "org.simantics.databoard.type.StringType" StringType | @JavaType "org.simantics.databoard.type.ArrayType" @FieldNames [componentType] ArrayType Datatype | @JavaType "org.simantics.databoard.type.OptionalType" @FieldNames [componentType] OptionalType Datatype | @JavaType "org.simantics.databoard.type.MapType" @FieldNames [keyType, valueType] MapType Datatype Datatype | @JavaType "org.simantics.databoard.type.RecordType" @FieldNames [components] RecordType (Vector DatatypeComponent) | @JavaType "org.simantics.databoard.type.UntionType" @FieldNames [components] UnionType (Vector DatatypeComponent) | @JavaType "org.simantics.databoard.type.VariantType" VariantType importJava "org.simantics.databoard.type.Datatype" where @private @JavaName toString showDatatype :: Datatype -> String "Get the number of type components in an data type" @JavaName getComponentCount datatypeCompnentCount :: Datatype -> Integer "Get a component type of a composite data type" @JavaName getComponentType datatypeComponentType :: Datatype -> ChildReference -> Datatype instance Show Datatype where show = showDatatype /// Binding /// importJava "org.simantics.databoard.binding.Binding" where "Check whether a dynamic object is an instance of a given binding" @JavaName isInstance isBindingInstance :: Binding Dynamic -> Dynamic -> Boolean "Create a serializable object from a textual representation" parseValueDefinition :: Serializable a => String -> a "Compare two serializable objects\n\nResult is -1, 0 or 1 depending the partial ordering of the objects." @JavaName compare compareObjects :: Serializable a => a -> a -> Integer "The default value of a serializable type" @JavaName createDefault serializableDefaultValue :: Serializable a => a "Create a random value of a serializable type" @JavaName createRandom serializableRandomValue :: Serializable a => a "Get a textual representation of a serializable value" @JavaName toString showSerializable :: Serializable a => a -> String @private @JavaName getComponent getSerializableComponent_ :: Serializable a => a -> ChildReference -> Binding b -> b "Get a component binding" @JavaName getComponentBinding getComponentBinding :: Binding a -> ChildReference -> Binding b "Get a child data component of a composite serializable value" getSerializableComponent :: Serializable a => Serializable b => a -> ChildReference -> b getSerializableComponent object ref = getSerializableComponent_ object ref binding /// Serializer /// importJava "org.simantics.databoard.serialization.Serializer" where "A data serializer for SCL type a" data Serializer a @private @JavaName "serialize" serialize_ :: Serializer a -> a -> ByteArray @private @JavaName "deserialize" deserialize_ :: Serializer a -> ByteArray -> a importJava "org.simantics.databoard.Bindings" where @private @JavaName "getSerializer" serializerOf :: Binding a -> Serializer a @private @JavaName toString bindingToString :: Binding a -> String "Adapt between types using explicitly provided binding objects: `adapt_ value from to`" @JavaName adapt adapt_ :: a -> Binding a -> Binding b -> b "Adapt value from one serializable type to another" adapt :: Serializable a => Serializable b => a -> b adapt x = adapt_ x binding binding instance Show (Binding a) where show = bindingToString "Serializes a value to a byte array using default serializer." serialize :: Serializable a => a -> ByteArray serialize v = serialize_ (serializerOf binding) v "Deserializes a value from a byte array using default serializer." deserialize :: Serializable a => ByteArray -> a deserialize ba = deserialize_ (serializerOf binding) ba importJava "org.simantics.databoard.Bindings" where "Get a default binding for a given data type" @JavaName getBinding datatypeBinding :: Datatype -> Binding Dynamic importJava "org.simantics.databoard.Datatypes" where "Get a data type from a string representation" @JavaName translate translateDatatype :: String -> Datatype importJava "org.simantics.databoard.binding.mutable.Variant" where // data Variant (in Builtins) "Create a variant using an explicitly provided binding value (unchecked cast)" @JavaName "" createVariant_ :: Binding Dynamic -> Dynamic -> Variant "Get the data type of a variant object" @JavaName "type" variantDatatype :: Variant -> Datatype "Get raw value contained by a variant (unchecked cast)" @JavaName getValue rawVariantValue :: Variant -> a "Create a variant from a raw object (based on Java class)" @JavaName ofInstance variantOf :: a -> Variant "Create a variant with explicitly provided binding and value" @JavaName "" variant_ :: Binding a -> a -> Variant "Get value from a variant using a given binding" @JavaName getValue variantValue_ :: Variant -> Binding a -> a @private @JavaName toString showVariant :: Variant -> String "Get a component of compound data value in a variant" @JavaName getComponent variantComponent :: Variant -> ChildReference -> Variant "Create a variant of a given data type from an object in the default binding (unchecked, use with extreme caution)" createVariant :: Datatype -> Dynamic -> Variant createVariant dt v = createVariant_ (datatypeBinding dt) v "Create a variant from a serializable value" variant :: Serializable a => a -> Variant variant v = variant_ binding v "Get the value of a variant in a serializable type" variantValue :: Serializable a => Variant -> a variantValue v = variantValue_ v binding instance Show Variant where show = showVariant "Get an element of a compound variant value using an index reference" variantElement :: Serializable a => Variant -> Integer -> a variantElement v i = variantValue (variantComponent v (indexReference i)) importJava "org.simantics.databoard.accessor.reference.ChildReference" where "A reference to a child element in a composite data type/binding or value" data ChildReference "Combine a list of child data object references into a single path reference" @JavaName compile compileReference :: [ChildReference] -> ChildReference importJava "org.simantics.databoard.accessor.reference.IndexReference" where """Get a reference to a child data object using an index (zero-based) * Element index of an array object * Field index of a record or union type * 0: * Key component of a map type/binding * Component of any single-component type/binding (optional, array) * Contained value/type of any single-element object (optional, union, variant) * 1: * Value component of a map type/binding """ @JavaName "" indexReference :: Integer -> ChildReference importJava "org.simantics.databoard.accessor.reference.KeyReference" where """Get a reference to a MapType child data object using a given key value * Contained value of a map object for a given key value """ @JavaName "" keyReference :: Variant -> ChildReference importJava "org.simantics.databoard.accessor.reference.NameReference" where """Get a reference to a child data object using a field name * A component name of a record or union data type/binding * "key": The key component of a map data type/binding * "value": The value component of a map data type/binding """ @JavaName "" nameReference :: String -> ChildReference importJava "org.simantics.databoard.accessor.reference.LabelReference" where """Get a reference to a child data object using a label * A component name of a record or union data type/binding * A string representation of the index of a record or union data type/binding component * "v": The component type of an array/optional data type/binding * "0"/"key": The key component of a map data type/binding * "1"/"value": The value component of a map data type/binding """ @JavaName "" labelReference :: String -> ChildReference importJava "org.simantics.databoard.accessor.reference.ComponentReference" where """Get a reference to a component child data object * Component of an array/optional data type/binding * Contained value of an optional/variant/union object """ @JavaName "" componentReference :: ChildReference