[libgdamm] Wrap GdaNumeric as Gnome::Gda::Numeric.



commit 9b594e83ed5f72e02be8ed6650c0bf94a136efc5
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Nov 11 23:16:07 2011 +0100

    Wrap GdaNumeric as Gnome::Gda::Numeric.
    
    * libgda/src/libgda_methods.defs: Regenerated with h2defs.py.
    * libgda/src/numeric.[hg|cc]: Wrap GdaNumeric, now that it is a proper
    boxed type with an API.
    * libgda/libgdamm/value.[h|cc]: Use Numeric instead of GdaNumeric in
    the API.

 ChangeLog                      |   10 +++++
 libgda/libgdamm/value.cc       |   11 +++---
 libgda/libgdamm/value.h        |   12 ++----
 libgda/src/filelist.am         |    1 +
 libgda/src/libgda_methods.defs |   76 ++++++++++++++++++++++++++++++++++++++--
 libgda/src/numeric.ccg         |   30 ++++++++++++++++
 libgda/src/numeric.hg          |   51 +++++++++++++++++++++++++++
 7 files changed, 175 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 59f5bf9..7fabc0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-11-11  Murray Cumming  <murrayc murrayc com>
+
+	Wrap GdaNumeric as Gnome::Gda::Numeric.
+
+	* libgda/src/libgda_methods.defs: Regenerated with h2defs.py.
+	* libgda/src/numeric.[hg|cc]: Wrap GdaNumeric, now that it is a proper
+	boxed type with an API.
+	* libgda/libgdamm/value.[h|cc]: Use Numeric instead of GdaNumeric in 
+	the API.
+
 2011-11-10  Murray Cumming  <murrayc murrayc com>
 
 	Add Connection::create_from_string().
diff --git a/libgda/libgdamm/value.cc b/libgda/libgdamm/value.cc
index 637f42c..826fedc 100644
--- a/libgda/libgdamm/value.cc
+++ b/libgda/libgdamm/value.cc
@@ -98,7 +98,7 @@ Value::Value(int val)
   set(val);
 }
 
-Value::Value(const GdaNumeric* val)
+Value::Value(const Numeric& val)
 {
   set(val);
 }
@@ -378,14 +378,15 @@ void Value::set(int val)
   g_value_set_int(gobj(), val);
 }
 
-const GdaNumeric* Value::get_numeric() const
+Numeric Value::get_numeric() const
 {
-  return gda_value_get_numeric(const_cast<GValue*>(gobj()));
+  const GdaNumeric* cobj = gda_value_get_numeric(const_cast<GValue*>(gobj()));
+  return Glib::wrap(const_cast<GdaNumeric*>(cobj), true /* take_copy */);
 }
 
-void Value::set(const GdaNumeric * val)
+void Value::set(const Numeric& val)
 {
-  gda_value_set_numeric(gobj(), val);
+  gda_value_set_numeric(gobj(), val.gobj());
 }
 
 float Value::get_float() const
diff --git a/libgda/libgdamm/value.h b/libgda/libgdamm/value.h
index ea0a6aa..280e02f 100644
--- a/libgda/libgdamm/value.h
+++ b/libgda/libgdamm/value.h
@@ -25,6 +25,7 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <libgdamm/numeric.h>
 #include <glibmm/value.h>
 #include <glibmm/date.h>
 #include <libgda/gda-value.h> //TODO: Patch libgda to use the struct _ technique.
@@ -80,7 +81,7 @@ public:
 
   explicit Value(int val);
 
-  explicit Value(const GdaNumeric* val);
+  explicit Value(const Numeric& val);
 
   explicit Value(float val);
 
@@ -177,9 +178,9 @@ public:
 
   void set(int val);
 
-  const GdaNumeric* get_numeric() const;
+  Numeric get_numeric() const;
 
-  void set(const GdaNumeric *val);
+  void set(const Numeric& val);
 
   float get_float() const;
 
@@ -283,11 +284,6 @@ typedef struct {
 	double amount;
 } GdaMoney;
 
-typedef struct {
-	gchar *number;
-	long precision;
-	long width;
-} GdaNumeric;
 */
 
 
diff --git a/libgda/src/filelist.am b/libgda/src/filelist.am
index db3875f..4870fe5 100644
--- a/libgda/src/filelist.am
+++ b/libgda/src/filelist.am
@@ -35,6 +35,7 @@ files_hg =			\
 	holder.hg		\
 	metastore.hg		\
 	metastruct.hg		\
+	numeric.hg		\
 	quarklist.hg		\
 	row.hg			\
 	serveroperation.hg	\
diff --git a/libgda/src/libgda_methods.defs b/libgda/src/libgda_methods.defs
index 73140f2..b409333 100644
--- a/libgda/src/libgda_methods.defs
+++ b/libgda/src/libgda_methods.defs
@@ -7270,19 +7270,85 @@
   (return-type "GType")
 )
 
+(define-function gda_numeric_new
+  (c-name "gda_numeric_new")
+  (is-constructor-of "GdaNumeric")
+  (return-type "GdaNumeric*")
+)
+
 (define-function gda_numeric_copy
   (c-name "gda_numeric_copy")
-  (return-type "gpointer")
+  (return-type "GdaNumeric*")
   (parameters
-    '("gpointer" "boxed")
+    '("GdaNumeric*" "src")
+  )
+)
+
+(define-method set_from_string
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_set_from_string")
+  (return-type "none")
+  (parameters
+    '("const-gchar*" "str")
+  )
+)
+
+(define-method set_double
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_set_double")
+  (return-type "none")
+  (parameters
+    '("gdouble" "number")
+  )
+)
+
+(define-method get_double
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_get_double")
+  (return-type "gdouble")
+)
+
+(define-method set_precision
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_set_precision")
+  (return-type "none")
+  (parameters
+    '("glong" "precision")
+  )
+)
+
+(define-method get_precision
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_get_precision")
+  (return-type "glong")
+)
+
+(define-method set_width
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_set_width")
+  (return-type "none")
+  (parameters
+    '("glong" "width")
   )
 )
 
+(define-method get_width
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_get_width")
+  (return-type "glong")
+)
+
+(define-method get_string
+  (of-object "GdaNumeric")
+  (c-name "gda_numeric_get_string")
+  (return-type "gchar*")
+)
+
 (define-function gda_numeric_free
   (c-name "gda_numeric_free")
   (return-type "none")
   (parameters
-    '("gpointer" "boxed")
+    '("GdaNumeric*" "numeric")
   )
 )
 
@@ -8710,3 +8776,7 @@
 )
 
 
+
+;; From libgda-report.h
+
+
diff --git a/libgda/src/numeric.ccg b/libgda/src/numeric.ccg
new file mode 100644
index 0000000..25c628b
--- /dev/null
+++ b/libgda/src/numeric.ccg
@@ -0,0 +1,30 @@
+/* Copyright 2011 libgdamm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <libgdamm/batch.h>
+#include <libgda/gda-batch.h>
+
+
+namespace Gnome
+{
+
+namespace Gda
+{
+
+} /* namespace Gda */
+
+} /* namespace Gnome */
diff --git a/libgda/src/numeric.hg b/libgda/src/numeric.hg
new file mode 100644
index 0000000..27ac432
--- /dev/null
+++ b/libgda/src/numeric.hg
@@ -0,0 +1,51 @@
+/* Copyright 2011 libgdamm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or(at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/ustring.h>
+#include <glibmm/value.h>
+
+_DEFS(libgdamm,libgda)
+
+namespace Gnome
+{
+
+namespace Gda
+{
+
+
+/** TODO
+ */
+class Numeric
+{
+  _CLASS_BOXEDTYPE(Numeric, GdaNumeric, gda_numeric_new, gda_numeric_copy, gda_numeric_free)
+  _IGNORE(gda_numeric_new, gda_numeric_copy, gda_numeric_free)
+public:
+
+  _WRAP_METHOD(void set_from_string(const Glib::ustring& str), gda_numeric_set_from_string)
+  _WRAP_METHOD(void set_double(double number), gda_numeric_set_double)
+  _WRAP_METHOD(double get_double() const, gda_numeric_get_double)
+  _WRAP_METHOD(void set_precision(long precision), gda_numeric_set_precision)
+  _WRAP_METHOD(long get_precision() const, gda_numeric_get_precision)
+  _WRAP_METHOD(void set_width(long width), gda_numeric_set_width)
+  _WRAP_METHOD(long get_width(), gda_numeric_get_width)
+  _WRAP_METHOD(Glib::ustring get_string() const, gda_numeric_get_string)
+};
+
+
+} // namespace Gda
+} // namespace Gnome
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]