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