extract samples classes from lib

This commit is contained in:
a-sansara 2018-08-29 16:27:04 +02:00
parent 487a5cd107
commit 2acc2930ce
15 changed files with 214 additions and 268 deletions

View File

@ -27,7 +27,6 @@
- meson : - meson :
file : file :
- meson.build - meson.build
startline : 1
sepline : sepline :
motif : "# " motif : "# "
repeat : 40 repeat : 40
@ -43,7 +42,6 @@
- .c - .c
file : file :
- install.vala.in - install.vala.in
startline : 1
sepline : sepline :
motif : " *" motif : " *"
repeat : 40 repeat : 40
@ -71,6 +69,6 @@
more details. more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with ^software.name^. If not, see <http://www.gnu.org/licenses/>. along with ^software.name^. If not, see ^license.address^.
^sepline^ ^sepline^

View File

@ -29,14 +29,17 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
# -------------------------------------------------------- # --------------------------------------------------------
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
lib="pluie-yaml-0.5" 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" c1="\033[1;38;5;215m"
c2="\033[1;38;5;97m" c2="\033[1;38;5;97m"
cok="\033[1;38;5;37m" cok="\033[1;38;5;37m"
cko="\033[1;38;5;204m" cko="\033[1;38;5;204m"
off="\033[m" off="\033[m"
resume= resume=
# -------------------------------------------------------- # --------------------------------------------------------
function build.title() function build.title()
{ {
@ -94,9 +97,9 @@ function build.sample()
local f="$(basename $1)" local f="$(basename $1)"
local fx="${f:0:-5}" local fx="${f:0:-5}"
local state="FAILED" 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" build.title "$f SAMPLE BUILD"
echo -e "\n$cmd" echo
$cmd $cmd
local done=$? local done=$?
resume="$resume$done$f " resume="$resume$done$f "

View File

@ -26,26 +26,15 @@
# along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>. # along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
project('pluie-yaml', 'vala', 'c', version:'0.5')
project('pluie-yaml', ['vala', 'c'], version:'0.5')
cc = meson.get_compiler('c') 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() version = meson.project_version()
bindir = join_paths(get_option('prefix'), get_option('bindir')) bindir = join_paths(get_option('prefix'), get_option('bindir'))
datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie/yaml') datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie/yaml')
libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig') libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig')
incdir = join_paths(get_option('prefix'), get_option('includedir'), 'pluie') incdir = join_paths(get_option('prefix'), get_option('includedir'), 'pluie')
conf = configuration_data() conf = configuration_data()
conf.set('VERSION' , version) conf.set('VERSION' , version)
conf.set('INSTALL_PATH', bindir) conf.set('INSTALL_PATH', bindir)
@ -57,52 +46,34 @@ configure_file(
configuration: conf configuration: conf
) )
sources = [ install_data([
'build/install.vala', 'resources/main.yml',
'src/vala/Pluie/Io.Reader.vala', 'resources/tag.yml',
'src/vala/Pluie/Io.InputChunkStream.vala', 'resources/test.yml',
'src/vala/Pluie/Io.StreamLineMark.vala', 'resources/test.json'
'src/vala/Pluie/Io.Writter.vala', ],
'src/vala/Pluie/Yaml.global.vala', install_dir : datadir
'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/config/db.yml', install_dir : join_paths(datadir, 'config')) 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')) install_data('resources/config/subdir/test.yml', install_dir : join_paths(datadir, 'config/subdir'))
subdir('src')
libpluie_yaml = library( libpluie_yaml = library(
'pluie-yaml-' + version, 'pluie-yaml-' + version,
sources, src_files + [ 'build/install.vala' ],
vala_header : 'pluie_yaml.h', vala_header : 'pluie_yaml.h',
vala_vapi : 'pluie-yaml-' +version+'.vapi', 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, install : true,
version : version, version : version,
install_dir : [get_option('libdir'), incdir, true] install_dir : [get_option('libdir'), incdir, true]

View File

@ -1,7 +1,7 @@
%YAML 1.2 %YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/ %TAG !v! tag:pluie.org,2018:vala/
--- ---
!v!Pluie.Yaml.Example test1 : !v!Pluie.Samples.YamlObject test1 :
myname : test1object myname : test1object
type_int : !v!int 3306 type_int : !v!int 3306
type_bool : !v!bool false type_bool : !v!bool false
@ -12,12 +12,12 @@
type_float : !v!float 42.36 type_float : !v!float 42.36
type_double : !v!double 95542123.4579512128 type_double : !v!double 95542123.4579512128
type_enum : !v!Pluie.Yaml.NODE_TYPE scalar # or int type_enum : !v!Pluie.Yaml.NODE_TYPE scalar # or int
!v!Pluie.Yaml.ExampleChild type_object : !v!Pluie.Samples.YamlChild type_object :
toto : totovalue1 toto : totovalue1
tata : tatavalue1 tata : tatavalue1
titi : 123 titi : 123
tutu : 1 tutu : 1
!v!Pluie.Yaml.ExampleStruct type_struct : !v!Pluie.Samples.YamlStruct type_struct :
red : !v!uint8 214 red : !v!uint8 214
green : !v!uint8 78 green : !v!uint8 78
blue : 153 blue : 153

View File

@ -46,21 +46,13 @@ int main (string[] args)
if ((done = root != null)) { if ((done = root != null)) {
root.display_childs (); root.display_childs ();
of.action("Yaml.Node", "to_yaml_string"); of.action("Yaml.Node", "to_yaml_string");
string yaml = root.to_yaml_string ();
string genpath = "./tag-generated.yml"; string genpath = "./tag-generated.yml";
try {
var writter = new Io.Writter (genpath, true); var writter = new Io.Writter (genpath, true);
long written = 0; long written = 0;
writter.write (yaml.data, out written); writter.write (root.to_yaml_string ().data, out written);
of.echo ("write %ld bytes in `%s`".printf ((long) written, genpath)); of.echo ("write %ld bytes in `%s`".printf ((long) written, genpath));
Yaml.Dumper.show_yaml_string (root, true, true, true); Yaml.Dumper.show_yaml_string (root, true, true, true);
}
catch (Error e) {
stderr.printf ("%s\n", e.message);
return 1;
}
} }

View File

@ -32,7 +32,7 @@ using GLib;
using Gee; using Gee;
using Pluie; using Pluie;
public void test_object(Yaml.Example obj) public void test_object(Samples.YamlObject obj)
{ {
of.action ("Test Object", obj.yaml_name); of.action ("Test Object", obj.yaml_name);
obj.type_object.method_a (); obj.type_object.method_a ();
@ -86,8 +86,7 @@ int main (string[] args)
root.display_childs (); root.display_childs ();
of.action ("Yaml build first child", root.first ().name); of.action ("Yaml build first child", root.first ().name);
Yaml.Example obj = (Yaml.Example) Yaml.Builder.from_node (root.first ()); var obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
obj = (Yaml.Example) Yaml.Builder.from_node (root.first ());
test_object (obj); test_object (obj);
of.action ("Serialize", obj.yaml_name); of.action ("Serialize", obj.yaml_name);
@ -100,7 +99,7 @@ int main (string[] args)
root = Yaml.deserialize (zdata); root = Yaml.deserialize (zdata);
root.display_childs (); root.display_childs ();
of.action ("Yaml build first child", obj.yaml_name); 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); test_object (obj);
} }

View File

@ -60,11 +60,12 @@ int main (string[] args)
node = node.next_sibling (); node = node.next_sibling ();
} }
} }
// hard code // hard code
Yaml.Example? o = null; Samples.YamlObject? o = null;
foreach (var entry in list.entries) { foreach (var entry in list.entries) {
if ((o = (Yaml.Example) entry.value)!=null) { if ((o = (Samples.YamlObject) 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); 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("yaml_name" , "%s" .printf(o.yaml_name));
of.keyval("type_int" , "%d" .printf(o.type_int)); of.keyval("type_int" , "%d" .printf(o.type_int));
of.keyval("type_bool" , "%s" .printf(o.type_bool.to_string ())); of.keyval("type_bool" , "%s" .printf(o.type_bool.to_string ()));

View File

@ -46,7 +46,7 @@ int main (string[] args)
root.first ().display_childs (); root.first ().display_childs ();
of.action ("with signal Yaml.Builder.from_node", root.first ().name); 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 (); obj.type_object.method_a ();
if (obj.type_gee_al != null) { 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 ())); of.keyval("type_gee_al", "(%s<%s>)" .printf(obj.type_gee_al.get_type ().name (), obj.type_gee_al.element_type.name ()));

View File

@ -103,13 +103,13 @@ 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 = true; Pluie.Yaml.DEBUG = false;
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 ();
root.first ().display_childs (); root.first ().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 ()); Samples.YamlObject obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
obj.type_object.method_a (); obj.type_object.method_a ();
if (obj.type_gee_al != null) { if (obj.type_gee_al != null) {
of.keyval("type_gee_al", "(%s)" .printf(obj.type_gee_al.get_type ().name ())); 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 (); n.display_childs ();
} }
//~ double?[] data = { 46548970.54324546464, 2.2, 2.1, 2.4, 5.7 };
//~ var list = new Gee.ArrayList<double?> ();
//~ list.add_all_array (data);
//~ Gee.ArrayList* p = list;
//~ var mynode = new Yaml.Root ();
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<double?>", mynode);
//~ string[] data2 = { "mastring1", "mastring2", "mastring3", "mastring4", "mastring5" };
//~ var list2 = new Gee.ArrayList<string> ();
//~ list2.add_all_array (data2);
//~ p = list2;
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<string>", mynode);
//~ int[] data3 = { 123, 456, 9875, 64205, 9924563 };
//~ var list3 = new Gee.ArrayList<int> ();
//~ list3.add_all_array (data3);
//~ p = list3;
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<int>", mynode);
//~ int64?[] data4 = { 123, 456, -9875, 64205, -549924563 };
//~ var list4 = new Gee.ArrayList<int64?> ();
//~ list4.add_all_array (data4);
//~ p = list4;
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<int64?>", mynode);
//~ long?[] data5 = { 123, 456, -9875, 64205, -549924563 };
//~ var list5 = new Gee.ArrayList<long?> ();
//~ list5.add_all_array (data5);
//~ p = list5;
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<long?>", mynode);
//~ uint[] data6 = { 123, 456, 19875, 64205, 1549924563 };
//~ var list6 = new Gee.ArrayList<uint> ();
//~ list6.add_all_array (data6);
//~ p = list6;
//~ Yaml.GeeBuilder.arraylist_to_node (p, "Gee.ArrayList<uint>", mynode);
//~ uint8[] data7 = { 97, 99, 122, 72 };
//~ var list7 = new Gee.ArrayList<uint8> ();
//~ 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<uint8>", mynode);
//~ uchar[] data8 = { 'a', 'c', 'z', 'H' };
//~ var list8 = new Gee.ArrayList<uchar> ();
//~ 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<uchar>", mynode, true);
//~ unichar[] data9 = { '水', 'は', '方', 'の', 'é', 'à', 'ï', 'Ô' };
//~ var list9 = new Gee.ArrayList<unichar> ();
//~ 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<unichar?>", mynode, true);
//~ uint64?[] data10 = { 4521, 8954354, 4535213213 };
//~ var list10 = new Gee.ArrayList<uint64?> ();
//~ 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<uint64?>", mynode);
//~ mynode.display_childs ();
of.rs (done); of.rs (done);
of.echo (); of.echo ();
return (int) done; return (int) done;

57
src/meson.build Normal file
View File

@ -0,0 +1,57 @@
#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
# @version : 0.54
# @type : library
# @date : 2018
# @license : 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/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
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'
]

View File

@ -30,7 +30,7 @@
/** /**
* a test class to implements yamlize * 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 toto { get; set; }
public string tata { get; set; } public string tata { get; set; }

View File

@ -34,7 +34,7 @@ using Pluie;
/** /**
* a test class to implements yamlize * 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 myname { get; set; }
public string type_string { get; set; } public string type_string { get; set; }
@ -60,18 +60,21 @@ public class Pluie.Yaml.Example : Yaml.Object
public int64 type_int64 { get; set; } public int64 type_int64 { get; set; }
public uint64 type_uint64 { get; set; } public uint64 type_uint64 { get; set; }
public bool type_bool { get; set; } public bool type_bool { get; set; }
public Yaml.ExampleChild type_object { get; set; } public Samples.YamlChild 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 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<Yaml.ExampleChild> type_gee_alobject { get; set; } public Gee.ArrayList<Samples.YamlChild> type_gee_alobject { get; set; }
/**
*
*/
static construct static construct
{ {
Yaml.Register.add_type ( Yaml.Register.add_type (
typeof (Yaml.Example), typeof (Samples.YamlObject),
typeof (Yaml.ExampleChild), typeof (Samples.YamlChild),
typeof (Yaml.ExampleStruct), typeof (Samples.YamlStruct),
typeof (Gee.ArrayList) typeof (Gee.ArrayList)
); );
} }
@ -82,8 +85,8 @@ public class Pluie.Yaml.Example : Yaml.Object
protected override void yaml_construct () protected override void yaml_construct ()
{ {
this.type_gee_al = new Gee.ArrayList<double?> (); this.type_gee_al = new Gee.ArrayList<double?> ();
this.type_gee_alobject = new Gee.ArrayList<Yaml.ExampleChild> (); this.type_gee_alobject = new Gee.ArrayList<Samples.YamlChild> ();
Yaml.Register.add_namespace("Gee", "GLib"); 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);
} }
@ -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) { public override void populate_from_node (string name, GLib.Type type, Yaml.Node node) {
if (type == typeof (Yaml.ExampleStruct)) { if (type == typeof (Samples.YamlStruct)) {
this.type_struct = Yaml.ExampleStruct.from_yaml_node (node); this.type_struct = Samples.YamlStruct.from_yaml_node (node);
} }
else if (type == typeof (Gee.ArrayList)) { else if (type == typeof (Gee.ArrayList)) {
foreach (var child in node) { 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)); this.type_gee_al.add(double.parse(child.data));
break; break;
case "type_gee_alobject": 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; break;
} }
} }
@ -117,7 +120,7 @@ public class Pluie.Yaml.Example : Yaml.Object
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") {
this.set (node.name, (Yaml.ExampleChild) obj); this.set (node.name, (Samples.YamlChild) obj);
} }
else { else {
this.set (node.name, obj); 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) { public override Yaml.Node? populate_to_node (string name, GLib.Type type, Yaml.Node parent) {
Yaml.Node? node = null; Yaml.Node? node = null;
if (type == typeof (Yaml.ExampleStruct)) { if (type == typeof (Samples.YamlStruct)) {
node = this.type_struct.to_yaml_node (name); node = this.type_struct.to_yaml_node (name);
} }
else if (type == typeof (Gee.ArrayList)) { else if (type == typeof (Gee.ArrayList)) {

View File

@ -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) { foreach (var child in node) {
var v = child.val (typeof (uint)); var v = child.val (typeof (uint));
switch (child.name) { switch (child.name) {
@ -79,6 +79,6 @@ public struct Pluie.Yaml.ExampleStruct
*/ */
public string to_string () 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);
} }
} }

View File

@ -90,6 +90,25 @@ public class Pluie.Yaml.Builder
return type; 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 * retriew corresponding c name related to specified vala name
* @param name a valid vala identifier name * @param name a valid vala identifier name
@ -103,7 +122,8 @@ public class Pluie.Yaml.Builder
try { try {
var reg = new Regex ("([^.]*).?"); var reg = new Regex ("([^.]*).?");
for (reg.match (name, 0, out mi) ; mi.matches () ; mi.next ()) { 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 ('_'); if (!begin) sb.append_unichar ('_');
else begin = false; else begin = false;
sb.append_unichar (str[0].tolower ()); sb.append_unichar (str[0].tolower ());
@ -128,7 +148,6 @@ public class Pluie.Yaml.Builder
public static GLib.Object? from_node (Yaml.Node node, Type otype = GLib.Type.INVALID) public static GLib.Object? from_node (Yaml.Node node, Type otype = GLib.Type.INVALID)
{ {
GLib.Object? obj = null; GLib.Object? obj = null;
try {
Type type = node.tag != null ? type_from_tag (node.tag.value) : otype; Type type = node.tag != null ? type_from_tag (node.tag.value) : otype;
if (type != Type.INVALID) { if (type != Type.INVALID) {
Yaml.dbg_action ("vala type founded", "%s (%s)".printf (type.name (), type.to_string ())); Yaml.dbg_action ("vala type founded", "%s (%s)".printf (type.name (), type.to_string ()));
@ -166,10 +185,6 @@ public class Pluie.Yaml.Builder
(obj as Yaml.Object).yaml_init (); (obj as Yaml.Object).yaml_init ();
} }
} }
}
catch (GLib.Error e) {
of.warn (e.message);
}
return obj; return obj;
} }