tmp
This commit is contained in:
parent
93ed254f8c
commit
4ac9c387b4
|
@ -22,10 +22,10 @@
|
||||||
green : !v!uint8 78
|
green : !v!uint8 78
|
||||||
blue : 153
|
blue : 153
|
||||||
!v!Gee.ArrayList type_gee_al :
|
!v!Gee.ArrayList type_gee_al :
|
||||||
- ab_1
|
- 1.2
|
||||||
- ab_2
|
- 2.2
|
||||||
- ab_3
|
- 3.2
|
||||||
- ab_4
|
- 4.2
|
||||||
|
|
||||||
!v!Pluie.Yaml.Example test2 :
|
!v!Pluie.Yaml.Example test2 :
|
||||||
myname : test2object
|
myname : test2object
|
||||||
|
|
|
@ -32,6 +32,57 @@ using GLib;
|
||||||
using Gee;
|
using Gee;
|
||||||
using Pluie;
|
using Pluie;
|
||||||
|
|
||||||
|
public void inspect_type (GLib.Type type, ...)
|
||||||
|
{
|
||||||
|
var l = va_list();
|
||||||
|
while (true) {
|
||||||
|
var obj = l.arg<GLib.Object> ();
|
||||||
|
if (obj == null) {
|
||||||
|
break; // end of the list
|
||||||
|
}
|
||||||
|
print ("%s\n", type.name ());
|
||||||
|
print (" is-obj: %s\n", type.is_object ().to_string ());
|
||||||
|
print (" is-abstr: %s\n", type.is_abstract ().to_string ());
|
||||||
|
print (" is-classed: %s\n", type.is_classed ().to_string ());
|
||||||
|
print (" is-derivable: %s\n", type.is_derivable ().to_string ());
|
||||||
|
print (" is-derived: %s\n", type.is_derived ().to_string ());
|
||||||
|
print (" is-fund: %s\n", type.is_fundamental ().to_string ());
|
||||||
|
print (" is-inst: %s\n", type.is_instantiatable ().to_string ());
|
||||||
|
print (" is-iface: %s\n", type.is_interface ().to_string ());
|
||||||
|
print (" is-enum: %s\n", type.is_enum ().to_string ());
|
||||||
|
print (" is-flags: %s\n", type.is_object ().to_string ());
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// `` Children:``
|
||||||
|
print (" Children:\n");
|
||||||
|
foreach (unowned Type ch in type.children ()) {
|
||||||
|
print (" - %s\n", ch.name ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// `` Interfaces:``
|
||||||
|
// `` - Interface``
|
||||||
|
print (" Interfaces:\n");
|
||||||
|
foreach (unowned Type ch in type.interfaces ()) {
|
||||||
|
if ( ch == typeof(Gee.Traversable)) {
|
||||||
|
print (" --- !!! element type is %s\n", (obj as Gee.Traversable).element_type.name ());
|
||||||
|
if ((obj as Gee.Traversable).element_type == typeof (Gee.Map.Entry)) {
|
||||||
|
print (" --- !!! key type is %s\n", (obj as Gee.Map).key_type.name ());
|
||||||
|
print (" --- !!! value type is %s\n", (obj as Gee.Map).value_type.name ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print (" - %s\n", ch.name ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// `` Parents:``
|
||||||
|
// `` - GObject``
|
||||||
|
print (" Parents:\n");
|
||||||
|
for (Type p = type.parent (); p != 0 ; p = p.parent ()) {
|
||||||
|
print (" - %s\n", p.name ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main (string[] args)
|
int main (string[] args)
|
||||||
{
|
{
|
||||||
Echo.init(false);
|
Echo.init(false);
|
||||||
|
@ -42,14 +93,32 @@ int main (string[] args)
|
||||||
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 = false;
|
||||||
var config = new Yaml.Config (path, true);
|
var config = new Yaml.Config (path, true);
|
||||||
var root = config.root_node ();
|
var root = config.root_node () as Yaml.Root;
|
||||||
root.display_childs ();
|
root.display_childs ();
|
||||||
|
|
||||||
of.action ("Yaml.Builder.from_node", root.first ().name);
|
of.action ("Yaml.Builder.from_node", root.first ().name);
|
||||||
var obj = (Yaml.Example) Yaml.Builder.from_node (root.first ());
|
var obj = (Yaml.Example) Yaml.Builder.from_node (root.first ());
|
||||||
obj.type_object.method_a ();
|
obj.type_object.method_a ();
|
||||||
|
if (obj.type_gee_al != null) {
|
||||||
|
of.keyval("type_gee_al", "(%s)" .printf(obj.type_gee_al.get_type ().name ()));
|
||||||
|
foreach (double v in obj.type_gee_al as Gee.ArrayList<double?>) {
|
||||||
|
of.echo(" - item : %f".printf (v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//~ double dv = 46548970.54324546464;
|
||||||
|
//~ var d = new Gee.ArrayList<double?> ();
|
||||||
|
//~ d.add(dv);
|
||||||
|
|
||||||
|
//~ Gee.ArrayList<double?>* z = d;
|
||||||
|
//~ of.action ("!!!!!!!Yaml.Builder.to_node", obj.get_type ().name ());
|
||||||
|
//~ var m = Yaml.Builder.gee_arraylist_to_node (z, "toto", root);
|
||||||
|
|
||||||
of.action ("Yaml.Builder.to_node", obj.get_type ().name ());
|
of.action ("Yaml.Builder.to_node", obj.get_type ().name ());
|
||||||
|
|
||||||
|
//~ inspect_type (root.tag_directives.get_type (), root.tag_directives);
|
||||||
|
|
||||||
var n = Yaml.Builder.to_node (obj);
|
var n = Yaml.Builder.to_node (obj);
|
||||||
if ((done = n !=null)) {
|
if ((done = n !=null)) {
|
||||||
n.display_childs ();
|
n.display_childs ();
|
||||||
|
|
|
@ -327,7 +327,12 @@ public class Pluie.Yaml.Builder
|
||||||
foreach (var def in obj.get_class ().list_properties ()){
|
foreach (var def in obj.get_class ().list_properties ()){
|
||||||
name = Yaml.Builder.transform_param_name(def.name);
|
name = Yaml.Builder.transform_param_name(def.name);
|
||||||
if (name != null && name != "yaml_name") {
|
if (name != null && name != "yaml_name") {
|
||||||
if (def.value_type.is_a (typeof (Yaml.Object)) || Yaml.Object.register.is_registered_type(obj.get_type (), def.value_type)) {
|
if (def.value_type.is_a (typeof (Gee.ArrayList))) {
|
||||||
|
void *p;
|
||||||
|
obj.get(name, out p);
|
||||||
|
Yaml.Builder.gee_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)) {
|
||||||
var child = obj.populate_to_node(def.value_type, name);
|
var child = obj.populate_to_node(def.value_type, name);
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
child.tag = new Yaml.Tag (Yaml.Object.register.resolve_namespace_type(def.value_type), "v");
|
child.tag = new Yaml.Tag (Yaml.Object.register.resolve_namespace_type(def.value_type), "v");
|
||||||
|
@ -362,4 +367,55 @@ public class Pluie.Yaml.Builder
|
||||||
}
|
}
|
||||||
else return node;
|
else return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static Yaml.Node? gee_arraylist_to_node (Gee.ArrayList* o, string property_name, Yaml.Node parent)
|
||||||
|
{
|
||||||
|
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 (!o->element_type.is_object () && o->element_type.is_fundamental ()) {
|
||||||
|
string data = "";
|
||||||
|
switch (o->element_type) {
|
||||||
|
case Type.INT64 :
|
||||||
|
case Type.INT :
|
||||||
|
data = ((int64) it.get ()).to_string ();
|
||||||
|
break;
|
||||||
|
case Type.CHAR :
|
||||||
|
data = ((char) it.get ()).to_string ();
|
||||||
|
break;
|
||||||
|
case Type.UCHAR :
|
||||||
|
data = ((uchar) it.get ()).to_string ();
|
||||||
|
break;
|
||||||
|
case Type.UINT64 :
|
||||||
|
case Type.UINT :
|
||||||
|
data = ((uint64) it.get ()).to_string ();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
new Yaml.Scalar (node, data);
|
||||||
|
}
|
||||||
|
else if (o->element_type.is_object ()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
public Yaml.ExampleChild type_object { get; set; }
|
public Yaml.ExampleChild type_object { get; set; }
|
||||||
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<string> type_gee_al { get; set; }
|
public Gee.ArrayList<double?> type_gee_al { get; set; }
|
||||||
|
|
||||||
static construct
|
static construct
|
||||||
{
|
{
|
||||||
|
@ -94,10 +94,11 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
this.type_struct = ExampleStruct.from_yaml_node (node);
|
this.type_struct = ExampleStruct.from_yaml_node (node);
|
||||||
}
|
}
|
||||||
else if (type == typeof (Gee.ArrayList)) {
|
else if (type == typeof (Gee.ArrayList)) {
|
||||||
this.type_gee_al = new Gee.ArrayList<string> ();
|
this.type_gee_al = new Gee.ArrayList<double?> ();
|
||||||
if (!node.empty ()) {
|
if (!node.empty ()) {
|
||||||
|
this.type_gee_al.clear ();
|
||||||
foreach (var child in node) {
|
foreach (var child in node) {
|
||||||
this.type_gee_al.add(child.data);
|
this.type_gee_al.add((double) double.parse (child.data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,16 +116,8 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
Yaml.Node? node = base.populate_to_node (type, name);
|
Yaml.Node? node = base.populate_to_node (type, name);
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
if (type == typeof (Yaml.ExampleStruct)) {
|
if (type == typeof (Yaml.ExampleStruct)) {
|
||||||
node = new Yaml.Mapping (null, name);
|
Yaml.ExampleStruct p = this.type_struct;
|
||||||
new Yaml.Mapping.with_scalar (node, "red" , this.type_struct.red.to_string ());
|
node = ExampleStruct.to_yaml_node (ref p, name);
|
||||||
new Yaml.Mapping.with_scalar (node, "green", this.type_struct.green.to_string ());
|
|
||||||
new Yaml.Mapping.with_scalar (node, "blue" , this.type_struct.blue.to_string ());
|
|
||||||
}
|
|
||||||
else if (type == typeof (Gee.ArrayList)) {
|
|
||||||
node = new Yaml.Sequence (null, name);
|
|
||||||
foreach (var data in this.type_gee_al) {
|
|
||||||
new Yaml.Scalar (node, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
|
|
@ -54,20 +54,26 @@ public struct Pluie.Yaml.ExampleStruct
|
||||||
foreach (var child in node) {
|
foreach (var child in node) {
|
||||||
var v = child.val (typeof (uint));
|
var v = child.val (typeof (uint));
|
||||||
switch (child.name) {
|
switch (child.name) {
|
||||||
case "red" :
|
case "red" : s.red = v.get_uint (); break;
|
||||||
s.red = v.get_uint ();
|
case "green" : s.green = v.get_uint (); break;
|
||||||
break;
|
case "blue" : s.blue = v.get_uint (); break;
|
||||||
case "green" :
|
|
||||||
s.green = v.get_uint ();
|
|
||||||
break;
|
|
||||||
case "blue" :
|
|
||||||
s.blue = v.get_uint ();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static Yaml.Node to_yaml_node (ref ExampleStruct self, string name)
|
||||||
|
{
|
||||||
|
var node = new Yaml.Mapping (null, name);
|
||||||
|
new Yaml.Mapping.with_scalar (node, "red" , self.red.to_string ());
|
||||||
|
new Yaml.Mapping.with_scalar (node, "green", self.green.to_string ());
|
||||||
|
new Yaml.Mapping.with_scalar (node, "blue" , self.blue.to_string ());
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user