tmp
This commit is contained in:
parent
bce93d2027
commit
804edebbee
|
@ -73,6 +73,7 @@ sources = [
|
||||||
'src/vala/Pluie/Yaml.ExampleChild.vala',
|
'src/vala/Pluie/Yaml.ExampleChild.vala',
|
||||||
'src/vala/Pluie/Yaml.ExampleStruct.vala',
|
'src/vala/Pluie/Yaml.ExampleStruct.vala',
|
||||||
'src/vala/Pluie/Yaml.Finder.vala',
|
'src/vala/Pluie/Yaml.Finder.vala',
|
||||||
|
'src/vala/Pluie/Yaml.GeeBuilder.vala',
|
||||||
'src/vala/Pluie/Yaml.Loader.vala',
|
'src/vala/Pluie/Yaml.Loader.vala',
|
||||||
'src/vala/Pluie/Yaml.Mapping.vala',
|
'src/vala/Pluie/Yaml.Mapping.vala',
|
||||||
'src/vala/Pluie/Yaml.Node.vala',
|
'src/vala/Pluie/Yaml.Node.vala',
|
||||||
|
|
|
@ -26,6 +26,23 @@
|
||||||
- 2.2
|
- 2.2
|
||||||
- 3.2
|
- 3.2
|
||||||
- 4.2
|
- 4.2
|
||||||
|
!v!Gee.ArrayList type_gee_alobject :
|
||||||
|
- toto : totovalue1
|
||||||
|
tata : tatavalue1
|
||||||
|
titi : 789
|
||||||
|
tutu : true
|
||||||
|
- toto : totovalue2
|
||||||
|
tata : tatavalue2
|
||||||
|
titi : 456
|
||||||
|
tutu : false
|
||||||
|
- toto : totovalue3
|
||||||
|
tata : tatavalue3
|
||||||
|
titi : 123
|
||||||
|
tutu : 1
|
||||||
|
- toto : totovalue4
|
||||||
|
tata : tatavalue4
|
||||||
|
titi : 44
|
||||||
|
tutu : 0
|
||||||
|
|
||||||
!v!Pluie.Yaml.Example test2 :
|
!v!Pluie.Yaml.Example test2 :
|
||||||
myname : test2object
|
myname : test2object
|
||||||
|
|
|
@ -103,7 +103,7 @@ int main (string[] args)
|
||||||
var done = false;
|
var done = false;
|
||||||
|
|
||||||
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||||
Pluie.Yaml.DEBUG = false;
|
Pluie.Yaml.DEBUG = true;
|
||||||
var config = new Yaml.Config (path, true);
|
var config = new Yaml.Config (path, true);
|
||||||
var root = config.root_node () as Yaml.Root;
|
var root = config.root_node () as Yaml.Root;
|
||||||
root.first ().display_childs ();
|
root.first ().display_childs ();
|
||||||
|
@ -129,42 +129,42 @@ int main (string[] args)
|
||||||
//~ list.add_all_array (data);
|
//~ list.add_all_array (data);
|
||||||
//~ Gee.ArrayList* p = list;
|
//~ Gee.ArrayList* p = list;
|
||||||
//~ var mynode = new Yaml.Root ();
|
//~ var mynode = new Yaml.Root ();
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<double?>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<double?>", mynode);
|
||||||
|
|
||||||
|
|
||||||
//~ string[] data2 = { "mastring1", "mastring2", "mastring3", "mastring4", "mastring5" };
|
//~ string[] data2 = { "mastring1", "mastring2", "mastring3", "mastring4", "mastring5" };
|
||||||
//~ var list2 = new Gee.ArrayList<string> ();
|
//~ var list2 = new Gee.ArrayList<string> ();
|
||||||
//~ list2.add_all_array (data2);
|
//~ list2.add_all_array (data2);
|
||||||
//~ p = list2;
|
//~ p = list2;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<string>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<string>", mynode);
|
||||||
|
|
||||||
|
|
||||||
//~ int[] data3 = { 123, 456, 9875, 64205, 9924563 };
|
//~ int[] data3 = { 123, 456, 9875, 64205, 9924563 };
|
||||||
//~ var list3 = new Gee.ArrayList<int> ();
|
//~ var list3 = new Gee.ArrayList<int> ();
|
||||||
//~ list3.add_all_array (data3);
|
//~ list3.add_all_array (data3);
|
||||||
//~ p = list3;
|
//~ p = list3;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<int>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<int>", mynode);
|
||||||
|
|
||||||
|
|
||||||
//~ int64?[] data4 = { 123, 456, -9875, 64205, -549924563 };
|
//~ int64?[] data4 = { 123, 456, -9875, 64205, -549924563 };
|
||||||
//~ var list4 = new Gee.ArrayList<int64?> ();
|
//~ var list4 = new Gee.ArrayList<int64?> ();
|
||||||
//~ list4.add_all_array (data4);
|
//~ list4.add_all_array (data4);
|
||||||
//~ p = list4;
|
//~ p = list4;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<int64?>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<int64?>", mynode);
|
||||||
|
|
||||||
|
|
||||||
//~ long?[] data5 = { 123, 456, -9875, 64205, -549924563 };
|
//~ long?[] data5 = { 123, 456, -9875, 64205, -549924563 };
|
||||||
//~ var list5 = new Gee.ArrayList<long?> ();
|
//~ var list5 = new Gee.ArrayList<long?> ();
|
||||||
//~ list5.add_all_array (data5);
|
//~ list5.add_all_array (data5);
|
||||||
//~ p = list5;
|
//~ p = list5;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<long?>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<long?>", mynode);
|
||||||
|
|
||||||
|
|
||||||
//~ uint[] data6 = { 123, 456, 19875, 64205, 1549924563 };
|
//~ uint[] data6 = { 123, 456, 19875, 64205, 1549924563 };
|
||||||
//~ var list6 = new Gee.ArrayList<uint> ();
|
//~ var list6 = new Gee.ArrayList<uint> ();
|
||||||
//~ list6.add_all_array (data6);
|
//~ list6.add_all_array (data6);
|
||||||
//~ p = list6;
|
//~ p = list6;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<uint>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<uint>", mynode);
|
||||||
|
|
||||||
|
|
||||||
//~ uint8[] data7 = { 97, 99, 122, 72 };
|
//~ uint8[] data7 = { 97, 99, 122, 72 };
|
||||||
|
@ -174,7 +174,7 @@ int main (string[] args)
|
||||||
//~ of.echo(" - item7 : %u".printf (u));
|
//~ of.echo(" - item7 : %u".printf (u));
|
||||||
//~ }
|
//~ }
|
||||||
//~ p = list7;
|
//~ p = list7;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<uint8>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<uint8>", mynode);
|
||||||
|
|
||||||
|
|
||||||
//~ uchar[] data8 = { 'a', 'c', 'z', 'H' };
|
//~ uchar[] data8 = { 'a', 'c', 'z', 'H' };
|
||||||
|
@ -184,7 +184,7 @@ int main (string[] args)
|
||||||
//~ of.echo(" - item8 : %c".printf (u));
|
//~ of.echo(" - item8 : %c".printf (u));
|
||||||
//~ }
|
//~ }
|
||||||
//~ p = list8;
|
//~ p = list8;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<uchar>", mynode, true);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<uchar>", mynode, true);
|
||||||
|
|
||||||
|
|
||||||
//~ unichar[] data9 = { '水', 'は', '方', 'の', 'é', 'à', 'ï', 'Ô' };
|
//~ unichar[] data9 = { '水', 'は', '方', 'の', 'é', 'à', 'ï', 'Ô' };
|
||||||
|
@ -194,7 +194,7 @@ int main (string[] args)
|
||||||
//~ of.echo(" - item9 : %s (%lu)".printf (u.to_string (), u));
|
//~ of.echo(" - item9 : %s (%lu)".printf (u.to_string (), u));
|
||||||
//~ }
|
//~ }
|
||||||
//~ p = list9;
|
//~ p = list9;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<unichar?>", mynode, true);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<unichar?>", mynode, true);
|
||||||
|
|
||||||
|
|
||||||
//~ uint64?[] data10 = { 4521, 8954354, 4535213213 };
|
//~ uint64?[] data10 = { 4521, 8954354, 4535213213 };
|
||||||
|
@ -204,7 +204,7 @@ int main (string[] args)
|
||||||
//~ of.echo(" - item10 : %s".printf (u.to_string ()));
|
//~ of.echo(" - item10 : %s".printf (u.to_string ()));
|
||||||
//~ }
|
//~ }
|
||||||
//~ p = list10;
|
//~ p = list10;
|
||||||
//~ Yaml.Builder.gee_arraylist_to_node (p, "Gee.ArrayList<uint64?>", mynode);
|
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<uint64?>", mynode);
|
||||||
|
|
||||||
//~ mynode.display_childs ();
|
//~ mynode.display_childs ();
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,7 @@ public class Pluie.Yaml.Builder
|
||||||
if (type.is_object ()) {
|
if (type.is_object ()) {
|
||||||
obj = (Yaml.Object) GLib.Object.new (type);
|
obj = (Yaml.Object) GLib.Object.new (type);
|
||||||
obj.set ("yaml_name", node.name);
|
obj.set ("yaml_name", node.name);
|
||||||
|
obj.yaml_construct ();
|
||||||
if (node!= null && !node.empty ()) {
|
if (node!= null && !node.empty ()) {
|
||||||
GLib.ParamSpec? def = null;
|
GLib.ParamSpec? def = null;
|
||||||
Yaml.Node? scalar = null;
|
Yaml.Node? scalar = null;
|
||||||
|
@ -170,11 +171,12 @@ public class Pluie.Yaml.Builder
|
||||||
*/
|
*/
|
||||||
public static void set_from_collection (ref Yaml.Object obj, GLib.Type parentType, Yaml.Node node, GLib.Type type)
|
public static void set_from_collection (ref Yaml.Object obj, GLib.Type parentType, Yaml.Node node, GLib.Type type)
|
||||||
{
|
{
|
||||||
|
Yaml.dbg (" > set_from_collection %s (%s)".printf (node.name, type.name ()));
|
||||||
if (type.is_a (typeof (Yaml.Object))) {
|
if (type.is_a (typeof (Yaml.Object))) {
|
||||||
obj.set (node.name, Yaml.Builder.from_node(node, type));
|
obj.set (node.name, Yaml.Builder.from_node(node, type));
|
||||||
}
|
}
|
||||||
else if (type.is_a (typeof (Gee.ArrayList))) {
|
else if (type.is_a (typeof (Gee.ArrayList))) {
|
||||||
Yaml.Builder.gee_arraylist_from_node(obj, node);
|
Yaml.GeeBuilder.arraylist_from_node(ref obj, node, type);
|
||||||
}
|
}
|
||||||
else if (Yaml.Object.register.is_registered_type(parentType, type)) {
|
else if (Yaml.Object.register.is_registered_type(parentType, type)) {
|
||||||
Yaml.dbg ("%s is a registered type".printf (type.name ()));
|
Yaml.dbg ("%s is a registered type".printf (type.name ()));
|
||||||
|
@ -333,7 +335,7 @@ public class Pluie.Yaml.Builder
|
||||||
if (def.value_type.is_a (typeof (Gee.ArrayList))) {
|
if (def.value_type.is_a (typeof (Gee.ArrayList))) {
|
||||||
void *p;
|
void *p;
|
||||||
obj.get(name, out p);
|
obj.get(name, out p);
|
||||||
Yaml.Builder.gee_arraylist_to_node(p, name, node);
|
Yaml.GeeBuilder.arraylist_to_node(p, name, node);
|
||||||
}
|
}
|
||||||
else if (def.value_type.is_a (typeof (Yaml.Object)) || Yaml.Object.register.is_registered_type(obj.get_type (), def.value_type)) {
|
else if (def.value_type.is_a (typeof (Yaml.Object)) || Yaml.Object.register.is_registered_type(obj.get_type (), def.value_type)) {
|
||||||
var child = obj.populate_to_node(def.value_type, name);
|
var child = obj.populate_to_node(def.value_type, name);
|
||||||
|
@ -370,167 +372,4 @@ public class Pluie.Yaml.Builder
|
||||||
}
|
}
|
||||||
else return node;
|
else return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static void gee_arraylist_from_node (Yaml.Object obj, Yaml.Node node)
|
|
||||||
{
|
|
||||||
Gee.ArrayList* o;
|
|
||||||
obj.get(node.name, out o);
|
|
||||||
var type = o->element_type;
|
|
||||||
if (!type.is_object () && type.is_fundamental ()) {
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case Type.STRING :
|
|
||||||
var l = new Gee.ArrayList<string> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.CHAR :
|
|
||||||
var l = new Gee.ArrayList<int8> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.UCHAR :
|
|
||||||
var l = new Gee.ArrayList<uchar> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.BOOLEAN :
|
|
||||||
var l = new Gee.ArrayList<bool> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.INT :
|
|
||||||
var l = new Gee.ArrayList<int> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.UINT :
|
|
||||||
var l = new Gee.ArrayList<uint> ();
|
|
||||||
o = &l;
|
|
||||||
o->add((uint)long.parse(child.data));
|
|
||||||
break;
|
|
||||||
case Type.LONG :
|
|
||||||
case Type.INT64 :
|
|
||||||
var l = new Gee.ArrayList<long> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.ULONG :
|
|
||||||
case Type.UINT64 :
|
|
||||||
var l = new Gee.ArrayList<ulong> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.FLOAT :
|
|
||||||
var l = new Gee.ArrayList<float?> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
case Type.DOUBLE :
|
|
||||||
var l = new Gee.ArrayList<double?> ();
|
|
||||||
o = &l;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
foreach (var child in node) {
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case Type.STRING :
|
|
||||||
o->add(child.data);
|
|
||||||
break;
|
|
||||||
case Type.CHAR :
|
|
||||||
o->add((int8)child.data.data[0]);
|
|
||||||
break;
|
|
||||||
case Type.UCHAR :
|
|
||||||
o->add((uint8)child.data.data[0]);
|
|
||||||
break;
|
|
||||||
case Type.BOOLEAN :
|
|
||||||
o->add(child.data == "1" || child.data.down () == "true");
|
|
||||||
break;
|
|
||||||
case Type.INT :
|
|
||||||
o->add(int.parse(child.data));
|
|
||||||
break;
|
|
||||||
case Type.UINT :
|
|
||||||
o->add((uint)long.parse(child.data));
|
|
||||||
break;
|
|
||||||
case Type.LONG :
|
|
||||||
case Type.INT64 :
|
|
||||||
o->add((long)int64.parse(data));
|
|
||||||
break;
|
|
||||||
case Type.ULONG :
|
|
||||||
case Type.UINT64 :
|
|
||||||
o->add((ulong)uint64.parse(data));
|
|
||||||
break;
|
|
||||||
case Type.FLOAT :
|
|
||||||
o->add((float)double.parse(data));
|
|
||||||
break;
|
|
||||||
case Type.DOUBLE :
|
|
||||||
o->add(double.parse(child.data));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type.is_object ()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static Yaml.Node? gee_arraylist_to_node (Gee.ArrayList* o, string property_name, Yaml.Node parent, bool is_char = false)
|
|
||||||
{
|
|
||||||
Yaml.dbg_action ("prop %s (type %s) has element type :".printf (property_name, o->get_type ().name ()), o->element_type.name ());
|
|
||||||
var type = o->element_type;
|
|
||||||
var node = new Yaml.Sequence (parent, property_name);
|
|
||||||
var it = o->iterator();
|
|
||||||
while (it.next ()) {
|
|
||||||
if (!type.is_object () && type.is_fundamental ()) {
|
|
||||||
string data = "";
|
|
||||||
if (is_char && (type == typeof (unichar) || type == typeof (uchar))) {
|
|
||||||
void* d = (void*) it.get ();
|
|
||||||
data = ((unichar) d).to_string();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
switch (type) {
|
|
||||||
case Type.LONG :
|
|
||||||
case Type.INT64 :
|
|
||||||
int64* d = (int64*) it.get ();
|
|
||||||
data = d.to_string ();
|
|
||||||
break;
|
|
||||||
case Type.INT :
|
|
||||||
data = ((int64) it.get ()).to_string ();
|
|
||||||
break;
|
|
||||||
case Type.CHAR :
|
|
||||||
data = ((char) it.get ()).to_string ();
|
|
||||||
break;
|
|
||||||
case Type.UCHAR :
|
|
||||||
data = "%u".printf (((uint) it.get ()));
|
|
||||||
break;
|
|
||||||
case Type.ULONG :
|
|
||||||
case Type.UINT64 :
|
|
||||||
uint64* d = (uint64*) it.get ();
|
|
||||||
data = d.to_string ();
|
|
||||||
break;
|
|
||||||
case Type.UINT :
|
|
||||||
data = "%u".printf ((uint) it.get ());
|
|
||||||
break;
|
|
||||||
case Type.BOOLEAN :
|
|
||||||
data = ((bool) it.get ()).to_string ();
|
|
||||||
break;
|
|
||||||
case Type.FLOAT :
|
|
||||||
float* f = (float*) it.get ();
|
|
||||||
data = f.to_string ();
|
|
||||||
break;
|
|
||||||
case Type.DOUBLE :
|
|
||||||
double* d = (double*) it.get ();
|
|
||||||
data = d.to_string ();
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
data = (string) it.get ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var f = new Yaml.Scalar (node, data);
|
|
||||||
}
|
|
||||||
else if (type.is_object ()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
public Yaml.NODE_TYPE type_enum { get; set; }
|
public Yaml.NODE_TYPE type_enum { get; set; }
|
||||||
public Yaml.ExampleStruct type_struct { get; set; }
|
public Yaml.ExampleStruct 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<Yaml.ExampleChild> type_gee_alobject { get; set; }
|
||||||
|
|
||||||
static construct
|
static construct
|
||||||
{
|
{
|
||||||
|
@ -75,13 +76,24 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected override void yaml_construct ()
|
||||||
|
{
|
||||||
|
this.type_gee_al = new Gee.ArrayList<double?> ();
|
||||||
|
this.type_gee_alobject = new Gee.ArrayList<Yaml.ExampleChild> ();
|
||||||
|
// base.yaml_init ();
|
||||||
|
Dbg.msg ("Yaml.Object %s (%s) instantiated".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected override void yaml_init ()
|
protected override void yaml_init ()
|
||||||
{
|
{
|
||||||
// base.yaml_init ();
|
// base.yaml_init ();
|
||||||
Dbg.msg ("Yaml.Object %s (%s) instantiated".printf (this.myname, this.get_type().name ()), Log.LINE, Log.FILE);
|
Dbg.msg ("Yaml.Object %s (%s) initialized".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,22 +101,8 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
*/
|
*/
|
||||||
public override void populate_from_node(GLib.Type type, Yaml.Node node)
|
public override void populate_from_node(GLib.Type type, Yaml.Node node)
|
||||||
{
|
{
|
||||||
try {
|
if (type == typeof (Yaml.ExampleStruct)) {
|
||||||
if (type == typeof (Yaml.ExampleStruct)) {
|
this.type_struct = ExampleStruct.from_yaml_node (node);
|
||||||
this.type_struct = ExampleStruct.from_yaml_node (node);
|
|
||||||
}
|
|
||||||
else if (type == typeof (Gee.ArrayList)) {
|
|
||||||
this.type_gee_al = new Gee.ArrayList<double?> ();
|
|
||||||
if (!node.empty ()) {
|
|
||||||
this.type_gee_al.clear ();
|
|
||||||
foreach (var child in node) {
|
|
||||||
this.type_gee_al.add((double) double.parse (child.data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (GLib.Error e) {
|
|
||||||
Dbg.error(e.message, Log.METHOD, Log.LINE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
204
src/vala/Pluie/Yaml.GeeBuilder.vala
Normal file
204
src/vala/Pluie/Yaml.GeeBuilder.vala
Normal file
|
@ -0,0 +1,204 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @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 Gee;
|
||||||
|
using Pluie;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a Yaml.Builder class helping to build vala Yaml.Object from Yaml.Node
|
||||||
|
*/
|
||||||
|
public class Pluie.Yaml.GeeBuilder
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static void arraylist_from_node (ref Yaml.Object obj, Yaml.Node node, Type type)
|
||||||
|
{
|
||||||
|
Gee.ArrayList* p;
|
||||||
|
obj.get (node.name, out p);
|
||||||
|
GLib.Type? elementType = null;
|
||||||
|
if (p != null && (elementType = p->element_type) != null) {
|
||||||
|
Yaml.dbg (" arraylist_from_node %s (%s<%s>)".printf (node.name, type.name (), elementType.name ()));
|
||||||
|
if (!elementType.is_object () && elementType.is_fundamental ()) {
|
||||||
|
switch (elementType)
|
||||||
|
{
|
||||||
|
case Type.STRING :
|
||||||
|
var l = new Gee.ArrayList<string> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add(child.data);
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.CHAR :
|
||||||
|
var l = new Gee.ArrayList<int8> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add((int8)child.data.data[0]);
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.UCHAR :
|
||||||
|
var l = new Gee.ArrayList<uchar> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add((uint8)child.data.data[0]);
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.BOOLEAN :
|
||||||
|
var l = new Gee.ArrayList<bool> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add(child.data == "1" || child.data.down () == "true");
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.INT :
|
||||||
|
var l = new Gee.ArrayList<int> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add(int.parse(child.data));
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.UINT :
|
||||||
|
var l = new Gee.ArrayList<uint> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add((uint)long.parse(child.data));
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.LONG :
|
||||||
|
case Type.INT64 :
|
||||||
|
var l = new Gee.ArrayList<long> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add((long)int64.parse(child.data));
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.ULONG :
|
||||||
|
case Type.UINT64 :
|
||||||
|
var l = new Gee.ArrayList<ulong> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add((ulong)uint64.parse(child.data));
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.FLOAT :
|
||||||
|
var l = new Gee.ArrayList<float?> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add((float)double.parse(child.data));
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
case Type.DOUBLE :
|
||||||
|
var l = new Gee.ArrayList<double?> ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
l.add(double.parse(child.data));
|
||||||
|
}
|
||||||
|
obj.set (node.name, l);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (elementType.is_object ()) {
|
||||||
|
var pg = p;
|
||||||
|
foreach (var child in node) {
|
||||||
|
pg.add(Yaml.Builder.from_node (child, elementType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
of.warn ("can't retriew Generic Type. did you forget to instanciate the list in yaml_construct () method ?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static Yaml.Node? arraylist_to_node (Gee.ArrayList* o, string property_name, Yaml.Node parent, bool is_char = false)
|
||||||
|
{
|
||||||
|
Yaml.dbg_action ("prop %s (type %s) has element type :".printf (property_name, o->get_type ().name ()), o->element_type.name ());
|
||||||
|
var type = o->element_type;
|
||||||
|
var node = new Yaml.Sequence (parent, property_name);
|
||||||
|
var it = o->iterator();
|
||||||
|
while (it.next ()) {
|
||||||
|
if (!type.is_object () && type.is_fundamental ()) {
|
||||||
|
string data = "";
|
||||||
|
if (is_char && (type == typeof (unichar) || type == typeof (uchar))) {
|
||||||
|
void* d = (void*) it.get ();
|
||||||
|
data = ((unichar) d).to_string();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (type) {
|
||||||
|
case Type.LONG :
|
||||||
|
case Type.INT64 :
|
||||||
|
int64* d = (int64*) it.get ();
|
||||||
|
data = d.to_string ();
|
||||||
|
break;
|
||||||
|
case Type.INT :
|
||||||
|
data = ((int64) it.get ()).to_string ();
|
||||||
|
break;
|
||||||
|
case Type.CHAR :
|
||||||
|
data = ((char) it.get ()).to_string ();
|
||||||
|
break;
|
||||||
|
case Type.UCHAR :
|
||||||
|
data = "%u".printf (((uint) it.get ()));
|
||||||
|
break;
|
||||||
|
case Type.ULONG :
|
||||||
|
case Type.UINT64 :
|
||||||
|
uint64* d = (uint64*) it.get ();
|
||||||
|
data = d.to_string ();
|
||||||
|
break;
|
||||||
|
case Type.UINT :
|
||||||
|
data = "%u".printf ((uint) it.get ());
|
||||||
|
break;
|
||||||
|
case Type.BOOLEAN :
|
||||||
|
data = ((bool) it.get ()).to_string ();
|
||||||
|
break;
|
||||||
|
case Type.FLOAT :
|
||||||
|
float* f = (float*) it.get ();
|
||||||
|
data = f.to_string ();
|
||||||
|
break;
|
||||||
|
case Type.DOUBLE :
|
||||||
|
double* d = (double*) it.get ();
|
||||||
|
data = d.to_string ();
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
data = (string) it.get ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var f = new Yaml.Scalar (node, data);
|
||||||
|
}
|
||||||
|
else if (type.is_object ()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,12 +60,25 @@ public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
register.add_namespace("Pluie", "Pluie.Yaml", "Gee");
|
register.add_namespace("Pluie", "Pluie.Yaml", "Gee");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object ()
|
||||||
|
{
|
||||||
|
this.yaml_construct ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public virtual void yaml_construct ()
|
||||||
|
{
|
||||||
|
Dbg.msg ("Yaml.Object (%s) construct".printf (this.get_type().name ()), Log.LINE, Log.FILE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public virtual void yaml_init ()
|
public virtual void yaml_init ()
|
||||||
{
|
{
|
||||||
Dbg.msg ("Yaml.Object (%s) instantiated".printf (this.get_type().name ()), Log.LINE, Log.FILE);
|
Dbg.msg ("Yaml.Object (%s) init".printf (this.get_type().name ()), Log.LINE, Log.FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user