[cluttermm] templated Interval methods to avoid the need for Glib::Values in application code.



commit 88cdfea40d0e03a18ffcda6603e5128985952f82
Author: Ian Martin <martin_id vodafone co nz>
Date:   Fri Mar 28 10:04:11 2014 +1300

    templated Interval methods to avoid the need for Glib::Values in application code.

 clutter/src/interval.ccg |    9 ++---
 clutter/src/interval.hg  |   81 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 81 insertions(+), 9 deletions(-)
---
diff --git a/clutter/src/interval.ccg b/clutter/src/interval.ccg
index 21f0e6a..c3df9db 100644
--- a/clutter/src/interval.ccg
+++ b/clutter/src/interval.ccg
@@ -32,15 +32,14 @@ Interval::Interval(GType type, const Glib::ValueBase& initial, const Glib::Value
 
 void Interval::set_interval(const Glib::ValueBase& initial, const Glib::ValueBase& final)
 {
-  set_initial_value(initial);
-  set_final_value(final);
+  set_initial_glib_value(initial);
+  set_final_glib_value(final);
 }
 
 void Interval::get_interval(Glib::ValueBase& initial, Glib::ValueBase& final)
 {
-  get_initial_value(initial);
-  get_final_value(final);
+  get_initial_glib_value(initial);
+  get_final_glib_value(final);
 }
 
 } //namespace Clutter
-
diff --git a/clutter/src/interval.hg b/clutter/src/interval.hg
index ba552aa..33aca9a 100644
--- a/clutter/src/interval.hg
+++ b/clutter/src/interval.hg
@@ -41,11 +41,44 @@ public:
 
   _WRAP_METHOD(Glib::RefPtr<Interval> clone() const, clutter_interval_clone)
   _WRAP_METHOD(GType get_value_type() const, clutter_interval_get_value_type)
-  _WRAP_METHOD(void set_initial_value(const Glib::ValueBase& value), clutter_interval_set_initial_value)
-  _WRAP_METHOD(void get_initial_value(Glib::ValueBase& value) const, clutter_interval_get_initial_value)
+  _WRAP_METHOD(void set_initial_glib_value(const Glib::ValueBase& value), clutter_interval_set_initial_value)
+  /**
+  * Sets the initial value.
+  *
+  * @param value the value to set to.
+  */
+  template <typename ValueType>
+  void set_initial_value(const ValueType& value);
+
+  _WRAP_METHOD(void get_initial_glib_value(Glib::ValueBase& value) const, clutter_interval_get_initial_value)
+  /**
+  * Retrieves the final value.
+  *
+  * @param value a location to return the value in.
+  */
+  template <typename ValueType>
+  void get_initial_value(ValueType& value) const;
+
+  //TODO: Does this have any use?
   _WRAP_METHOD(GValue* peek_initial_value(), clutter_interval_peek_initial_value)
-  _WRAP_METHOD(void set_final_value(const Glib::ValueBase& value), clutter_interval_set_final_value)
-  _WRAP_METHOD(void get_final_value(Glib::ValueBase& value) const, clutter_interval_get_final_value)
+  _WRAP_METHOD(void set_final_glib_value(const Glib::ValueBase& value), clutter_interval_set_final_value)
+  /**
+  * Sets the final value.
+  *
+  * @param value the value to set to.
+  */
+  template <typename ValueType>
+  void set_final_value(const ValueType& value);
+
+  _WRAP_METHOD(void get_final_glib_value(Glib::ValueBase& value) const, clutter_interval_get_final_value)
+  /**
+  * Retrieves the final value.
+  *
+  * @param value a location to return the value in.
+  */
+  template <typename ValueType>
+  void get_final_value(ValueType& value) const;
+  //TODO: Does this have any use?
   _WRAP_METHOD(GValue* peek_final_value(), clutter_interval_peek_final_value)
 
   void set_interval(const Glib::ValueBase& initial, const Glib::ValueBase& final);
@@ -76,5 +109,45 @@ Glib::RefPtr<Interval> Interval::create_with_values(const Glib::Value<ValueType>
 {
   return Glib::RefPtr<Interval>( new Interval(initial.value_type(), initial, final) );
 }
+
+template <typename ValueType>
+void Interval::set_initial_value(const ValueType& value)
+{
+  Glib::Value<ValueType> initial_val;
+  //Create the GType based on what type the Interval holds:
+  initial_val.init(get_value_type());
+  initial_val.set(value);
+  set_initial_glib_value(initial_val);
+}
+
+template <typename ValueType>
+void Interval::get_initial_value(ValueType& value) const
+{
+  Glib::Value<ValueType> initial_val;
+  initial_val.init(get_value_type());
+  get_initial_glib_value(initial_val);
+
+  value = initial_val.get();
+}
+
+template <typename ValueType>
+void Interval::set_final_value(const ValueType& value)
+{
+  Glib::Value<ValueType> final_val;
+  final_val.init(get_value_type());
+  final_val.set(value);
+  set_final_glib_value(final_val);
+}
+
+template <typename ValueType>
+void Interval::get_final_value(ValueType& value) const
+{
+  Glib::Value<ValueType> final_val;
+  final_val.init(get_value_type());
+  get_final_glib_value(final_val);
+
+  value = final_val.get();
+}
+
 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
 } // namespace Clutter


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