Permalink
Browse files

modified: CMakeLists.txt

	modified:   commands.vala
	modified:   expressions.vala
	modified:   test.vala
  • Loading branch information...
1 parent 58fb259 commit 90044f6241afee093fe836f140fb7f8f4135aa27 iloveaok committed May 1, 2012
Showing with 105 additions and 34 deletions.
  1. +2 −1 CMakeLists.txt
  2. +51 −9 commands.vala
  3. +10 −23 expressions.vala
  4. +42 −1 test.vala
View
@@ -42,7 +42,8 @@ link_directories(${LIB_PATHS})
set(VALA_SRC
expressions.vala
- commands.vala#test.gs#commands.gs
+ commands.vala
+ #test.vala
)
vala_precompile(VALA_C
View
@@ -5,17 +5,17 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
*/
using Gee;
-using Gda;
+//using Gda;
class Database : Object {
- public ArrayList<Model> models;
- public Model user_model;
+ //public ArrayList<Model> models;
+ //public Model user_model;
}
class Column : Operand {
public string _name;
construct {
- _name = "";
+ _name = "cn";
}
public Column() {
}
@@ -26,9 +26,9 @@ class Column : Operand {
class Model : Object {
/* every Model object has one Database object associated with it */
- public Database db;
+ //public Database db;
/* access Column names by columns.keys; Column objects by columns.values */
- public ArrayList<Column> columns;
+ //public ArrayList<Column> columns;
}
/* Easy interface to GdaSqlBuilder
@@ -53,15 +53,16 @@ abstract class Command : Object {
values_where = new ValueArray(0);
values_having = new ValueArray(0);
}
- public void values_v(ValueArray vals) {
+ /*public void values_v(ValueArray vals) {
free(values_commit); // gets replaced!
values_commit = vals.copy();
- }
+ }*/
/** returns all values related to this command depending on it's type */
public abstract ValueArray get_values();
}
class Insert : Command {
+ // http://www.swig.org/Doc1.3/Varargs.html
// [GIR (name = "foo")]
public Insert(ArrayList<Column> into_columns) {
relevant_columns = into_columns;
@@ -92,8 +93,16 @@ class Delete : Command {
}
class Select : Command {
- public Select(ArrayList<Column> columns) {
+ /*public Select(ArrayList<Column> columns) {
relevant_columns = columns;
+ }*/
+ public Select(Column c1, ...) {
+ /*var l = va_list();
+ while (true) {
+ Column? cx = l.arg();
+ if (cx == null) break; // end of varargs
+ //print(cx._name);
+ };*/
}
public override ValueArray get_values() {
// values_commit + values_having # ensure the right order
@@ -104,6 +113,39 @@ class Select : Command {
}
}
+/*
+select().from(MyModel).where(
+ MyModel.age.equals(50).and(
+ MyModel.fullname.like("%huber")
+ ).or(
+ MyModel.pk.equals(1)
+ )
+)*/
+
+class Adress : Model {
+ public static Column street { get; set; }
+ public static Column housenr { get; set; }
+ construct {
+ street = new Column();
+ housenr = new Column();
+ }
+}
+
+class DatabaseInstance : Database {
+ construct {
+ }
+}
+
int main () {
+ test_expressions();
+ var x = new Adress();
+ var s = new Select(x.street);
+ print("%s\n", Adress.street._name);
+ s.get_values();
+ // https://live.gnome.org/Vala/ValaForCSharpProgrammers#Reflection
+ var obj_class = (ObjectClass) typeof(Adress).class_ref();
+ var properties = obj_class.list_properties();
+ foreach(var prop in properties)
+ print("col: %s nick: %s\n", prop.name, prop.get_nick());
return 0;
}
View
@@ -13,7 +13,7 @@ abstract class Operand : Object {
return new Expression(ExprOperator.OR, this, right);
}
public Expression equals(Value right) {
- return new Expression(ExprOperator.OR, this, right);
+ return new Expression(ExprOperator.EQ, this, right);
}
}
@@ -80,8 +80,8 @@ public enum ExprOperator {
}
errordomain InvalidExpression {
- NONEXISTANT_OPERATOR,
- FOO
+ NONEXISTANT_OPERATOR,
+ FOO
}
// this function primarily exists for debugging, usually libgda will be used
@@ -124,34 +124,21 @@ string _operator_to_str(ExprOperator o) throws InvalidExpression {
}
/*
-select().from(MyModel).where(
- MyModel.age.equals(50).and(
- MyModel.fullname.like("%huber")
- ).or(
- MyModel.pk.equals(1)
- )
-)
=> Operate on Column objects instead of strings containing their names
=> Accept Value, Column, Expression objects as Operands
=> https://live.gnome.org/Vala/ValueSample
plan: dependency on libgda only if relational backend is used, native impl. shouldn't need to have libgda
read https://live.gnome.org/Vala/Tutorial#Methods_With_Syntax_Support
read http://developer.gimp.org/api/2.0/app/app-config-interface.html
-class Column : Operand {
- public override string to_string() {
- return "Hallo";
- }
-}
-int main () {
+read https://github.com/antono/vala-object
+*/
+
+void test_expressions() {
var x = new Column();
var y = new Column();
var z = x.and(y);
- var a = new Expression(ExprOperator.EQ, "as", "yahoo");
- var b = new Expression(ExprOperator.EQ, a, z);
- //Value v = b;
- //print("%s\n", v.type().name());
- if(a is Expression)
+ var a = new Expression(ExprOperator.GT, "as", "yahoo");
+ var b = a.equals(z).or(a);
+ if(x is Operand)
print("%s\n", b.to_string());
- return 0;
}
-*/
View
@@ -1,4 +1,4 @@
-using Gee;
+/*using Gee;
class Test : Object {
public HashMap<string, string> d;
@@ -35,3 +35,44 @@ void main () {
foreach (var entry in tt.d.entries)
stdout.printf ("%s => %s\n", entry.key, entry.value);
}
+*/
+class Foo : Object {
+ public int hello { get; set; }
+ public int world { get; set; }
+ public int foo_bar { get; set; }
+
+ public signal void action ();
+ public signal void more_action ();
+}
+
+enum Bar {
+ FEE, FIE, FOE, FUM
+}
+
+void main () {
+
+ /* Getting type information */
+ Type type = typeof (Foo);
+ stdout.printf ("%s\n", type.name ());
+
+ /* Instantiation from type */
+ Foo foo = (Foo) Object.new (type);
+
+ /* list properties of a class */
+ var obj_class = (ObjectClass) typeof (Foo).class_ref ();
+ var properties = obj_class.list_properties ();
+ foreach (var prop in properties) {
+ stdout.printf ("%s\n", prop.name);
+ }
+
+ /* enum value as string */
+ var enum_class = (EnumClass) typeof (Bar).class_ref ();
+ string name = enum_class.get_value (Bar.FEE).value_name;
+ stdout.printf ("Enum value as string: %s\n", name);
+
+ /* list signals of a class */
+ uint[] ids = Signal.list_ids (typeof (Foo));
+ foreach (uint id in ids) {
+ stdout.printf ("%s\n", Signal.name (id));
+ }
+}

0 comments on commit 90044f6

Please sign in to comment.