[libgda/libgda-vala] Set Version to 0.2. Added DataModelIterable. Fixes on DataModelIterator and Unit Tests.
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/libgda-vala] Set Version to 0.2. Added DataModelIterable. Fixes on DataModelIterator and Unit Tests.
- Date: Tue, 6 Dec 2011 17:32:02 +0000 (UTC)
commit 0e2aaea8468956f5488dfab285f3add41bca4c9e
Author: Daniel Espinosa <despinosa src gnome org>
Date: Tue Dec 6 10:28:58 2011 -0600
Set Version to 0.2. Added DataModelIterable. Fixes on DataModelIterator and Unit Tests.
* New DataModelIterable in order to use foreach and get Gee.Iterator
* Fixes on DataModelIterator
* Moved libgda/data/libgdadata.h to just libgdadata.h to help in parallel installations of future versions
* libgdadata set version to 0.2
* Fixes on SelectQuery base class to GLib.Object
* Fexed Makefile.am for unit tests
libgda/data/DataModelIterator.vala | 86 ++++++++++++++++++++++++++++++-----
libgda/data/DataObject.vala | 2 +-
libgda/data/Makefile.am | 3 +-
libgda/data/SelectQuery.vala | 2 +-
tests/vala/Makefile.am | 41 +++++++++++++++--
5 files changed, 113 insertions(+), 21 deletions(-)
---
diff --git a/libgda/data/DataModelIterator.vala b/libgda/data/DataModelIterator.vala
index 077e28d..858fb2c 100644
--- a/libgda/data/DataModelIterator.vala
+++ b/libgda/data/DataModelIterator.vala
@@ -22,10 +22,60 @@
namespace GdaData {
+ public class DataModelIterable : GLib.Object, Gee.Traversable <Value?>, Gee.Iterable <Value?>
+ {
+ private Gda.DataModel model;
+
+ public DataModelIterable (Gda.DataModel model) {
+ this.model = model;
+ }
+
+ // Iterable Interface
+
+ public Type element_type {
+ get { return typeof (GLib.Value); }
+ }
+
+ public Iterator<Value?> iterator ()
+ {
+ return new DataModelIterator (this.model);
+ }
+
+ // Traversable Interface
+
+ public Gee.Iterator<Value?> chop (int offset, int length = -1)
+ {
+ var iter = new DataModelIterator (this.model);
+ return iter.chop (offset, length);
+ }
+
+ public Gee.Iterator<Value?> filter (owned Gee.Predicate<Value?> f)
+ {
+ var iter = new DataModelIterator (this.model);
+ return iter.filter (f);
+ }
+
+ public new void @foreach (Gee.ForallFunc<Value?> f)
+ {
+ for (int i = 0; i < this.model.get_n_rows (); i++) {
+ for (int j = 0; j < this.model.get_n_columns (); j++) {
+ Value v = this.model.get_value_at (i, j);
+ f(v);
+ }
+ }
+ }
+
+ public Gee.Iterator<Value?> stream<Value> (owned Gee.StreamFunc<Value?,Value?> f)
+ {
+ var iter = new DataModelIterator (this.model);
+ return iter.stream<Value> (f);
+ }
+ }
+
/**
* Iterator that implements [ link [Gee.Iterator] and [ link [Gee.Traversable]]
*/
- class DataModelIterator : Object, Gee.Iterator <Value>, Gee.Traversable < Value >
+ public class DataModelIterator : GLib.Object, Gee.Traversable <Value?>, Gee.Iterator <Value?>
{
private Gda.DataModelIter iter;
private int _current_pos;
@@ -36,10 +86,14 @@
private bool filtered;
- public int current_col {
+ public int current_column {
get { return this._current_pos - this.iter.get_row () * this.iter.data_model.get_n_columns (); }
}
+ public int current_row {
+ get { return this.iter.get_row (); }
+ }
+
public DataModelIterator (Gda.DataModel model)
{
this.iter = model.create_iter ();
@@ -58,10 +112,11 @@
if (maxpos > (model.get_n_columns () * model.get_n_rows () - 1))
this.iter.invalidate_contents ();
- this._current_pos = i;
+ this._current_pos = -1;
this.pos_init = i;
this.maxpos = maxpos;
this.filtered = false;
+ this.move_to_row (this.pos_init / this.iter.data_model.get_n_columns ());
}
private DataModelIterator.filtered_elements (Gda.DataModel model, Gee.HashMap <int, int> elements)
@@ -74,6 +129,8 @@
this.elements = elements;
}
+ // Iterator Interface
+
public bool valid
{
get { return this.iter.is_valid (); }
@@ -84,7 +141,10 @@
public bool next () {
if (!this.filtered)
{
- this._current_pos++;
+ if (this._current_pos == -1)
+ this._current_pos = this.pos_init;
+ else
+ this._current_pos++;
if (this._current_pos > this.maxpos) {
this.iter.invalidate_contents ();
return false;
@@ -121,7 +181,7 @@
* ''Implementation:'' Gda.DataModel have read only GLib.Value no modification is allowed.
* This function returns a copy of the Value stored in the DataModel.
*/
- public Value @get ()
+ public Value? @get ()
{
return this.iter.get_value_at (this._current_pos -
this.iter.get_row () *
@@ -130,18 +190,18 @@
public void remove () {}
- /* Traversable */
+ /* Traversable Interface */
public Gee.Iterator<Value?> chop (int offset, int length = -1)
requires ( offset >= 0)
{
- int elements = this.iter.data_model.get_n_columns () * this.iter.data_model.get_n_rows ();
- int maxpos = elements;
+ int maxpos = this.maxpos;
+ int pos_init = this.pos_init + offset;
if (length > -1) {
- maxpos = offset + length;
- if (maxpos > elements)
- maxpos = elements;
+ maxpos = this.pos_init + offset + length;
+ if (maxpos > this.maxpos)
+ maxpos = this.maxpos;
}
- return new DataModelIterator.with_offset (this.iter.data_model, offset, maxpos);
+ return new DataModelIterator.with_offset (this.iter.data_model, pos_init, maxpos);
}
public Gee.Iterator<Value?> filter (owned Gee.Predicate<Value?> f)
@@ -159,7 +219,7 @@
public new void @foreach (Gee.ForallFunc<Value?> f)
{
- for (int i = 0; i < this.maxpos; i++) {
+ for (int i = this.pos_init; i < this.maxpos; i++) {
int row = i / this.iter.data_model.get_n_columns ();
int col = i - row * this.iter.data_model.get_n_columns ();
Value v = this.iter.data_model.get_value_at (row, col);
diff --git a/libgda/data/DataObject.vala b/libgda/data/DataObject.vala
index f8d03dc..81133b5 100644
--- a/libgda/data/DataObject.vala
+++ b/libgda/data/DataObject.vala
@@ -19,7 +19,7 @@
using Gda;
-[CCode (cheader_filename="libgda/data/libgdadata.h")]
+[CCode (cheader_filename="libgdadata.h")]
namespace GdaData {
public abstract class Object : GLib.Object {
diff --git a/libgda/data/Makefile.am b/libgda/data/Makefile.am
index aacbb40..9eedb53 100644
--- a/libgda/data/Makefile.am
+++ b/libgda/data/Makefile.am
@@ -13,6 +13,7 @@ AM_CFLAGS =\
-g \
-I$(top_srcdir) -I$(srcdir)/.. \
-I$(top_builddir) \
+ -I$(top_builddir)/libgda/data \
$(COREDEPS_CFLAGS) \
$(LIBGDA_WFLAGDS) \
$(LIBGDA_CFLAGS) \
@@ -59,7 +60,7 @@ include_HEADERS = \
libgdadata.h \
$(NULL)
-gdadataincludedir = $(includedir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)/libgda/data
+gdadataincludedir = $(includedir)/libgdadata-0.2/
gdadatainclude_HEADERS = libgdadata.h
pkgconfigdir = $(libdir)/pkgconfig
diff --git a/libgda/data/SelectQuery.vala b/libgda/data/SelectQuery.vala
index d7fdd3c..ef5d38d 100644
--- a/libgda/data/SelectQuery.vala
+++ b/libgda/data/SelectQuery.vala
@@ -21,7 +21,7 @@ using Gda;
namespace GdaData {
- private class SelectQuery : Object {
+ private class SelectQuery : GLib.Object {
private Gee.ArrayList<string> _fields;
private SqlBuilder _sql;
diff --git a/tests/vala/Makefile.am b/tests/vala/Makefile.am
index 68a999a..ed1cf9b 100644
--- a/tests/vala/Makefile.am
+++ b/tests/vala/Makefile.am
@@ -7,14 +7,22 @@ AM_CPPFLAGS = \
$(COREDEPS_CFLAGS) \
$(COREDEPS_WFLAGS) \
$(JSON_GLIB_CFLAGS) \
+ $(GEE_CFLAGS) \
-DROOT_DIR=\""$(top_srcdir)"\"
TESTS_ENVIRONMENT =
-TESTS = check_dataobject
-check_PROGRAMS = check_dataobject
+TESTS = check_dataobject check_datamodeliterator
+check_PROGRAMS = check_dataobject check_datamodeliterator
-BUILT_SOURCES = check_dataobject.vala.stamp
-CLEANFILES = check_dataobject.vala.stamp
+BUILT_SOURCES = \
+ check_dataobject.vala.stamp \
+ check_datamodeliterator.vala.stamp \
+ $(NULL)
+
+CLEANFILES = \
+ check_dataobject.vala.stamp \
+ check_datamodeliterator.vala.stamp \
+ $(NULL)
VALAFLAGS = \
--pkg gee-0.8 \
@@ -31,20 +39,43 @@ check_dataobject_VALASOURCES = \
CheckDataObject.vala \
$(NULL)
+check_datamodeliterator_VALASOURCES = \
+ CheckDataModelIterator.vala \
+ $(NULL)
+
check_dataobject.vala.stamp: $(check_dataobject_VALASOURCES)
$(VALA_COMPILER) $(VALAFLAGS) -C -H check_dataobject.h $^
@touch $@
+check_datamodeliterator.vala.stamp: $(check_datamodeliterator_VALASOURCES)
+ $(VALA_COMPILER) $(VALAFLAGS) -C -H check_datamodeliterator.h $^
+ @touch $@
+
check_dataobject_SOURCES = $(check_dataobject_VALASOURCES:.vala=.c) check_dataobject.h
+check_dataobject_CFLAGS= \
+ -I$(top_builddir)/libgda/data \
+ $(NULL)
check_dataobject_LDADD = \
$(top_builddir)/libgda/libgda-5.0.la \
- $(top_builddir)/libgda/data/libgdadata-1.0.la \
+ $(top_builddir)/libgda/data/libgdadata-0.2.la \
+ $(COREDEPS_LIBS)
+
+check_datamodeliterator_SOURCES = $(check_datamodeliterator_VALASOURCES:.vala=.c) check_datamodeliterator.h
+check_datamodeliterator_CFLAGS= \
+ -I$(top_builddir)/libgda/data \
+ $(NULL)
+check_datamodeliterator_LDADD = \
+ $(top_builddir)/libgda/libgda-5.0.la \
+ $(top_builddir)/libgda/data/libgdadata-0.2.la \
$(COREDEPS_LIBS)
CLEANFILES += \
$(check_dataobject_VALASOURCES:.vala=.c) \
check_dataobject.h \
+ $(check_datamodeliterator_VALASOURCES:.vala=.c) \
+ check_datamodeliterator.h \
dataobject.db \
+ datamodeliterator.db \
$(NULL)
EXTRA_DIST =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]