gnucash stable: [~qofchoice.cpp] remove, not useful

Christopher Lam clam at code.gnucash.org
Sun Jun 9 13:42:50 EDT 2024


Updated	 via  https://github.com/Gnucash/gnucash/commit/ddc79588 (commit)
	from  https://github.com/Gnucash/gnucash/commit/fbb08c9d (commit)



commit ddc7958801c3c1649e6c420823a8d2584237b8be
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Jun 9 13:17:42 2024 +0800

    [~qofchoice.cpp] remove, not useful
    
    because the options GLists are populated, but are never actually
    queried. The QOF_TYPE_CHOICE definition is moved to qofclass.h

diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index 7fa07271f6..15bd88040d 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -108,7 +108,6 @@ set (engine_HEADERS
   qofbook.h
   qofbook.hpp
   qofbookslots.h
-  qofchoice.h
   qofclass.h
   qofevent.h
   qofid-p.h
@@ -196,7 +195,6 @@ set (engine_SOURCES
   kvp-value.cpp
   qof-backend.cpp
   qofbook.cpp
-  qofchoice.cpp
   qofclass.cpp
   qofevent.cpp
   qofid.cpp
diff --git a/libgnucash/engine/gncAddress.c b/libgnucash/engine/gncAddress.c
index 19c40bee73..27e249f658 100644
--- a/libgnucash/engine/gncAddress.c
+++ b/libgnucash/engine/gncAddress.c
@@ -661,10 +661,6 @@ gboolean gncAddressRegister (void)
     };
 
     qof_class_register (GNC_ID_ADDRESS, (QofSortFunc)gncAddressCompare, params);
-    if (!qof_choice_add_class(GNC_ID_CUSTOMER, GNC_ID_ADDRESS, ADDRESS_OWNER))
-    {
-        return FALSE;
-    }
 
     return qof_object_register(&GncAddressDesc);
 }
diff --git a/libgnucash/engine/gncCustomer.c b/libgnucash/engine/gncCustomer.c
index f089807c57..9786b3dd7a 100644
--- a/libgnucash/engine/gncCustomer.c
+++ b/libgnucash/engine/gncCustomer.c
@@ -951,19 +951,7 @@ gboolean gncCustomerRegister (void)
         { NULL },
     };
 
-    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_CUSTOMER, INVOICE_OWNER))
-    {
-        return FALSE;
-    }
-    if (!qof_choice_add_class(GNC_ID_JOB, GNC_ID_CUSTOMER, JOB_OWNER))
-    {
-        return FALSE;
-    }
     qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncCustomerCompare, params);
-    if (!qof_choice_create(GNC_ID_CUSTOMER))
-    {
-        return FALSE;
-    }
     /* temp */
     _gncCustomerPrintable(NULL);
     return qof_object_register (&gncCustomerDesc);
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index fc5220795d..eb4ab1db8d 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -2308,10 +2308,6 @@ gboolean gncInvoiceRegister (void)
         qofInvoiceSetBillTo (NULL, NULL);
         qofInvoiceGetBillTo (NULL);
     }
-    if (!qof_choice_create (GNC_ID_INVOICE))
-    {
-        return FALSE;
-    }
     return qof_object_register (&gncInvoiceDesc);
 }
 
diff --git a/libgnucash/engine/gncJob.c b/libgnucash/engine/gncJob.c
index 244cc9920c..e1e55a09e4 100644
--- a/libgnucash/engine/gncJob.c
+++ b/libgnucash/engine/gncJob.c
@@ -591,15 +591,6 @@ gboolean gncJobRegister (void)
         { NULL },
     };
 
-    if (!qof_choice_create(GNC_ID_JOB))
-    {
-        return FALSE;
-    }
-    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_JOB, INVOICE_OWNER))
-    {
-        return FALSE;
-    }
-
     qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params);
     qofJobGetOwner(NULL);
     qofJobSetOwner(NULL, NULL);
diff --git a/libgnucash/engine/gncVendor.c b/libgnucash/engine/gncVendor.c
index f4f90f517a..7d0340c707 100644
--- a/libgnucash/engine/gncVendor.c
+++ b/libgnucash/engine/gncVendor.c
@@ -1012,15 +1012,6 @@ gboolean gncVendorRegister (void)
         { NULL },
     };
 
-    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_VENDOR, INVOICE_OWNER))
-    {
-        return FALSE;
-    }
-    if (!qof_choice_add_class(GNC_ID_JOB, GNC_ID_VENDOR, JOB_OWNER))
-    {
-        return FALSE;
-    }
-
     qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncVendorCompare, params);
 
     return qof_object_register (&gncVendorDesc);
diff --git a/libgnucash/engine/qof.h b/libgnucash/engine/qof.h
index 1549a2dd1f..c7dd2d8819 100644
--- a/libgnucash/engine/qof.h
+++ b/libgnucash/engine/qof.h
@@ -85,7 +85,6 @@
 #include "qofquery.h"
 #include "qofquerycore.h"
 #include "qofsession.h"
-#include "qofchoice.h"
 #include "qof-string-cache.h"
 
 #endif /* QOF_H_ */
diff --git a/libgnucash/engine/qofchoice.cpp b/libgnucash/engine/qofchoice.cpp
deleted file mode 100644
index 16a9e4a7a6..0000000000
--- a/libgnucash/engine/qofchoice.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/***************************************************************************
- *            qofchoice.c
- *
- *  Thu Jul  7 12:24:30 2005
- *  Copyright  2005  Neil Williams
- *  linux at codehelp.co.uk
- ****************************************************************************/
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 Library General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <config.h>
-#include <glib.h>
-
-#include "qof.h"
-#include "qofchoice.h"
-
-static QofLogModule log_module = QOF_MOD_CHOICE;
-static GHashTable *qof_choice_table = NULL;
-
-/* To initialise, call qof_choice_add_class in
-qof_object_register for the choice object. */
-static gboolean qof_choice_is_initialized(void)
-{
-    if (!qof_choice_table)
-    {
-        qof_choice_table = g_hash_table_new(g_str_hash, g_str_equal);
-    }
-    if (!qof_choice_table)
-    {
-        return FALSE;
-    }
-    return TRUE;
-}
-
-gboolean qof_object_is_choice(QofIdTypeConst type)
-{
-    gpointer value = NULL;
-
-    if (!qof_choice_is_initialized())
-    {
-        return FALSE;
-    }
-    g_return_val_if_fail(type != NULL, FALSE);
-    value = g_hash_table_lookup(qof_choice_table, type);
-    if ((GHashTable*)value)
-    {
-        return TRUE;
-    }
-    DEBUG (" QOF_TYPE_CHOICE setup failed for %s\n", type);
-    return FALSE;
-}
-
-gboolean
-qof_choice_create(char* type)
-{
-    GHashTable *param_table;
-
-    g_return_val_if_fail(type != NULL, FALSE);
-    g_return_val_if_fail(qof_choice_is_initialized() == TRUE, FALSE);
-    param_table = g_hash_table_new(g_str_hash, g_str_equal);
-    g_hash_table_insert(qof_choice_table, type, param_table);
-    return TRUE;
-}
-
-gboolean qof_choice_add_class(const char* select,
-                              char* option,
-                              char* param_name)
-{
-    GHashTable *param_table;
-    GList *option_list;
-
-    option_list = NULL;
-    param_table = NULL;
-    g_return_val_if_fail(select != NULL, FALSE);
-    g_return_val_if_fail(qof_object_is_choice(select), FALSE);
-    param_table = (GHashTable*)g_hash_table_lookup(qof_choice_table, select);
-    g_return_val_if_fail(param_table, FALSE);
-    option_list = (GList*)g_hash_table_lookup(param_table, param_name);
-    option_list = g_list_append(option_list, option);
-    g_hash_table_insert(param_table, param_name, option_list);
-    return TRUE;
-}
-
-GList* qof_object_get_choices(QofIdType type, QofParam *param)
-{
-    GList *choices;
-    GHashTable *param_table;
-
-    g_return_val_if_fail(type != NULL, NULL);
-    g_return_val_if_fail(qof_choice_is_initialized() == TRUE, FALSE);
-    choices = NULL;
-    param_table = static_cast<GHashTable*>(g_hash_table_lookup(qof_choice_table, type));
-    choices = static_cast<GList*>(g_hash_table_lookup(param_table, param->param_name));
-    return choices;
-}
-
-gboolean qof_choice_check(const char* choice_obj,
-                          const char *param_name,
-                          const char* choice )
-{
-    GList *choices, *result;
-    GHashTable *param_table;
-
-    choices = result = NULL;
-    g_return_val_if_fail(qof_object_is_choice(choice_obj), FALSE);
-    param_table = static_cast<GHashTable*>(g_hash_table_lookup(qof_choice_table, choice_obj));
-    choices = static_cast<GList*>(g_hash_table_lookup(param_table, param_name));
-    result = g_list_find(choices, choice);
-    if (!result)
-    {
-        return FALSE;
-    }
-    return TRUE;
-}
diff --git a/libgnucash/engine/qofchoice.h b/libgnucash/engine/qofchoice.h
deleted file mode 100644
index 283b384c77..0000000000
--- a/libgnucash/engine/qofchoice.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/***************************************************************************
- *            qofchoice.h
- *
- *  Thu Jul  7 12:25:24 2005
- *  Copyright  2005  Neil Williams
- *  linux at codehelp.co.uk
- ****************************************************************************/
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef _QOFCHOICE_H
-#define _QOFCHOICE_H
-
-/** @addtogroup Choice
-
-Objects can be linked together one-to-one by simply using the name of
-the related object as the parameter type in the QofClass parameter list.
-
-\verbatim
-{ FOO_PARAM, BAR_ID, (QofAccessFunc)qofFooGetBar, (QofSetterFunc)qofFooSetBar },
-\endverbatim
-
-This is limited as each FOO entity can contain only one reference to a
-single BAR entity per parameter. Also, this parameter cannot be used to
-link to a similar object, OBJ. This requires "one to many" links.
-
-There are two types of one-to-many links in QOF.
-
--# ::QOF_TYPE_COLLECT - one to many entities all of only one type.
-	- Handles links between one object and a series of objects
-	that are \b all of the same type, e.g. a simple list.
--# ::QOF_TYPE_CHOICE - one to a single entity of many possible types.
-	- Handles links between one object and a series of
-\b dissimilar objects, one of each type.
-
-Currently, there is no explicit way to support many-to-many links
-but existing methods can be combined to give approximately the same results.
-
-A QOF_TYPE_CHOICE object is like a C++ template. QOF_TYPE_CHOICE doesn't
-really exist by itself:
-\verbatim
-QOF_TYPE_CHOICE<QOF_X, QOF_Y, QOF_Z>
-\endverbatim
-It holds a single entity of type X, Y, or Z for the purposes of QOF.
-For querying the object it queries as if it's an X, Y, or Z.
-
-Each choice type has it's own definition of the allowable objects -
-each of which need to be registered as normal. Objects can declare
-themselves to be one option of a particular choice. There is no
-requirement for any object to be either a choice or an option for a
-choice object.
-
--# Each ::QOF_TYPE_CHOICE parameter provides access to \b ONE entity of
-a pre-determined set of object types.
--# The entity type within the choice can be determined at run time.
--# Each entity can have a different *type* of entity to it's siblings,
-provided that it is one of the pre-determined object types.
--# Objects declare themselves as containing choices and other objects
-can add themselves to the list of acceptable choices of suitable objects.
--# QOF_TYPE_CHOICE is transparent - objects should retrieve the e_type of
-the received entity and handle the entity appropriately.
--# The number of different entity types that can be pre-determined for
-any one QOF_TYPE_CHOICE parameter is not fixed. You can have as many
-types as the ::QofAccessFunc and ::QofSetterFunc can handle.
--# Any one parameter can only have one QOF type. You cannot have a parameter
-that is both ::QOF_TYPE_COLLECT and QOF_TYPE_CHOICE any more than you can have
-one parameter that is both ::QOF_TYPE_BOOLEAN and ::QOF_TYPE_NUMERIC.
--# When setting references using QOF_TYPE_CHOICE, QOF passes a single entity
-to the QofSetterFunc and it is left to the function to determine how to
-handle that entity type.  When retrieving references using QOF_TYPE_CHOICE,
-the object must return a single entity matching one of the choice types.
-
- @{
-*/
-
-/** @file qofchoice.h
-	@brief Linking one entity to other entities of many possible types.
-	@author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
-*/
-#include "qofclass.h"
-#include "qofobject.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define QOF_MOD_CHOICE "qof.choice"
-
-/** \note Choice
-@{
-*/
-
-/** \brief Identify an object as containing a choice. */
-#define QOF_TYPE_CHOICE "choice"
-
-/** \brief Does this object contain a choice parameter?
-
-Returns TRUE if any parameter in the object definition
-uses a choice of elements, whether or not those
-parameters contain any data.
-
- at param type Type of object/entity.
-
- at return TRUE if one or more choice parameters has been
-registered using the object definition, otherwise FALSE.
-*/
-gboolean qof_object_is_choice(QofIdTypeConst type);
-
-/** \brief Set an object as using QOF_TYPE_CHOICE. */
-gboolean  qof_choice_create(char* type);
-
-/** \brief Add the choices for this parameter to the object.
-
- at param choice The choice object.
- at param add  The object to be added as an option.
- at param param_name The parameter that will be used to get or set options.
-
- at return FALSE if object is not a choice object or on error
-	otherwise TRUE.
-*/
-gboolean qof_choice_add_class(const char* choice, char* add, char* param_name);
-
-/** \brief Return the list of all object types usable with this parameter.
-
- at param type The choice object type.
- at param param The name of the parameter that will be used to
-	get or set options.
-
- at return NULL on error or if no options exist for this parameter,
-	otherwise a GList of all QofIdType object type(s) available
-	via this choice object using this parameter.
-*/
-GList* qof_object_get_choices(QofIdType type, QofParam *param);
-
-/** \brief Is the choice valid for this param_name?
-
- at param choice_obj The object containing the QOF_TYPE_CHOICE parameter.
- at param param_name The name of a QOF_TYPE_CHOICE parameter in this object.
- at param choice The QofIdType to look for in the list of choices.
-
- at return TRUE if choice is found in the list of allowed choices for
-this parameter of this object. Otherwise, FALSE
-*/
-gboolean qof_choice_check(const char* choice_obj,
-                          const char *param_name,
-                          const char* choice);
-/** @} */
-
-/** @} */
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _QOFCHOICE_H */
diff --git a/libgnucash/engine/qofclass.h b/libgnucash/engine/qofclass.h
index 6ce2832c16..54378068b7 100644
--- a/libgnucash/engine/qofclass.h
+++ b/libgnucash/engine/qofclass.h
@@ -98,6 +98,7 @@ single reference between two known objects.
 #define QOF_TYPE_BOOLEAN   "boolean"
 #define QOF_TYPE_KVP       "kvp"
 #define QOF_TYPE_CHAR      "character"
+#define QOF_TYPE_CHOICE    "choice"     /* was moved from (deleted) qofchoice.h */
 #define QOF_TYPE_COLLECT   "collection" /**< secondary collections
 are used for one-to-many references between entities and are
 implemented using ::QofCollection.
diff --git a/libgnucash/engine/qofobject.h b/libgnucash/engine/qofobject.h
index 919a272737..53338dfe02 100644
--- a/libgnucash/engine/qofobject.h
+++ b/libgnucash/engine/qofobject.h
@@ -50,7 +50,6 @@
 
 #include "qofbook.h"
 #include "qofid.h"
-#include "qofchoice.h"
 
 #ifdef __cplusplus
 extern "C"
diff --git a/libgnucash/engine/qofquery.h b/libgnucash/engine/qofquery.h
index 791315c6ce..959ef26bfa 100644
--- a/libgnucash/engine/qofquery.h
+++ b/libgnucash/engine/qofquery.h
@@ -77,7 +77,6 @@ probably optimize.
 #include "guid.h"
 #include "qofbook.h"
 #include "qofquerycore.h"
-#include "qofchoice.h"
 
 #ifdef __cplusplus
 extern "C"
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f4618ee1b5..da66e69f58 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -669,7 +669,6 @@ libgnucash/engine/policy.cpp
 libgnucash/engine/qof-backend.cpp
 libgnucash/engine/qofbook.cpp
 libgnucash/engine/qofbookslots.h
-libgnucash/engine/qofchoice.cpp
 libgnucash/engine/qofclass.cpp
 libgnucash/engine/qofevent.cpp
 libgnucash/engine/qofid.cpp



Summary of changes:
 libgnucash/engine/CMakeLists.txt |   2 -
 libgnucash/engine/gncAddress.c   |   4 -
 libgnucash/engine/gncCustomer.c  |  12 ---
 libgnucash/engine/gncInvoice.c   |   4 -
 libgnucash/engine/gncJob.c       |   9 ---
 libgnucash/engine/gncVendor.c    |   9 ---
 libgnucash/engine/qof.h          |   1 -
 libgnucash/engine/qofchoice.cpp  | 127 -----------------------------
 libgnucash/engine/qofchoice.h    | 168 ---------------------------------------
 libgnucash/engine/qofclass.h     |   1 +
 libgnucash/engine/qofobject.h    |   1 -
 libgnucash/engine/qofquery.h     |   1 -
 po/POTFILES.in                   |   1 -
 13 files changed, 1 insertion(+), 339 deletions(-)
 delete mode 100644 libgnucash/engine/qofchoice.cpp
 delete mode 100644 libgnucash/engine/qofchoice.h



More information about the gnucash-changes mailing list