]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src-isv/doc/datatype.mediawiki
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src-isv / doc / datatype.mediawiki
1 =Datatype=
2 In Databoard all values have a type representation, [../javadoc/org/simantics/databoard/type/Datatype.html|Datatype]. 
3 It is the base abstract class for all concrete type classes (See table below). 
4 There is a facade class utility ([../javadoc/org/simantics/databoard/Datatypes.html|Datatypes]) that provides functions to most of the Datatype library's features.
5
6 '''[../javadoc/org/simantics/databoard/type|org.simantics.databoard.type]'''.
7 {| style="background-color: #f9f9f9; border: 1px solid #aaaaaa; "
8 |- style="background-color: #e9e9e9; " |
9 | '''Class''' || '''Description'''
10 |- 
11 | [../javadoc/org/simantics/databoard/type/Datatype.html|Datatype] || Base class for all data types
12 |- 
13 | [../javadoc/org/simantics/databoard/type/RecordType.html|RecordType] || Record 
14 |- 
15 | [../javadoc/org/simantics/databoard/type/ArrayType.html|ArrayType] || Array - an ordered sequence of elements of one type.
16 |- 
17 | [../javadoc/org/simantics/databoard/type/MapType.html|MapType] || Map - an ordered map of keys to values. 
18 |- 
19 | [../javadoc/org/simantics/databoard/type/UnionType.html|UnionType] || Union
20 |- 
21 | [../javadoc/org/simantics/databoard/type/BooleanType.html|BooleanType],[../javadoc/org/simantics/databoard/type/IntType.html|IntType],[../javadoc/org/simantics/databoard/type/LongType.html|LongType],[../javadoc/org/simantics/databoard/type/FloatType.html|FloatType],[../javadoc/org/simantics/databoard/type/DoubleType.html|DoubleType]
22 | Primitive and numeric types
23 |- 
24 | [../javadoc/org/simantics/databoard/type/StringType.html|StringType] || String 
25 |- 
26 | [../javadoc/org/simantics/databoard/type/OptionalType.html|OptionalType] || Optional value
27 |- 
28 | [../javadoc/org/simantics/databoard/type/VariantType.html|VariantType] || Variant value
29 |}
30
31
32 Datatype can be acquired or created using one of the following methods:
33 * Construct new
34 * Constant 
35 * [[binding#Reflection|Reflection]]-Read from a Class
36 * Read from string of [[Databoard_Specification|the text notation]].
37 <pre class="code">
38     Datatype type = new DoubleType();
39     Datatype type = Datatypes.DOUBLE;
40     Datatype type = Datatypes.getDatatype( Double.class );
41     
42     Datatypes.addDefinition("type Node = { id : String; children : Node[] }");
43     Datatype type = Datatypes.getDatatype("Node");
44 </pre>
45
46 ==Parsing==
47 Datatypes are parsed using <code>Datatypes.DatatypeRepository</code>. 
48 <pre class="code">
49     Datatypes.addDefinition("type Node = { id : String; children : Node[] }");
50     Datatype type = Datatypes.getDatatype("Node");
51 </pre>
52
53 Types are printed to types and definitions with 
54 <pre class="code">
55     String type = type.toString();
56     
57     DatatypeRepository repo = new DatatypeRepository();
58     repo.add("temp1", type);
59     String typeDef = repo.toString();
60 </pre>
61
62 ==Structure Example==
63 A node is a recursive type. With databoard typesystem it could be stated as
64 <pre class="code">
65   type Node = {
66          id : String;
67          displayNames : LocalizedTexts;
68          children : Node[];
69          value : Optional(Variant);
70        }
71 </pre>
72
73 [[Image:NodeType.png|Type presented as tree]]
74
75
76 A couple of instances with Databoard value notation:
77 <pre class="code">
78   root : Node = {
79            id = \93PI_01\94
80            displayNames = map{ \93en\94 = \93Instrument \93 }
81            children = 
82             [ 
83               {id=\94Child\94
84                displayNames = map{ \93en\94 = \93Child\94} },
85                value = 5 : Integer
86               }
87             ]
88            value = \93<root>\94 : String
89          }
90 </pre>
91
92 [[Image:NodeInstance.png|Node values preseted as tree]]