[glibmm/wip/dboles/Binding-master: 2/4] Binding: Move SlotTypeTransform up and document it



commit 4ed3ff9cad836dc7b24282a112d66847292a9baa
Author: Daniel Boles <dboles src gmail com>
Date:   Sat Nov 9 13:26:19 2019 +0000

    Binding: Move SlotTypeTransform up and document it
    
    This is more maintainable than all the arguments to all the overloads of
    bind_property() manually repeating the signature in their documentation,
    plus more user-friendly as we document it, users can use the typedef, &c
    
    Note: My next thought was we can just take SlotTypeTransforms in the
    argument list, instead of totally arbitrary functors, so the conversion
    would be done at call site instead of via extra code in the body. But I
    didn't get that working yet, and it should be a separate commit anyway.

 glib/src/binding.hg | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)
---
diff --git a/glib/src/binding.hg b/glib/src/binding.hg
index ca20d939..840b0b62 100644
--- a/glib/src/binding.hg
+++ b/glib/src/binding.hg
@@ -114,6 +114,19 @@ public:
    */
   using SlotTransform = sigc::slot<bool(const GValue*, GValue*)>;
 
+  /** A slot to be called to transform values in a binding created by
+   * bind_property().
+   *
+   * For instance:
+   * @code
+   *   bool on_transform_to(const Glib::ustring& from_string, int& to_int);
+   * @endcode
+   *
+   * @return <tt>true</tt> if the transformation was successful, and <tt>false</tt> otherwise.
+   */
+  template <typename T_from, typename T_to>
+  using SlotTypedTransform = sigc::slot<bool(const T_from&, T_to&>);
+
   /** Creates a binding between @a source_property and @a target_property,
    * allowing you to set the transformation functions to be used by the binding.
    *
@@ -188,8 +201,7 @@ public:
    * @tparam T_target Type of the target property. Must be a type that can be
    *         stored in a Glib::Value<T_target> object.
    * @tparam T_functor_to Type of functor that translates from the source to the target.
-   *         Must be convertible to<br>
-   *         sigc::slot<bool(const T_source&, T_target&)>.
+   *         Must be convertible to SlotTypedTransform<T_source, T_target>.
    *
    * @see bind_property_value()
    *
@@ -202,7 +214,7 @@ public:
     Flags flags,
     const T_functor_to& transform_to)
   {
-    sigc::slot<bool(const T_source&, T_target&)> slot_transform_to = transform_to;
+    SlotTypedTransform<T_source, T_target> slot_transform_to = transform_to;
 
     return bind_property_value(source_property, target_property, flags,
       slot_transform_to.empty() ? SlotTransform() : TransformProp<T_source, T_target>(slot_transform_to));
@@ -224,8 +236,7 @@ public:
    * @tparam T_target Type of the target property. Must be a type that can be
    *         stored in a Glib::Value<T_target> object.
    * @tparam T_functor_to Type of functor that translates from the source to the target.
-   *         Must be convertible to<br>
-   *         sigc::slot<bool(const T_source&, T_target&)>.
+   *         Must be convertible to SlotTypedTransform<T_source, T_target>.
    *
    * @see bind_property_value()
    *
@@ -238,7 +249,7 @@ public:
     Flags flags,
     const T_functor_to& transform_to)
   {
-    sigc::slot<bool(const T_source&, T_target&)> slot_transform_to = transform_to;
+    SlotTypedTransform<T_source, T_target> slot_transform_to = transform_to;
 
     return bind_property_value(source_property, target_property, flags,
       slot_transform_to.empty() ? SlotTransform() : TransformProp<T_source, T_target>(slot_transform_to));
@@ -260,8 +271,7 @@ public:
    * @tparam T_target Type of the target property. Must be a type that can be
    *         stored in a Glib::Value<T_target> object.
    * @tparam T_functor_to Type of functor that translates from the source to the target.
-   *         Must be convertible to<br>
-   *         sigc::slot<bool(const T_source&, T_target&)>.
+   *         Must be convertible to SlotTypedTransform<T_source, T_target>.
    *
    * @see bind_property_value()
    *
@@ -274,7 +284,7 @@ public:
     Flags flags,
     const T_functor_to& transform_to)
   {
-    sigc::slot<bool(const T_source&, T_target&)> slot_transform_to = transform_to;
+    SlotTypedTransform<T_source, T_target> slot_transform_to = transform_to;
 
     return bind_property_value(source_property, target_property, flags,
       slot_transform_to.empty() ? SlotTransform() : TransformProp<T_source, T_target>(slot_transform_to));
@@ -296,8 +306,7 @@ public:
    * @tparam T_target Type of the target property. Must be a type that can be
    *         stored in a Glib::Value<T_target> object.
    * @tparam T_functor_to Type of functor that translates from the source to the target.
-   *         Must be convertible to<br>
-   *         sigc::slot<bool(const T_source&, T_target&)>.
+   *         Must be convertible to SlotTypedTransform<T_source, T_target>.
    *
    * @see bind_property_value()
    *
@@ -310,7 +319,7 @@ public:
     Flags flags,
     const T_functor_to& transform_to)
   {
-    sigc::slot<bool(const T_source&, T_target&)> slot_transform_to = transform_to;
+    SlotTypedTransform<T_source, T_target> slot_transform_to = transform_to;
 
     return bind_property_value(source_property, target_property, flags,
       slot_transform_to.empty() ? SlotTransform() : TransformProp<T_source, T_target>(slot_transform_to));
@@ -334,11 +343,9 @@ public:
    * @tparam T_target Type of the target property. Must be a type that can be
    *         stored in a Glib::Value<T_target> object.
    * @tparam T_functor_to Type of functor that translates from the source to the target.
-   *         Must be convertible to<br>
-   *         sigc::slot<bool(const T_source&, T_target&)>.
+   *         Must be convertible to SlotTypedTransform<T_source, T_target>.
    * @tparam T_functor_from Type of functor that translates from the target to the source.
-   *         Must be convertible to<br>
-   *         sigc::slot<bool(const T_target&, T_source&)>.
+   *         Must be convertible to SlotTypedTransform<T_target, T_source>.
    *
    * @see bind_property_value()
    *
@@ -352,8 +359,8 @@ public:
     const T_functor_to& transform_to,
     const T_functor_from& transform_from)
   {
-    sigc::slot<bool(const T_source&, T_target&)> slot_transform_to = transform_to;
-    sigc::slot<bool(const T_target&, T_source&)> slot_transform_from = transform_from;
+    SlotTypedTransform<T_source, T_target> slot_transform_from = transform_from;
+    SlotTypedTransform<T_target, T_source> slot_transform_to = transform_to;
 
     return bind_property_value(source_property, target_property, flags,
       slot_transform_to.empty() ? SlotTransform() : TransformProp<T_source, T_target>(slot_transform_to),
@@ -400,9 +407,7 @@ private:
   class TransformProp
   {
   public:
-    using SlotTypedTransform = sigc::slot<bool(const T_from&, T_to&)>;
-
-    explicit TransformProp(const SlotTypedTransform& slot) : typed_transform(slot) {}
+    explicit TransformProp(const SlotTypedTransform<T_from, T_to>& slot) : typed_transform(slot) {}
 
     bool operator()(const GValue* from_value, GValue* to_value)
     {
@@ -419,7 +424,7 @@ private:
     }
 
   private:
-    SlotTypedTransform typed_transform;
+    SlotTypedTransform<T_from, T_to> typed_transform;
   };
 };
 


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