GObject Style Construction...

This commit is contained in:
Kolan Sh 2015-08-10 20:24:16 +03:00
parent 7d5300f6dc
commit 3f3c1b1d59
2 changed files with 80 additions and 0 deletions

View File

@ -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<SplitLimit?> 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?> ();
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);
}

View File

@ -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");
}