update readme

This commit is contained in:
a-Sansara 2018-08-18 23:22:55 +02:00
parent e4c554df3d
commit f620de7980

View File

@ -259,13 +259,19 @@ on yaml side, proceed like that :
type_uint : !v!uint 62005 type_uint : !v!uint 62005
type_float : !v!float 42.36 type_float : !v!float 42.36
type_double : !v!double 95542123.4579512128 type_double : !v!double 95542123.4579512128
!v!Pluie.Yaml.SubExample type_object : !v!Pluie.Yaml.ExampleChild type_object :
toto : totovalue1 toto : totovalue1
tata : tatavalue1 tata : tatavalue1
titi : 123 titi : 123
tutu : 1 tutu : 1
``` ```
**note :**
only the first level of yaml node matching a vala object need a tag.
**pluie-yaml** has mechanisms to retriew properties types of a Yaml.Object.
So basic vala types tag, enum tag, struct tag and derived Yaml.Object (here ExampleChild)
or GLib.Object vala tags are not necessary inside a Yaml.Object.
on vala side : on vala side :
```vala ```vala
@ -279,13 +285,13 @@ on vala side :
### Builder ### Builder
**pluie-yaml** has automatic mechanisms to build Yaml.Object instances (and derived classes) **pluie-yaml** provide a Yaml.Builder which has automatic mechanisms to build Yaml.Object instances (and derived classes)
and set basics types properties, enum properties and based Yaml.Object properties. and set basics types properties, enum properties and based Yaml.Object properties from Yaml.node.
Other types like struct or native GLib.Object (Gee.ArrayList for example) properties need some stuff in order to populate instances appropriately Other types like struct or native GLib.Object (Gee.ArrayList for example) properties need some stuff in order to be populated appropriately
We cannot do introspection on Structure's properties, so you need to implement a method which will do the job. We cannot do introspection on Structure's properties, so you need to implement a method which will do the job.
First at all you need to register in the static construct, (properties) types that need some glue for instanciation. First at all, in the static construct of your class, you need to register (properties) types that need some glue for instanciation.
```vala ```vala
public class Example : Yaml.Object public class Example : Yaml.Object
@ -303,21 +309,19 @@ Secondly you must override the `Yaml.Object populate_by_type (Glib.Typem Yaml.No
Example of implementation from `src/vala/Pluie/Yaml.Example.vala` : Example of implementation from `src/vala/Pluie/Yaml.Example.vala` :
``` ```vala
public override void populate_by_type(GLib.Type type, Yaml.Node node) public override void populate_by_type(GLib.Type type, Yaml.Node node)
{ {
switch (type) { if (type == typeof (Yaml.ExampleStruct)) {
case typeof (Yaml.ExampleStruct) : this.type_struct = ExampleStruct.from_yaml_node (node);
this.type_struct = ExampleStruct.from_yaml_node (node); }
break; else if (type == typeof (Gee.ArrayList)) {
case typeof (Gee.ArrayList) : this.type_gee_al = new Gee.ArrayList<string> ();
this.type_gee_al = new Gee.ArrayList<string> (); if (!node.empty ()) {
if (!node.empty ()) { foreach (var child in node) {
foreach (var child in node) { this.type_gee_al.add(child.data);
this.type_gee_al.add(child.data);
}
} }
break; }
} }
} }
``` ```