From 3f3c1b1d590fbfb119d4ea5583543c3ed2550f5b Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Mon, 10 Aug 2015 20:24:16 +0300 Subject: [PATCH] GObject Style Construction... --- vala/array_sort/array_sort.vala | 55 ++++++++++++++++++++++++++ vala/gobj_style_construction/main.vala | 25 ++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 vala/array_sort/array_sort.vala create mode 100644 vala/gobj_style_construction/main.vala diff --git a/vala/array_sort/array_sort.vala b/vala/array_sort/array_sort.vala new file mode 100644 index 0000000..45a3293 --- /dev/null +++ b/vala/array_sort/array_sort.vala @@ -0,0 +1,55 @@ +/** + * Bounds of the ``ATable`` to split. + */ +public struct SplitLimit { + + /** + * First column index [0; last]. + */ + uint first; + + /** + * Last column index [first; ncols - 1]. + */ + uint last; + + /** + * Maximum of columns per page [1; ncols]. + */ + uint max_cols; +} + +void print_list (List array) { + for (var i = 0; i < array.length(); ++i) { + stdout.printf ("%lu %lu %lu\n", array.nth(i).data.first, + array.nth(i).data.last, array.nth(i).data.max_cols); + } +} + +void main () { + var array = new List (); + SplitLimit lim = { 9, 11, 3 }; + array.append (lim); + lim = { 2, 6, 2 }; + array.append (lim); + lim = { 13, 16, 1 }; + array.append (lim); + //array.append ("ccc"); + //array.append ("aaa"); + //array.append ("bbb"); + + print_list (array); + + stdout.puts ("--------\n"); + + array.sort ((a, b) => { + stdout.printf ("a.first=%lu\n", a.first); + if (a.first < b.first) return -1; + if (a.first > b.first) return 1; + return 0; + }); + + stdout.puts ("--------\n"); + + print_list (array); +} diff --git a/vala/gobj_style_construction/main.vala b/vala/gobj_style_construction/main.vala new file mode 100644 index 0000000..093bf75 --- /dev/null +++ b/vala/gobj_style_construction/main.vala @@ -0,0 +1,25 @@ +public class Person : Object { + /* Construction properties */ + public string name { get; construct; } + public int age { get; construct set; } + + public Person(string name) { + Object(name: name); + } + + public Person.with_age(string name, int years) { + Object(name: name, age:years); + } + + construct { + // do anything else + stdout.printf("Welcome %s\n", this.name); + } +} + +void main () { + var a = new Person("Kolan"), + b = new Person.with_age("Volodia", 30); + + var c = Object.new (a.get_type(), "name", "Unnamed"); +}