]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Migrated ZakFormElementFilter from interface to abstract class.
authorAndrea Zagli <azagli@libero.it>
Mon, 2 Nov 2015 21:08:13 +0000 (22:08 +0100)
committerAndrea Zagli <azagli@libero.it>
Mon, 2 Nov 2015 21:08:13 +0000 (22:08 +0100)
12 files changed:
src/Makefile.am
src/formelement.c
src/formelement.h
src/formelementfilter.c [new file with mode: 0644]
src/formelementfilter.h [new file with mode: 0644]
src/formelementfiltertrim.c
src/formelementfiltertrim.h
src/formelementifilter.c [deleted file]
src/formelementifilter.h [deleted file]
src/formelementvalidatornotempty.c
src/formelementvalidatorregex.c
src/libzakform.h

index fc8f1c1c2fa75026fd2975df7b50c2d53ec3c78f..d300a591d8f6a716b0ab73685cd2c67a2172d9c7 100644 (file)
@@ -8,7 +8,7 @@ lib_LTLIBRARIES = libzakform.la
 libzakform_la_SOURCES = \
                         form.c \
                         formelement.c \
-                        formelementifilter.c \
+                        formelementfilter.c \
                         formelementfiltertrim.c \
                         formelementvalidator.c \
                         formelementvalidatornotempty.c \
@@ -20,7 +20,7 @@ libzakform_include_HEADERS = \
                              libzakform.h \
                              form.h \
                              formelement.h \
-                             formelementifilter.h \
+                             formelementfilter.h \
                              formelementfiltertrim.h \
                              formelementvalidator.h \
                              formelementvalidatornotempty.h \
index 93d6e82320e47d3b05cbc30f86b20cc446d898af..98f2909f5c07cdb48fb95795bd23f762502e574b 100644 (file)
@@ -105,7 +105,7 @@ zak_form_element_init (ZakFormElement *zak_form_element)
  *
  */
 void
-zak_form_element_add_filter (ZakFormElement *element, ZakFormElementIFilter *filter)
+zak_form_element_add_filter (ZakFormElement *element, ZakFormElementFilter *filter)
 {
        ZakFormElementPrivate *priv;
 
@@ -145,8 +145,8 @@ zak_form_element_filter (ZakFormElement *element)
 
                        value = zak_form_element_get_value (element);
 
-                       val = zak_form_element_ifilter_filter ((ZakFormElementIFilter *)g_ptr_array_index (priv->pa_filters, i),
-                                                                                                          value);
+                       val = zak_form_element_filter_filter ((ZakFormElementFilter *)g_ptr_array_index (priv->pa_filters, i),
+                                                                                                 value);
                        zak_form_element_set_value (element, val);
                }
 }
index cef647dac6952da9943e1b836e710b01c6338012..4acc22802ed74ea2a5aee91510717d009dd2812b 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <glib-object.h>
 
-#include "formelementifilter.h"
+#include "formelementfilter.h"
 #include "formelementvalidator.h"
 
 
@@ -48,7 +48,7 @@ gchar *zak_form_element_get_default_value (ZakFormElement *element);
 
 void zak_form_element_clear (ZakFormElement *element);
 
-void zak_form_element_add_filter (ZakFormElement *element, ZakFormElementIFilter *filter);
+void zak_form_element_add_filter (ZakFormElement *element, ZakFormElementFilter *filter);
 void zak_form_element_filter (ZakFormElement *element);
 
 void zak_form_element_add_validator (ZakFormElement *element, ZakFormElementValidator *validator);
diff --git a/src/formelementfilter.c b/src/formelementfilter.c
new file mode 100644 (file)
index 0000000..ba30a32
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#endif
+
+#include "formelementfilter.h"
+
+static void zak_form_element_filter_class_init (ZakFormElementFilterClass *class);
+static void zak_form_element_filter_init (ZakFormElementFilter *zak_form_element_filter);
+
+static void zak_form_element_filter_set_property (GObject *object,
+                               guint property_id,
+                               const GValue *value,
+                               GParamSpec *pspec);
+static void zak_form_element_filter_get_property (GObject *object,
+                               guint property_id,
+                               GValue *value,
+                               GParamSpec *pspec);
+
+static void zak_form_element_filter_dispose (GObject *gobject);
+static void zak_form_element_filter_finalize (GObject *gobject);
+
+typedef struct
+       {
+           gpointer nothing;
+       } ZakFormElementFilterPrivate;
+
+G_DEFINE_ABSTRACT_TYPE (ZakFormElementFilter, zak_form_element_filter, G_TYPE_OBJECT)
+
+static void
+zak_form_element_filter_class_init (ZakFormElementFilterClass *class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+       object_class->set_property = zak_form_element_filter_set_property;
+       object_class->get_property = zak_form_element_filter_get_property;
+       object_class->dispose = zak_form_element_filter_dispose;
+       object_class->finalize = zak_form_element_filter_finalize;
+}
+
+static void
+zak_form_element_filter_init (ZakFormElementFilter *zak_form_element_filter)
+{
+       ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
+}
+
+gchar
+*zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value)
+{
+       gchar *ret;
+
+       g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_FILTER (self), g_strdup (""));
+
+       if (ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->filter != NULL)
+               {
+                       ret = ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->filter (self, value);
+               }
+       else
+               {
+                       ret = g_strdup ("");
+               }
+       return ret;
+}
+
+/* PRIVATE */
+static void
+zak_form_element_filter_set_property (GObject *object,
+                   guint property_id,
+                   const GValue *value,
+                   GParamSpec *pspec)
+{
+       ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)object;
+       ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
+
+       switch (property_id)
+               {
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+zak_form_element_filter_get_property (GObject *object,
+                   guint property_id,
+                   GValue *value,
+                   GParamSpec *pspec)
+{
+       ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)object;
+       ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
+
+       switch (property_id)
+               {
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+zak_form_element_filter_dispose (GObject *gobject)
+{
+       ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)gobject;
+       ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->dispose (gobject);
+}
+
+static void
+zak_form_element_filter_finalize (GObject *gobject)
+{
+       ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)gobject;
+       ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->finalize (gobject);
+}
diff --git a/src/formelementfilter.h b/src/formelementfilter.h
new file mode 100644 (file)
index 0000000..cc92929
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __ZAK_FORM_ELEMENT_FILTER_H__
+#define __ZAK_FORM_ELEMENT_FILTER_H__
+
+#include <glib-object.h>
+
+
+G_BEGIN_DECLS
+
+
+#define ZAK_FORM_TYPE_ELEMENT_FILTER zak_form_element_filter_get_type ()
+G_DECLARE_DERIVABLE_TYPE (ZakFormElementFilter, zak_form_element_filter, ZAK_FORM, ELEMENT_FILTER, GObject)
+
+struct _ZakFormElementFilterClass
+{
+       GObjectClass parent_cleass;
+
+       gchar *(*filter) (ZakFormElementFilter *self, const gchar *value);
+};
+
+gchar *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value);
+
+
+G_END_DECLS
+
+
+#endif /* __ZAK_FORM_ELEMENT_FILTER_H__ */
index f4b22bca90c8fb082ea9cf700027621f3e259946..5cb348a29e9d6cc3ad5f0b126850e451f794da49 100644 (file)
        #include <config.h>
 #endif
 
-#include "formelementifilter.h"
+#include "formelementfilter.h"
 #include "formelementfiltertrim.h"
 
 static void zak_form_element_filter_trim_class_init (ZakFormElementFilterTrimClass *class);
-static void zak_form_element_filter_trim_interface_init (ZakFormElementIFilterInterface *iface);
 static void zak_form_element_filter_trim_init (ZakFormElementFilterTrim *zak_form_element);
 
 static void zak_form_element_filter_trim_set_property (GObject *object,
@@ -39,16 +38,16 @@ static void zak_form_element_filter_trim_get_property (GObject *object,
 static void zak_form_element_filter_trim_dispose (GObject *gobject);
 static void zak_form_element_filter_trim_finalize (GObject *gobject);
 
-static gchar *zak_form_element_filter_trim_filter (ZakFormElementIFilter *filter_trim, const gchar *value);
+static gchar *zak_form_element_filter_trim_filter (ZakFormElementFilter *filter_trim, const gchar *value);
 
 struct _ZakFormElementFilterTrim
 {
-       GObject parent_instance;
+       ZakFormElementFilter parent_instance;
 
        /* Other members, including private data. */
 };
 
-#define ZAK_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_TYPE_FORM_ELEMENT_FILTER_TRIM, ZakFormElementFilterTrimPrivate))
+#define ZAK_FORM_ELEMENT_FILTER_TRIM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_TYPE_ELEMENT_FILTER_TRIM, ZakFormElementFilterTrimPrivate))
 
 typedef struct _ZakFormElementFilterTrimPrivate ZakFormElementFilterTrimPrivate;
 struct _ZakFormElementFilterTrimPrivate
@@ -56,27 +55,22 @@ struct _ZakFormElementFilterTrimPrivate
                gpointer nothing;
        };
 
-G_DEFINE_TYPE_WITH_CODE (ZakFormElementFilterTrim, zak_form_element_filter_trim, G_TYPE_OBJECT,
-                                                G_IMPLEMENT_INTERFACE (ZAK_TYPE_FORM_ELEMENT_IFILTER,
-                                                                                               zak_form_element_filter_trim_interface_init))
+G_DEFINE_TYPE (ZakFormElementFilterTrim, zak_form_element_filter_trim, ZAK_FORM_TYPE_ELEMENT_FILTER)
 
 static void
 zak_form_element_filter_trim_class_init (ZakFormElementFilterTrimClass *class)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (class);
+       ZakFormElementFilterClass *parent_class = ZAK_FORM_ELEMENT_FILTER_CLASS (class);
 
        object_class->set_property = zak_form_element_filter_trim_set_property;
        object_class->get_property = zak_form_element_filter_trim_get_property;
        object_class->dispose = zak_form_element_filter_trim_dispose;
        object_class->finalize = zak_form_element_filter_trim_finalize;
 
-       g_type_class_add_private (object_class, sizeof (ZakFormElementFilterTrimPrivate));
-}
+       parent_class->filter = zak_form_element_filter_trim_filter;
 
-static void
-zak_form_element_filter_trim_interface_init (ZakFormElementIFilterInterface *iface)
-{
-       iface->filter = zak_form_element_filter_trim_filter;
+       g_type_class_add_private (object_class, sizeof (ZakFormElementFilterTrimPrivate));
 }
 
 static void
@@ -160,7 +154,7 @@ zak_form_element_filter_trim_finalize (GObject *gobject)
 }
 
 static gchar
-*zak_form_element_filter_trim_filter (ZakFormElementIFilter *filter_trim,
+*zak_form_element_filter_trim_filter (ZakFormElementFilter *filter_trim,
                                                                          const gchar *value)
 {
        gchar *ret;
index cc666fe321933fe4323432131bfddc20326074b7..9d49611954ae75934d0914763ccb1a5d9270d7ab 100644 (file)
 
 #include <glib-object.h>
 
+#include "formelementfilter.h"
+
 
 G_BEGIN_DECLS
 
 
-#define ZAK_TYPE_FORM_ELEMENT_FILTER_TRIM zak_form_element_filter_trim_get_type ()
-G_DECLARE_FINAL_TYPE (ZakFormElementFilterTrim, zak_form_element_filter_trim, ZAK_FORM, ELEMENT_FILTER_TRIM, GObject)
+#define ZAK_FORM_TYPE_ELEMENT_FILTER_TRIM zak_form_element_filter_trim_get_type ()
+G_DECLARE_FINAL_TYPE (ZakFormElementFilterTrim, zak_form_element_filter_trim, ZAK_FORM, ELEMENT_FILTER_TRIM, ZakFormElementFilter)
 
 ZakFormElementFilterTrim *zak_form_element_filter_trim_new (void);
 
diff --git a/src/formelementifilter.c b/src/formelementifilter.c
deleted file mode 100644 (file)
index 22ba445..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "formelementifilter.h"
-
-G_DEFINE_INTERFACE (ZakFormElementIFilter, zak_form_element_ifilter, G_TYPE_OBJECT);
-
-static void
-zak_form_element_ifilter_default_init (ZakFormElementIFilterInterface *iface)
-{
-    /* add properties and signals to the interface here */
-}
-
-gchar
-*zak_form_element_ifilter_filter (ZakFormElementIFilter *self, const gchar *value)
-{
-       g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_IFILTER (self), NULL);
-
-       return ZAK_FORM_ELEMENT_IFILTER_GET_IFACE (self)->filter (self, value);
-}
diff --git a/src/formelementifilter.h b/src/formelementifilter.h
deleted file mode 100644 (file)
index f6ff856..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef __ZAK_FORM_ELEMENT_IFILTER_H__
-#define __ZAK_FORM_ELEMENT_IFILTER_H__
-
-#include <glib-object.h>
-
-
-G_BEGIN_DECLS
-
-
-#define ZAK_TYPE_FORM_ELEMENT_IFILTER zak_form_element_ifilter_get_type ()
-G_DECLARE_INTERFACE (ZakFormElementIFilter, zak_form_element_ifilter, ZAK_FORM, ELEMENT_IFILTER, GObject)
-
-struct _ZakFormElementIFilterInterface
-{
-       GTypeInterface parent_iface;
-
-       gchar *(*filter) (ZakFormElementIFilter *self, const gchar *value);
-};
-
-gchar *zak_form_element_ifilter_filter (ZakFormElementIFilter *self, const gchar *value);
-
-
-G_END_DECLS
-
-
-#endif /* __ZAK_FORM_ELEMENT_IFILTER_H__ */
index ede9aeec82e5b2407cd5a3b34b492e61f914d98a..51ff245f7c1c8feda988017d78fe773b84c5d1d2 100644 (file)
@@ -42,7 +42,7 @@ static gboolean zak_form_element_validator_notempty_validate (ZakFormElementVali
 
 struct _ZakFormElementValidatorNotempty
 {
-       GObject parent_instance;
+       ZakFormElementValidator parent_instance;
 
        /* Other members, including private data. */
 };
index ac9ab17717fddd88a978f079d5c885e2ff513323..a56bf40f3696ccc844dc1e464e01ffdad8b1d10e 100644 (file)
@@ -42,7 +42,7 @@ static gboolean zak_form_element_validator_regex_validate (ZakFormElementValidat
 
 struct _ZakFormElementValidatorRegex
 {
-       GObject parent_instance;
+       ZakFormElementValidator parent_instance;
 
        /* Other members, including private data. */
 };
index 359fac706680f9a63fd0aca8780319ac816e8fbe..b41c41646771d89900d71343b25b735bdf333837 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <libzakform/formelement.h>
 
-#include <libzakform/formelementifilter.h>
+#include <libzakform/formelementfilter.h>
 #include <libzakform/formelementfiltertrim.h>
 
 #include <libzakform/formelementvalidator.h>