fix set enum value
This commit is contained in:
parent
2692c633ae
commit
68d2c026d4
|
@ -12,6 +12,7 @@
|
||||||
type_uint : !v!uint 62005
|
type_uint : !v!uint 62005
|
||||||
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
|
||||||
!v!Pluie.Yaml.SubExample type_object :
|
!v!Pluie.Yaml.SubExample type_object :
|
||||||
toto : totovalue1
|
toto : totovalue1
|
||||||
tata : tatavalue1
|
tata : tatavalue1
|
||||||
|
|
54
samples/yaml-tag2.vala
Normal file
54
samples/yaml-tag2.vala
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||||
|
* @version : 0.4
|
||||||
|
* @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 lib-yaml.
|
||||||
|
*
|
||||||
|
* lib-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.
|
||||||
|
*
|
||||||
|
* lib-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 lib-yaml. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
|
||||||
|
using GLib;
|
||||||
|
using Gee;
|
||||||
|
using Pluie;
|
||||||
|
|
||||||
|
int main (string[] args)
|
||||||
|
{
|
||||||
|
Echo.init(false);
|
||||||
|
|
||||||
|
var path = Yaml.DATA_PATH + "/tag.yml";
|
||||||
|
var done = false;
|
||||||
|
|
||||||
|
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||||
|
Pluie.Yaml.Scanner.DEBUG = true;
|
||||||
|
Yaml.Object? obj = null;
|
||||||
|
var config = new Yaml.Config (path, true);
|
||||||
|
var root = config.root_node ();
|
||||||
|
root.display_childs ();
|
||||||
|
// define a map with base Yaml.Object type rather than target type
|
||||||
|
obj = Yaml.Object.from_node (root.first());
|
||||||
|
|
||||||
|
of.rs (done);
|
||||||
|
of.echo ();
|
||||||
|
return (int) done;
|
||||||
|
|
||||||
|
}
|
|
@ -58,6 +58,7 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
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.SubExample type_object { get; set; }
|
public Yaml.SubExample type_object { get; set; }
|
||||||
|
public Yaml.NODE_TYPE type_enum { get; set; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -185,41 +185,66 @@ public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
of.action("Auto setting property value %s".printf (of.c (ECHO.MICROTIME).s (type.name ())), name);
|
of.action("Auto setting property value %s".printf (of.c (ECHO.MICROTIME).s (type.name ())), name);
|
||||||
of.echo (data);
|
of.echo (data);
|
||||||
}
|
}
|
||||||
switch (type)
|
if (type.is_a(Type.ENUM)) {
|
||||||
{
|
this.set_enum_value (ref v, type, data);
|
||||||
case Type.STRING :
|
}
|
||||||
v.set_string(data);
|
else {
|
||||||
break;
|
switch (type)
|
||||||
case Type.CHAR :
|
{
|
||||||
v.set_schar((int8)data.data[0]);
|
case Type.STRING :
|
||||||
break;
|
v.set_string(data);
|
||||||
case Type.UCHAR :
|
break;
|
||||||
v.set_uchar((uint8)data.data[0]);
|
case Type.CHAR :
|
||||||
break;
|
v.set_schar((int8)data.data[0]);
|
||||||
case Type.BOOLEAN :
|
break;
|
||||||
v.set_boolean (data == "1" || data.down () == "true");
|
case Type.UCHAR :
|
||||||
break;
|
v.set_uchar((uint8)data.data[0]);
|
||||||
case Type.INT :
|
break;
|
||||||
v.set_int(int.parse(data));
|
case Type.BOOLEAN :
|
||||||
break;
|
v.set_boolean (data == "1" || data.down () == "true");
|
||||||
case Type.UINT :
|
break;
|
||||||
v.set_uint((uint)long.parse(data));
|
case Type.INT :
|
||||||
break;
|
v.set_int(int.parse(data));
|
||||||
case Type.LONG :
|
break;
|
||||||
case Type.INT64 :
|
case Type.UINT :
|
||||||
v.set_long((long)int64.parse(data));
|
v.set_uint((uint)long.parse(data));
|
||||||
break;
|
break;
|
||||||
case Type.ULONG :
|
case Type.LONG :
|
||||||
case Type.UINT64 :
|
case Type.INT64 :
|
||||||
v.set_ulong((ulong)uint64.parse(data));
|
v.set_long((long)int64.parse(data));
|
||||||
break;
|
break;
|
||||||
case Type.FLOAT :
|
case Type.ULONG :
|
||||||
v.set_float((float)double.parse(data));
|
case Type.UINT64 :
|
||||||
break;
|
v.set_ulong((ulong)uint64.parse(data));
|
||||||
case Type.DOUBLE :
|
break;
|
||||||
v.set_double(double.parse(data));
|
case Type.FLOAT :
|
||||||
break;
|
v.set_float((float)double.parse(data));
|
||||||
|
break;
|
||||||
|
case Type.DOUBLE :
|
||||||
|
v.set_double(double.parse(data));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.set_property(name, v);
|
this.set_property(name, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void set_enum_value (ref Value v, GLib.Type type, string data)
|
||||||
|
{
|
||||||
|
EnumClass eclass = (EnumClass) type.class_ref();
|
||||||
|
unowned EnumValue? evalue = eclass.get_value_by_name(data);
|
||||||
|
if (evalue == null) {
|
||||||
|
evalue = eclass.get_value_by_nick(data.down());
|
||||||
|
int64 e = 0;
|
||||||
|
if(evalue == null) {
|
||||||
|
if(!int64.try_parse(data, out e)) {
|
||||||
|
Dbg.error ("invalid enum value %s".printf(data), Log.METHOD, Log.LINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e = evalue.value;
|
||||||
|
v.set_enum((int)e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user