diff --git a/.berel.yml b/.berel.yml index 4576c70..53a0c87 100644 --- a/.berel.yml +++ b/.berel.yml @@ -27,7 +27,6 @@ - meson : file : - meson.build - startline : 1 sepline : motif : "# " repeat : 40 @@ -43,7 +42,6 @@ - .c file : - install.vala.in - startline : 1 sepline : motif : " *" repeat : 40 @@ -71,6 +69,6 @@ more details. You should have received a copy of the GNU General Public License - along with ^software.name^. If not, see . + along with ^software.name^. If not, see ^license.address^. ^sepline^ diff --git a/build.sh b/build.sh index ccbf9a3..2c7a740 100755 --- a/build.sh +++ b/build.sh @@ -29,14 +29,17 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^# # -------------------------------------------------------- -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -lib="pluie-yaml-0.5" - c1="\033[1;38;5;215m" - c2="\033[1;38;5;97m" -cok="\033[1;38;5;37m" -cko="\033[1;38;5;204m" -off="\033[m" -resume= + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + lib="pluie-yaml-0.5" +samples=" src/vala/Pluie/Samples.YamlObject.vala \ +src/vala/Pluie/Samples.YamlChild.vala \ +src/vala/Pluie/Samples.YamlStruct.vala " + c1="\033[1;38;5;215m" + c2="\033[1;38;5;97m" + cok="\033[1;38;5;37m" + cko="\033[1;38;5;204m" + off="\033[m" + resume= # -------------------------------------------------------- function build.title() { @@ -94,9 +97,9 @@ function build.sample() local f="$(basename $1)" local fx="${f:0:-5}" local state="FAILED" - local cmd="valac -v --pkg gee-0.8 --pkg gio-2.0 --pkg pluie-echo-0.2 --pkg $lib $1 -o ./bin/$fx" + local cmd="valac -v -X -Wno-discarded-qualifiers -X -Wno-deprecated-declarations --pkg gee-0.8 --pkg gio-2.0 --pkg pluie-echo-0.2 --pkg $lib $samples $1 -o ./bin/$fx" build.title "$f SAMPLE BUILD" - echo -e "\n$cmd" + echo $cmd local done=$? resume="$resume$done$f " diff --git a/meson.build b/meson.build index 5388bc2..733ae99 100644 --- a/meson.build +++ b/meson.build @@ -26,26 +26,15 @@ # along with pluie-yaml. If not, see . # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^# -project('pluie-yaml', 'vala', 'c', version:'0.5') + +project('pluie-yaml', ['vala', 'c'], version:'0.5') cc = meson.get_compiler('c') -dep_glib = dependency('glib-2.0') -dep_gobject = dependency('gobject-2.0') -dep_gmodule = dependency('gmodule-2.0') -dep_gio = dependency('gio-2.0') -dep_gee = dependency('gee-0.8') -dep_echo = dependency('pluie-echo-0.2') -dep_m = cc.find_library('m', required : false) -dep_yaml = cc.find_library('yaml', required : true) - -#~ add_global_link_arguments('-lyaml', language : 'c') - version = meson.project_version() bindir = join_paths(get_option('prefix'), get_option('bindir')) datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie/yaml') libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig') incdir = join_paths(get_option('prefix'), get_option('includedir'), 'pluie') - conf = configuration_data() conf.set('VERSION' , version) conf.set('INSTALL_PATH', bindir) @@ -57,52 +46,34 @@ configure_file( configuration: conf ) -sources = [ - 'build/install.vala', - 'src/vala/Pluie/Io.Reader.vala', - 'src/vala/Pluie/Io.InputChunkStream.vala', - 'src/vala/Pluie/Io.StreamLineMark.vala', - 'src/vala/Pluie/Io.Writter.vala', - 'src/vala/Pluie/Yaml.global.vala', - 'src/vala/Pluie/Yaml.AbstractChild.vala', - 'src/vala/Pluie/Yaml.AbstractNode.vala', - 'src/vala/Pluie/Yaml.Builder.vala', - 'src/vala/Pluie/Yaml.Collection.vala', - 'src/vala/Pluie/Yaml.Config.vala', - 'src/vala/Pluie/Yaml.Dumper.vala', - 'src/vala/Pluie/Yaml.Event.vala', - 'src/vala/Pluie/Yaml.Example.vala', - 'src/vala/Pluie/Yaml.ExampleChild.vala', - 'src/vala/Pluie/Yaml.ExampleStruct.vala', - 'src/vala/Pluie/Yaml.Finder.vala', - 'src/vala/Pluie/Yaml.GeeBuilder.vala', - 'src/vala/Pluie/Yaml.Loader.vala', - 'src/vala/Pluie/Yaml.Mapping.vala', - 'src/vala/Pluie/Yaml.Node.vala', - 'src/vala/Pluie/Yaml.Object.vala', - 'src/vala/Pluie/Yaml.Processor.vala', - 'src/vala/Pluie/Yaml.Register.vala', - 'src/vala/Pluie/Yaml.Root.vala', - 'src/vala/Pluie/Yaml.Scalar.vala', - 'src/vala/Pluie/Yaml.Scanner.vala', - 'src/vala/Pluie/Yaml.Sequence.vala', - 'src/vala/Pluie/Yaml.Tag.vala', - 'src/c/yaml.c' -] - -install_data('resources/main.yml', install_dir : datadir) -install_data('resources/tag.yml', install_dir : datadir) -install_data('resources/test.yml', install_dir : datadir) -install_data('resources/test.json', install_dir : datadir) +install_data([ + 'resources/main.yml', + 'resources/tag.yml', + 'resources/test.yml', + 'resources/test.json' + ], + install_dir : datadir +) install_data('resources/config/db.yml', install_dir : join_paths(datadir, 'config')) install_data('resources/config/subdir/test.yml', install_dir : join_paths(datadir, 'config/subdir')) +subdir('src') + libpluie_yaml = library( 'pluie-yaml-' + version, - sources, + src_files + [ 'build/install.vala' ], vala_header : 'pluie_yaml.h', vala_vapi : 'pluie-yaml-' +version+'.vapi', - dependencies : [dep_glib, dep_gobject, dep_gmodule, dep_gio, dep_gee, dep_echo, dep_m, dep_yaml], + dependencies : [ + dependency('glib-2.0'), + dependency('gobject-2.0'), + dependency('gmodule-2.0'), + dependency('gio-2.0'), + dependency('gee-0.8'), + dependency('pluie-echo-0.2'), + cc.find_library('m', required : false), + cc.find_library('yaml', required : true) + ], install : true, version : version, install_dir : [get_option('libdir'), incdir, true] diff --git a/resources/tag.yml b/resources/tag.yml index 93461fb..77de1ca 100644 --- a/resources/tag.yml +++ b/resources/tag.yml @@ -1,7 +1,7 @@ %YAML 1.2 %TAG !v! tag:pluie.org,2018:vala/ --- -!v!Pluie.Yaml.Example test1 : +!v!Pluie.Samples.YamlObject test1 : myname : test1object type_int : !v!int 3306 type_bool : !v!bool false @@ -12,12 +12,12 @@ type_float : !v!float 42.36 type_double : !v!double 95542123.4579512128 type_enum : !v!Pluie.Yaml.NODE_TYPE scalar # or int - !v!Pluie.Yaml.ExampleChild type_object : + !v!Pluie.Samples.YamlChild type_object : toto : totovalue1 tata : tatavalue1 titi : 123 tutu : 1 - !v!Pluie.Yaml.ExampleStruct type_struct : + !v!Pluie.Samples.YamlStruct type_struct : red : !v!uint8 214 green : !v!uint8 78 blue : 153 diff --git a/samples/yaml-dump.vala b/samples/yaml-dump.vala index 73d001d..48a9906 100644 --- a/samples/yaml-dump.vala +++ b/samples/yaml-dump.vala @@ -46,21 +46,13 @@ int main (string[] args) if ((done = root != null)) { root.display_childs (); - of.action("Yaml.Node", "to_yaml_string"); - string yaml = root.to_yaml_string (); string genpath = "./tag-generated.yml"; - try { - var writter = new Io.Writter (genpath, true); - long written = 0; - writter.write (yaml.data, out written); - of.echo ("write %ld bytes in `%s`".printf ((long) written, genpath)); - Yaml.Dumper.show_yaml_string (root, true, true, true); - } - catch (Error e) { - stderr.printf ("%s\n", e.message); - return 1; - } + var writter = new Io.Writter (genpath, true); + long written = 0; + writter.write (root.to_yaml_string ().data, out written); + of.echo ("write %ld bytes in `%s`".printf ((long) written, genpath)); + Yaml.Dumper.show_yaml_string (root, true, true, true); } diff --git a/samples/yaml-serialize.vala b/samples/yaml-serialize.vala index 74a0e51..86c872c 100644 --- a/samples/yaml-serialize.vala +++ b/samples/yaml-serialize.vala @@ -32,7 +32,7 @@ using GLib; using Gee; using Pluie; -public void test_object(Yaml.Example obj) +public void test_object(Samples.YamlObject obj) { of.action ("Test Object", obj.yaml_name); obj.type_object.method_a (); @@ -86,8 +86,7 @@ int main (string[] args) root.display_childs (); of.action ("Yaml build first child", root.first ().name); - Yaml.Example obj = (Yaml.Example) Yaml.Builder.from_node (root.first ()); - obj = (Yaml.Example) Yaml.Builder.from_node (root.first ()); + var obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ()); test_object (obj); of.action ("Serialize", obj.yaml_name); @@ -100,7 +99,7 @@ int main (string[] args) root = Yaml.deserialize (zdata); root.display_childs (); of.action ("Yaml build first child", obj.yaml_name); - obj = (Yaml.Example) Yaml.Builder.from_node (root.first ()); + obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ()); test_object (obj); } diff --git a/samples/yaml-tag.vala b/samples/yaml-tag.vala index f37ff0a..533bf32 100644 --- a/samples/yaml-tag.vala +++ b/samples/yaml-tag.vala @@ -60,11 +60,12 @@ int main (string[] args) node = node.next_sibling (); } } + // hard code - Yaml.Example? o = null; + Samples.YamlObject? o = null; foreach (var entry in list.entries) { - if ((o = (Yaml.Example) entry.value)!=null) { - of.action ("Getting Hard coded values for Yaml.Object %s".printf (of.c (ECHO.MICROTIME).s (o.get_type().name ())), entry.key); + if ((o = (Samples.YamlObject) entry.value)!=null) { + of.action ("Getting Hard coded values for Samples.YamlObject %s".printf (of.c (ECHO.MICROTIME).s (o.get_type().name ())), entry.key); of.keyval("yaml_name" , "%s" .printf(o.yaml_name)); of.keyval("type_int" , "%d" .printf(o.type_int)); of.keyval("type_bool" , "%s" .printf(o.type_bool.to_string ())); diff --git a/samples/yaml-test.vala b/samples/yaml-test.vala index 0bf5a75..f77963f 100644 --- a/samples/yaml-test.vala +++ b/samples/yaml-test.vala @@ -46,7 +46,7 @@ int main (string[] args) root.first ().display_childs (); of.action ("with signal Yaml.Builder.from_node", root.first ().name); - Yaml.Example obj = (Yaml.Example) Yaml.Builder.from_node (root.first ()); + Samples.YamlObject obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ()); obj.type_object.method_a (); if (obj.type_gee_al != null) { of.keyval("type_gee_al", "(%s<%s>)" .printf(obj.type_gee_al.get_type ().name (), obj.type_gee_al.element_type.name ())); diff --git a/samples/yaml-tonode.vala b/samples/yaml-tonode.vala index 77a6da6..6359323 100644 --- a/samples/yaml-tonode.vala +++ b/samples/yaml-tonode.vala @@ -103,13 +103,13 @@ int main (string[] args) var done = false; of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); - Pluie.Yaml.DEBUG = true; + Pluie.Yaml.DEBUG = false; var config = new Yaml.Config (path, true); - var root = config.root_node () as Yaml.Root; + var root = config.root_node (); root.first ().display_childs (); of.action ("Yaml.Builder.from_node", root.first ().name); - var obj = (Yaml.Example) Yaml.Builder.from_node (root.first ()); + Samples.YamlObject obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ()); 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 ())); @@ -123,91 +123,6 @@ int main (string[] args) n.display_childs (); } - -//~ double?[] data = { 46548970.54324546464, 2.2, 2.1, 2.4, 5.7 }; -//~ var list = new Gee.ArrayList (); -//~ list.add_all_array (data); -//~ Gee.ArrayList* p = list; -//~ var mynode = new Yaml.Root (); -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - - -//~ string[] data2 = { "mastring1", "mastring2", "mastring3", "mastring4", "mastring5" }; -//~ var list2 = new Gee.ArrayList (); -//~ list2.add_all_array (data2); -//~ p = list2; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - - -//~ int[] data3 = { 123, 456, 9875, 64205, 9924563 }; -//~ var list3 = new Gee.ArrayList (); -//~ list3.add_all_array (data3); -//~ p = list3; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - - -//~ int64?[] data4 = { 123, 456, -9875, 64205, -549924563 }; -//~ var list4 = new Gee.ArrayList (); -//~ list4.add_all_array (data4); -//~ p = list4; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - - -//~ long?[] data5 = { 123, 456, -9875, 64205, -549924563 }; -//~ var list5 = new Gee.ArrayList (); -//~ list5.add_all_array (data5); -//~ p = list5; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - - -//~ uint[] data6 = { 123, 456, 19875, 64205, 1549924563 }; -//~ var list6 = new Gee.ArrayList (); -//~ list6.add_all_array (data6); -//~ p = list6; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - - -//~ uint8[] data7 = { 97, 99, 122, 72 }; -//~ var list7 = new Gee.ArrayList (); -//~ list7.add_all_array (data7); -//~ foreach (uint8 u in list7) { -//~ of.echo(" - item7 : %u".printf (u)); -//~ } -//~ p = list7; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - - -//~ uchar[] data8 = { 'a', 'c', 'z', 'H' }; -//~ var list8 = new Gee.ArrayList (); -//~ list8.add_all_array (data8); -//~ foreach (uchar u in list8) { -//~ of.echo(" - item8 : %c".printf (u)); -//~ } -//~ p = list8; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode, true); - - -//~ unichar[] data9 = { '水', 'は', '方', 'の', 'é', 'à', 'ï', 'Ô' }; -//~ var list9 = new Gee.ArrayList (); -//~ list9.add_all_array (data9); -//~ foreach (unichar u in list9) { -//~ of.echo(" - item9 : %s (%lu)".printf (u.to_string (), u)); -//~ } -//~ p = list9; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode, true); - - -//~ uint64?[] data10 = { 4521, 8954354, 4535213213 }; -//~ var list10 = new Gee.ArrayList (); -//~ list10.add_all_array (data10); -//~ foreach (uint64 u in list10) { -//~ of.echo(" - item10 : %s".printf (u.to_string ())); -//~ } -//~ p = list10; -//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList", mynode); - -//~ mynode.display_childs (); - of.rs (done); of.echo (); return (int) done; diff --git a/install.vala.in b/src/install.vala similarity index 99% rename from install.vala.in rename to src/install.vala index 26ec2ba..926c6f1 100644 --- a/install.vala.in +++ b/src/install.vala @@ -28,7 +28,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/ namespace Pluie -{ +{ namespace Yaml { protected const string INSTALL_PATH = "@INSTALL_PATH@"; diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..c5e2081 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,57 @@ +#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# +# @software : pluie-yaml +# @version : 0.54 +# @type : library +# @date : 2018 +# @license : GPLv3.0 +# @author : a-Sansara <[dev]at[pluie]dot[org]> +# @copyright : 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 . +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^# + +src_files = [ + 'src/c/yaml.c', + 'src/vala/Pluie/Io.Reader.vala', + 'src/vala/Pluie/Io.InputChunkStream.vala', + 'src/vala/Pluie/Io.StreamLineMark.vala', + 'src/vala/Pluie/Io.Writter.vala', + 'src/vala/Pluie/Yaml.global.vala', + 'src/vala/Pluie/Yaml.AbstractChild.vala', + 'src/vala/Pluie/Yaml.AbstractNode.vala', + 'src/vala/Pluie/Yaml.Builder.vala', + 'src/vala/Pluie/Yaml.Collection.vala', + 'src/vala/Pluie/Yaml.Config.vala', + 'src/vala/Pluie/Yaml.Dumper.vala', + 'src/vala/Pluie/Yaml.Event.vala', + 'src/vala/Pluie/Yaml.Finder.vala', + 'src/vala/Pluie/Yaml.GeeBuilder.vala', + 'src/vala/Pluie/Yaml.Loader.vala', + 'src/vala/Pluie/Yaml.Mapping.vala', + 'src/vala/Pluie/Yaml.Node.vala', + 'src/vala/Pluie/Yaml.Object.vala', + 'src/vala/Pluie/Yaml.Processor.vala', + 'src/vala/Pluie/Yaml.Register.vala', + 'src/vala/Pluie/Yaml.Root.vala', + 'src/vala/Pluie/Yaml.Scalar.vala', + 'src/vala/Pluie/Yaml.Scanner.vala', + 'src/vala/Pluie/Yaml.Sequence.vala', + 'src/vala/Pluie/Yaml.Tag.vala' +] diff --git a/src/vala/Pluie/Yaml.ExampleChild.vala b/src/vala/Pluie/Samples.YamlChild.vala similarity index 97% rename from src/vala/Pluie/Yaml.ExampleChild.vala rename to src/vala/Pluie/Samples.YamlChild.vala index 94948cc..e433ac8 100644 --- a/src/vala/Pluie/Yaml.ExampleChild.vala +++ b/src/vala/Pluie/Samples.YamlChild.vala @@ -30,7 +30,7 @@ /** * a test class to implements yamlize */ -public class Pluie.Yaml.ExampleChild : Yaml.Object +public class Pluie.Samples.YamlChild : Yaml.Object { public string toto { get; set; } public string tata { get; set; } diff --git a/src/vala/Pluie/Yaml.Example.vala b/src/vala/Pluie/Samples.YamlObject.vala similarity index 56% rename from src/vala/Pluie/Yaml.Example.vala rename to src/vala/Pluie/Samples.YamlObject.vala index 0eb1616..1afa73c 100644 --- a/src/vala/Pluie/Yaml.Example.vala +++ b/src/vala/Pluie/Samples.YamlObject.vala @@ -34,44 +34,47 @@ using Pluie; /** * a test class to implements yamlize */ -public class Pluie.Yaml.Example : Yaml.Object +public class Pluie.Samples.YamlObject : Yaml.Object { - public string myname { get; set; } - public string type_string { get; set; } - public int type_int { get; set; } - public uint type_uint { get; set; } - public float type_float { get; set; } - public double type_double { get; set; } - public char type_char { get; set; } - public uchar type_uchar { get; set; } - public unichar type_unichar { get; set; } - public short type_short { get; set; } - public ushort type_ushort { get; set; } - public long type_long { get; set; } - public ulong type_ulong { get; set; } - public size_t type_size_t { get; set; } - public ssize_t type_ssize_t { get; set; } - public int8 type_int8 { get; set; } - public uint8 type_uint8 { get; set; } - public int16 type_int16 { get; set; } - public uint16 type_uint16 { get; set; } - public int32 type_int32 { get; set; } - public uint32 type_uint32 { get; set; } - public int64 type_int64 { get; set; } - public uint64 type_uint64 { get; set; } - public bool type_bool { get; set; } - public Yaml.ExampleChild type_object { get; set; } - public Yaml.NODE_TYPE type_enum { get; set; } - public Yaml.ExampleStruct type_struct { get; set; } - public Gee.ArrayList type_gee_al { get; set; } - public Gee.ArrayList type_gee_alobject { get; set; } + public string myname { get; set; } + public string type_string { get; set; } + public int type_int { get; set; } + public uint type_uint { get; set; } + public float type_float { get; set; } + public double type_double { get; set; } + public char type_char { get; set; } + public uchar type_uchar { get; set; } + public unichar type_unichar { get; set; } + public short type_short { get; set; } + public ushort type_ushort { get; set; } + public long type_long { get; set; } + public ulong type_ulong { get; set; } + public size_t type_size_t { get; set; } + public ssize_t type_ssize_t { get; set; } + public int8 type_int8 { get; set; } + public uint8 type_uint8 { get; set; } + public int16 type_int16 { get; set; } + public uint16 type_uint16 { get; set; } + public int32 type_int32 { get; set; } + public uint32 type_uint32 { get; set; } + public int64 type_int64 { get; set; } + public uint64 type_uint64 { get; set; } + public bool type_bool { get; set; } + public Samples.YamlChild type_object { get; set; } + public Yaml.NODE_TYPE type_enum { get; set; } + public Samples.YamlStruct type_struct { get; set; } + public Gee.ArrayList type_gee_al { get; set; } + public Gee.ArrayList type_gee_alobject { get; set; } + /** + * + */ static construct { Yaml.Register.add_type ( - typeof (Yaml.Example), - typeof (Yaml.ExampleChild), - typeof (Yaml.ExampleStruct), + typeof (Samples.YamlObject), + typeof (Samples.YamlChild), + typeof (Samples.YamlStruct), typeof (Gee.ArrayList) ); } @@ -82,8 +85,8 @@ public class Pluie.Yaml.Example : Yaml.Object protected override void yaml_construct () { this.type_gee_al = new Gee.ArrayList (); - this.type_gee_alobject = new Gee.ArrayList (); - Yaml.Register.add_namespace("Gee", "GLib"); + this.type_gee_alobject = new Gee.ArrayList (); + Yaml.Register.add_namespace("Gee", "Pluie.Samples"); Dbg.msg ("%s (%s) instantiated".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE); } @@ -99,8 +102,8 @@ public class Pluie.Yaml.Example : Yaml.Object * */ public override void populate_from_node (string name, GLib.Type type, Yaml.Node node) { - if (type == typeof (Yaml.ExampleStruct)) { - this.type_struct = Yaml.ExampleStruct.from_yaml_node (node); + if (type == typeof (Samples.YamlStruct)) { + this.type_struct = Samples.YamlStruct.from_yaml_node (node); } else if (type == typeof (Gee.ArrayList)) { foreach (var child in node) { @@ -109,7 +112,7 @@ public class Pluie.Yaml.Example : Yaml.Object this.type_gee_al.add(double.parse(child.data)); break; case "type_gee_alobject": - this.type_gee_alobject.add((Yaml.ExampleChild) Yaml.Builder.from_node (child, typeof (Yaml.ExampleChild))); + this.type_gee_alobject.add((Samples.YamlChild) Yaml.Builder.from_node (child, typeof (Samples.YamlChild))); break; } } @@ -117,7 +120,7 @@ public class Pluie.Yaml.Example : Yaml.Object else { var obj = Yaml.Builder.from_node(node, type); if (name == "type_object") { - this.set (node.name, (Yaml.ExampleChild) obj); + this.set (node.name, (Samples.YamlChild) obj); } else { this.set (node.name, obj); @@ -125,20 +128,12 @@ public class Pluie.Yaml.Example : Yaml.Object } } - /** - * match delegate CastYamlObject - */ - public GLib.Object cast_child_collection (string name, GLib.Object obj) - { - return (GLib.Object) ((Yaml.ExampleChild) obj); - } - /** * */ public override Yaml.Node? populate_to_node (string name, GLib.Type type, Yaml.Node parent) { Yaml.Node? node = null; - if (type == typeof (Yaml.ExampleStruct)) { + if (type == typeof (Samples.YamlStruct)) { node = this.type_struct.to_yaml_node (name); } else if (type == typeof (Gee.ArrayList)) { diff --git a/src/vala/Pluie/Yaml.ExampleStruct.vala b/src/vala/Pluie/Samples.YamlStruct.vala similarity index 90% rename from src/vala/Pluie/Yaml.ExampleStruct.vala rename to src/vala/Pluie/Samples.YamlStruct.vala index c560c85..639cc39 100644 --- a/src/vala/Pluie/Yaml.ExampleStruct.vala +++ b/src/vala/Pluie/Samples.YamlStruct.vala @@ -30,7 +30,7 @@ /** * */ -public struct Pluie.Yaml.ExampleStruct +public struct Pluie.Samples.YamlStruct { /** * @@ -48,9 +48,9 @@ public struct Pluie.Yaml.ExampleStruct /** * */ - public static ExampleStruct from_yaml_node (Yaml.Node node) + public static YamlStruct from_yaml_node (Yaml.Node node) { - ExampleStruct s = {}; + YamlStruct s = {}; foreach (var child in node) { var v = child.val (typeof (uint)); switch (child.name) { @@ -79,6 +79,6 @@ public struct Pluie.Yaml.ExampleStruct */ public string to_string () { - return "%s(red:%u,green:%u,blue:%u)".printf ((typeof (ExampleStruct)).name (), this.red, this.green, this.blue); + return "%s(red:%u,green:%u,blue:%u)".printf ((typeof (YamlStruct)).name (), this.red, this.green, this.blue); } } diff --git a/src/vala/Pluie/Yaml.Builder.vala b/src/vala/Pluie/Yaml.Builder.vala index 26c866a..69fb2ac 100644 --- a/src/vala/Pluie/Yaml.Builder.vala +++ b/src/vala/Pluie/Yaml.Builder.vala @@ -90,20 +90,40 @@ public class Pluie.Yaml.Builder return type; } + /** + * + */ + private static string resolve_c_subname (string name) throws GLib.RegexError + { + MatchInfo? mi = null; + bool update = false; + var reg = new Regex ("([A-Z]{1}[a-z]+)"); + string? str = null; + var sb = new StringBuilder(); + for (reg.match (name, 0, out mi) ; mi.matches () ; mi.next ()) { + if ((str = mi.fetch (1)) != null && str.length > 0) { + sb.append ("%s%s%s".printf (update ? "_" : "", str[0].tolower ().to_string (), str.substring(1))); + if (!update) update = true; + } + } + return update ? sb.str : name; + } + /** * retriew corresponding c name related to specified vala name * @param name a valid vala identifier name */ public static string resolve_c_name (string name) { - string? str = null; - MatchInfo? mi = null; + string? str = null; + MatchInfo? mi = null; StringBuilder sb = new StringBuilder (); bool begin = true; try { var reg = new Regex ("([^.]*).?"); for (reg.match (name, 0, out mi) ; mi.matches () ; mi.next ()) { - if ((str = mi.fetch (1)) != null && str.length > 0) { + str = Yaml.Builder.resolve_c_subname(mi.fetch (1)); + if (str != null && str.length > 0) { if (!begin) sb.append_unichar ('_'); else begin = false; sb.append_unichar (str[0].tolower ()); @@ -128,47 +148,42 @@ public class Pluie.Yaml.Builder public static GLib.Object? from_node (Yaml.Node node, Type otype = GLib.Type.INVALID) { GLib.Object? obj = null; - try { - Type type = node.tag != null ? type_from_tag (node.tag.value) : otype; - if (type != Type.INVALID) { - Yaml.dbg_action ("vala type founded", "%s (%s)".printf (type.name (), type.to_string ())); - if (type.is_object ()) { - obj = GLib.Object.new (type); - if (type.is_a (typeof (Yaml.Object))) { - (obj as Yaml.Object).set ("yaml_name", node.name); - (obj as Yaml.Object).yaml_construct (); - } - if (node!= null && !node.empty ()) { - GLib.ParamSpec? def = null; - Yaml.Node? scalar = null; - foreach (var child in node) { - if ((def = obj.get_class ().find_property (child.name)) != null) { - Yaml.dbg ("== prop [%s] type is : %s".printf (child.name, def.value_type.name ())); - if (child.ntype.is_single_pair () && (scalar = child.first ()) != null) { - set_from_scalar (ref obj, def.name, def.value_type, scalar.data); - } - else if (child.ntype.is_collection ()) { - set_from_collection (ref obj, type, child, def.value_type); - } + Type type = node.tag != null ? type_from_tag (node.tag.value) : otype; + if (type != Type.INVALID) { + Yaml.dbg_action ("vala type founded", "%s (%s)".printf (type.name (), type.to_string ())); + if (type.is_object ()) { + obj = GLib.Object.new (type); + if (type.is_a (typeof (Yaml.Object))) { + (obj as Yaml.Object).set ("yaml_name", node.name); + (obj as Yaml.Object).yaml_construct (); + } + if (node!= null && !node.empty ()) { + GLib.ParamSpec? def = null; + Yaml.Node? scalar = null; + foreach (var child in node) { + if ((def = obj.get_class ().find_property (child.name)) != null) { + Yaml.dbg ("== prop [%s] type is : %s".printf (child.name, def.value_type.name ())); + if (child.ntype.is_single_pair () && (scalar = child.first ()) != null) { + set_from_scalar (ref obj, def.name, def.value_type, scalar.data); } - else { - of.warn ("property %s not found".printf (child.name)); + else if (child.ntype.is_collection ()) { + set_from_collection (ref obj, type, child, def.value_type); } } + else { + of.warn ("property %s not found".printf (child.name)); + } } } } - if (obj == null) { - of.warn ("searched type not found : %s".printf (type.name ())); - } - else { - if (type.is_a (typeof (Yaml.Object))) { - (obj as Yaml.Object).yaml_init (); - } - } } - catch (GLib.Error e) { - of.warn (e.message); + if (obj == null) { + of.warn ("searched type not found : %s".printf (type.name ())); + } + else { + if (type.is_a (typeof (Yaml.Object))) { + (obj as Yaml.Object).yaml_init (); + } } return obj; }