Compare commits
No commits in common. "master" and "0.60" have entirely different histories.
25
README.md
25
README.md
|
@ -45,28 +45,11 @@ sudo ninja install -C build
|
||||||
## Compilation
|
## Compilation
|
||||||
|
|
||||||
```
|
```
|
||||||
valac --pkg glib-2.0 \
|
valac --pkg pluie-echo-0.2 --pkg pluie-yaml-0.4 main.vala
|
||||||
--pkg gobject-2.0 \
|
|
||||||
--pkg gmodule-2.0 \
|
|
||||||
--pkg gio-2.0 \
|
|
||||||
--pkg gee-0.8 \
|
|
||||||
--pkg pluie-echo-0.2 \
|
|
||||||
--pkg pluie-yaml-0.4 \
|
|
||||||
main.vala
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can use `./build.sh` to rebuild/install the **pluie-yaml** lib and compile samples files
|
You can use `./build.sh` to rebuild/install the **pluie-yaml** lib and compile samples files
|
||||||
|
|
||||||
```
|
|
||||||
# rebuild lib + build all samples
|
|
||||||
./build.sh
|
|
||||||
# rebuild lib + build only single sample (give sample file name without extension)
|
|
||||||
./build.sh yaml-serialize
|
|
||||||
# rebuild lib in local mode
|
|
||||||
# local mode avoid to rebuild when modifying yaml files in resources dir
|
|
||||||
# must be in the root directory
|
|
||||||
./build.sh yaml-serialize 1
|
|
||||||
```
|
|
||||||
|
|
||||||
## Api / Documentation
|
## Api / Documentation
|
||||||
|
|
||||||
|
@ -396,9 +379,9 @@ Once your class has this glue, you can deal with complex object and populate the
|
||||||
directly from yaml files.
|
directly from yaml files.
|
||||||
|
|
||||||
for more details see :
|
for more details see :
|
||||||
* `src/vala/Pluie/Samples.YamlObject.vala`
|
* `src/vala/Pluie/Yaml.Example.vala`
|
||||||
* `src/vala/Pluie/Samples.YamlChild.vala`
|
* `src/vala/Pluie/Yaml.ExampleChild.vala`
|
||||||
* `src/vala/Pluie/Samples.YamlStruct.vala`
|
* `src/vala/Pluie/Yaml.ExampleStruct.vala`
|
||||||
* `samples/yaml-tag.vala`
|
* `samples/yaml-tag.vala`
|
||||||
|
|
||||||
code from samples/yaml-tag.vala :
|
code from samples/yaml-tag.vala :
|
||||||
|
|
|
@ -43,35 +43,3 @@
|
||||||
tata : tatavalue4
|
tata : tatavalue4
|
||||||
titi : 44
|
titi : 44
|
||||||
tutu : 0
|
tutu : 0
|
||||||
!v!Gee.HashMap type_gee_hmap :
|
|
||||||
- key : key1
|
|
||||||
!v!Pluie.Samples.YamlChild val :
|
|
||||||
toto : key1toto
|
|
||||||
tata : kay1tata
|
|
||||||
titi : 5
|
|
||||||
tutu : 0
|
|
||||||
- key : key2
|
|
||||||
val :
|
|
||||||
toto : key2toto
|
|
||||||
tata : kay2tata
|
|
||||||
titi : 46
|
|
||||||
tutu : 1
|
|
||||||
!v!Gee.HashMap type_gee_hmap2 :
|
|
||||||
- !v!Pluie.Samples.YamlStruct key :
|
|
||||||
red : !v!uint8 214
|
|
||||||
green : !v!uint8 78
|
|
||||||
blue : 153
|
|
||||||
!v!Pluie.Samples.YamlChild val :
|
|
||||||
toto : key1toto
|
|
||||||
tata : kay1tata
|
|
||||||
titi : 5
|
|
||||||
tutu : 0
|
|
||||||
- key :
|
|
||||||
red : !v!uint8 82
|
|
||||||
green : !v!uint8 109
|
|
||||||
blue : 35
|
|
||||||
val :
|
|
||||||
toto : key2toto
|
|
||||||
tata : kay2tata
|
|
||||||
titi : 46
|
|
||||||
tutu : 1
|
|
||||||
|
|
|
@ -27,6 +27,36 @@
|
||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
|
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||||
|
* @version : 0.5
|
||||||
|
* @type : library
|
||||||
|
* @date : 2018
|
||||||
|
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||||
|
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||||
|
* @copyright : pluie.org <http://www.pluie.org/>
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* This file is part of pluie-yaml.
|
||||||
|
*
|
||||||
|
* pluie-yaml is free software (free as in speech) : you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
|
||||||
using GLib;
|
using GLib;
|
||||||
using Gee;
|
using Gee;
|
||||||
using Pluie;
|
using Pluie;
|
||||||
|
@ -67,31 +97,6 @@ public void test_object(Samples.YamlObject obj)
|
||||||
of.keyval(" tutu" , "%s (bool)" .printf(child.tutu.to_string ()));
|
of.keyval(" tutu" , "%s (bool)" .printf(child.tutu.to_string ()));
|
||||||
child.method_a ();
|
child.method_a ();
|
||||||
}
|
}
|
||||||
if (obj.type_gee_hmap != null) {
|
|
||||||
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(obj.type_gee_hmap.get_type ().name (), obj.type_gee_hmap.key_type.name (), obj.type_gee_hmap.value_type.name ()));
|
|
||||||
foreach (var child in obj.type_gee_hmap.entries) {
|
|
||||||
of.echo(" == entry (%s) ==".printf(child.key));
|
|
||||||
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
|
|
||||||
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
|
|
||||||
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
|
|
||||||
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (obj.type_gee_hmap2 != null) {
|
|
||||||
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(obj.type_gee_hmap2.get_type ().name (), obj.type_gee_hmap2.key_type.name (), obj.type_gee_hmap2.value_type.name ()));
|
|
||||||
foreach (var child in obj.type_gee_hmap2.entries) {
|
|
||||||
of.echo(" == key ==");
|
|
||||||
of.keyval(" obj :" , "%s" .printf(child.key.to_string ()));
|
|
||||||
of.echo(" == val (%s) ==".printf(child.value.get_type ( ).name ()));
|
|
||||||
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
|
|
||||||
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
|
|
||||||
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
|
|
||||||
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
of.echo ("hmap2 null");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,31 +129,6 @@ int main (string[] args)
|
||||||
child.method_a ();
|
child.method_a ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o.type_gee_hmap != null) {
|
|
||||||
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(o.type_gee_hmap.get_type ().name (), o.type_gee_hmap.key_type.name (), o.type_gee_hmap.value_type.name ()));
|
|
||||||
foreach (var child in o.type_gee_hmap.entries) {
|
|
||||||
of.echo(" == entry (%s) ==".printf(child.key));
|
|
||||||
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
|
|
||||||
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
|
|
||||||
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
|
|
||||||
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (o.type_gee_hmap2 != null) {
|
|
||||||
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(o.type_gee_hmap2.get_type ().name (), o.type_gee_hmap2.key_type.name (), o.type_gee_hmap2.value_type.name ()));
|
|
||||||
foreach (var child in o.type_gee_hmap2.entries) {
|
|
||||||
of.echo(" == key ==");
|
|
||||||
of.keyval(" obj :" , "%s" .printf(child.key.to_string ()));
|
|
||||||
of.echo(" == val (%s) ==".printf(child.value.get_type ( ).name ()));
|
|
||||||
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
|
|
||||||
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
|
|
||||||
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
|
|
||||||
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
of.echo ("hmap2 null");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,6 @@ public class Pluie.Samples.YamlObject : Yaml.Object
|
||||||
public Samples.YamlStruct type_struct { get; set; }
|
public Samples.YamlStruct type_struct { get; set; }
|
||||||
public Gee.ArrayList<double?> type_gee_al { get; set; }
|
public Gee.ArrayList<double?> type_gee_al { get; set; }
|
||||||
public Gee.ArrayList<Samples.YamlChild> type_gee_alobject { get; set; }
|
public Gee.ArrayList<Samples.YamlChild> type_gee_alobject { get; set; }
|
||||||
public Gee.HashMap<string, Samples.YamlChild> type_gee_hmap { get; set; }
|
|
||||||
public Gee.HashMap<YamlStruct?, Samples.YamlChild> type_gee_hmap2 { get; set; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -77,8 +75,7 @@ public class Pluie.Samples.YamlObject : Yaml.Object
|
||||||
typeof (Samples.YamlObject),
|
typeof (Samples.YamlObject),
|
||||||
typeof (Samples.YamlChild),
|
typeof (Samples.YamlChild),
|
||||||
typeof (Samples.YamlStruct),
|
typeof (Samples.YamlStruct),
|
||||||
typeof (Gee.ArrayList),
|
typeof (Gee.ArrayList)
|
||||||
typeof (Gee.HashMap)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +86,6 @@ public class Pluie.Samples.YamlObject : Yaml.Object
|
||||||
{
|
{
|
||||||
this.type_gee_al = new Gee.ArrayList<double?> ();
|
this.type_gee_al = new Gee.ArrayList<double?> ();
|
||||||
this.type_gee_alobject = new Gee.ArrayList<Samples.YamlChild> ();
|
this.type_gee_alobject = new Gee.ArrayList<Samples.YamlChild> ();
|
||||||
this.type_gee_hmap = new Gee.HashMap<string, Samples.YamlChild> ();
|
|
||||||
this.type_gee_hmap2 = new Gee.HashMap<Samples.YamlStruct?, Samples.YamlChild> ();
|
|
||||||
Yaml.Register.add_namespace("Gee", "Pluie.Samples");
|
Yaml.Register.add_namespace("Gee", "Pluie.Samples");
|
||||||
Dbg.msg ("%s (%s) instantiated".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
|
Dbg.msg ("%s (%s) instantiated".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
|
||||||
}
|
}
|
||||||
|
@ -122,24 +117,6 @@ public class Pluie.Samples.YamlObject : Yaml.Object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == typeof (Gee.HashMap)) {
|
|
||||||
Yaml.Mapping? c;
|
|
||||||
foreach (var child in node) {
|
|
||||||
c = child as Yaml.Mapping;
|
|
||||||
switch (name) {
|
|
||||||
case "type_gee_hmap":
|
|
||||||
Value key = c.item ("key").val (typeof (string));
|
|
||||||
var entry = (Samples.YamlChild) Yaml.Builder.from_node (c.item ("val"), typeof (Samples.YamlChild));
|
|
||||||
this.type_gee_hmap.set((string) key, entry);
|
|
||||||
break;
|
|
||||||
case "type_gee_hmap2":
|
|
||||||
var key = Samples.YamlStruct.from_yaml_node (c.item ("key"));
|
|
||||||
var entry = (Samples.YamlChild) Yaml.Builder.from_node (c.item ("val"), typeof (Samples.YamlChild));
|
|
||||||
this.type_gee_hmap2.set(key, entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
var obj = Yaml.Builder.from_node(node, type);
|
var obj = Yaml.Builder.from_node(node, type);
|
||||||
if (name == "type_object") {
|
if (name == "type_object") {
|
||||||
|
@ -170,35 +147,9 @@ public class Pluie.Samples.YamlObject : Yaml.Object
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == typeof (Gee.HashMap)) {
|
|
||||||
switch (name) {
|
|
||||||
case "type_gee_hmap" :
|
|
||||||
Yaml.Object.objects_mapkstr_to_node (this.type_gee_hmap, name, parent);
|
|
||||||
break;
|
|
||||||
case "type_gee_hmap2" :
|
|
||||||
this.hmap2_to_node (name, parent);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
base.populate_to_node (name, type, parent);
|
base.populate_to_node (name, type, parent);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void hmap2_to_node (string name, Yaml.Node? parent = null)
|
|
||||||
{
|
|
||||||
of.echo (Log.METHOD);
|
|
||||||
var node = new Yaml.Sequence (parent, name);
|
|
||||||
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(this.type_gee_hmap2.get_type ()), "v");
|
|
||||||
var i = 0;
|
|
||||||
foreach (var child in this.type_gee_hmap2.entries) {
|
|
||||||
var entryNode = new Yaml.Mapping (node, "_%d".printf (i));
|
|
||||||
entryNode.add (child.key.to_yaml_node ("key"));
|
|
||||||
Yaml.Builder.to_node ((GLib.Object) child.value, entryNode, false, null, "val");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,53 +127,18 @@ public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
*/
|
*/
|
||||||
public static Yaml.Node? objects_collection_to_node (Gee.Collection list, string name, Yaml.Node? parent = null)
|
public static Yaml.Node? objects_collection_to_node (Gee.Collection list, string name, Yaml.Node? parent = null)
|
||||||
{
|
{
|
||||||
|
of.echo (Log.METHOD);
|
||||||
var node = new Yaml.Sequence (parent, name);
|
var node = new Yaml.Sequence (parent, name);
|
||||||
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(list.get_type ()), "v");
|
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(list.get_type ()), "v");
|
||||||
var it = list.iterator ();
|
var it = list.iterator ();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (it.next ()) {
|
while (it.next ()) {
|
||||||
Yaml.Builder.to_node ((GLib.Object) it.get (), node, false, i++);
|
Yaml.Builder.to_node (
|
||||||
}
|
(GLib.Object) it.get (),
|
||||||
return node;
|
node,
|
||||||
}
|
false,
|
||||||
|
i++
|
||||||
/**
|
);
|
||||||
* build an object Gee.HashMap<string, Yaml.Object> to a Yaml.Node
|
|
||||||
* @param map the gee hashmap to transform
|
|
||||||
* @param name name of map sequence node
|
|
||||||
* @param parent parent node of the map
|
|
||||||
* @return the resulting Yaml.Node
|
|
||||||
*/
|
|
||||||
public static Yaml.Node? objects_mapkstr_to_node (Gee.HashMap map, string name, Yaml.Node? parent = null)
|
|
||||||
{
|
|
||||||
var node = new Yaml.Sequence (parent, name);
|
|
||||||
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(map.get_type ()), "v");
|
|
||||||
var i = 0;
|
|
||||||
foreach (var child in map.entries) {
|
|
||||||
var entryNode = new Yaml.Mapping (node, "_%d".printf (i++));
|
|
||||||
new Yaml.Mapping.with_scalar (entryNode, "key", (string) child.key);
|
|
||||||
Yaml.Builder.to_node ((GLib.Object) child.value, entryNode, false, null, "val");
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* build an object Gee.HashMap<string, Yaml.Object> to a Yaml.Node
|
|
||||||
* @param map the gee hashmap to transform
|
|
||||||
* @param name name of map sequence node
|
|
||||||
* @param parent parent node of the map
|
|
||||||
* @return the resulting Yaml.Node
|
|
||||||
*/
|
|
||||||
public static Yaml.Node? objects_mapobjects_to_node (Gee.HashMap map, string name, Yaml.Node? parent = null)
|
|
||||||
{
|
|
||||||
var node = new Yaml.Sequence (parent, name);
|
|
||||||
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(map.get_type ()), "v");
|
|
||||||
var i = 0;
|
|
||||||
foreach (var child in map.entries) {
|
|
||||||
var entryNode = new Yaml.Mapping (node, "_%d".printf (i++));
|
|
||||||
Yaml.Builder.to_node ((GLib.Object) child.key, entryNode, false, null, "key");
|
|
||||||
Yaml.Builder.to_node ((GLib.Object) child.value, entryNode, false, null, "val");
|
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,9 +100,7 @@ namespace Pluie.Yaml
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* serialize an object as a yaml compressed document data
|
*
|
||||||
* @param obj the object to serialize
|
|
||||||
* @param dest path destination if you want to write to a file
|
|
||||||
*/
|
*/
|
||||||
public static uint8[] serialize (GLib.Object? obj, string? dest = null)
|
public static uint8[] serialize (GLib.Object? obj, string? dest = null)
|
||||||
{
|
{
|
||||||
|
@ -139,8 +137,7 @@ namespace Pluie.Yaml
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deserialize yaml compressed document data to a Yaml.Object
|
*
|
||||||
* @param zdata the data to deserialized
|
|
||||||
*/
|
*/
|
||||||
public static Yaml.Root deserialize (uint8[] zdata)
|
public static Yaml.Root deserialize (uint8[] zdata)
|
||||||
{
|
{
|
||||||
|
@ -439,7 +436,7 @@ namespace Pluie.Yaml
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@return a universal unique identifier (type 4)
|
*@return universal infos related to NODE_TYPE
|
||||||
*/
|
*/
|
||||||
public string uuid ()
|
public string uuid ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ if [ $? -eq 0 ]; then
|
||||||
rm $lib.tar.gz
|
rm $lib.tar.gz
|
||||||
tar -czvf $lib.tar.gz doc/
|
tar -czvf $lib.tar.gz doc/
|
||||||
scp $lib.tar.gz pluie@pluie.org:/home/pluie/
|
scp $lib.tar.gz pluie@pluie.org:/home/pluie/
|
||||||
ssh pluie@pluie.org "./updatedoc.sh $lib"
|
ssh pluie@pluie.org "./updatedoc.sh $lib.tar.gz"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user