Line data Source code
1 : /********************************************************************
2 : * sixtp-dom-parsers.h *
3 : * Copyright (c) 2001 Gnumatic, Inc. *
4 : * *
5 : * This program is free software; you can redistribute it and/or *
6 : * modify it under the terms of the GNU General Public License as *
7 : * published by the Free Software Foundation; either version 2 of *
8 : * the License, or (at your option) any later version. *
9 : * *
10 : * This program is distributed in the hope that it will be useful, *
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 : * GNU General Public License for more details. *
14 : * *
15 : * You should have received a copy of the GNU General Public License*
16 : * along with this program; if not, contact: *
17 : * *
18 : * Free Software Foundation Voice: +1-617-542-5942 *
19 : * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20 : * Boston, MA 02110-1301, USA gnu@gnu.org *
21 : * *
22 : ********************************************************************/
23 :
24 : #ifndef SIXTP_DOM_PARSERS_H
25 : #define SIXTP_DOM_PARSERS_H
26 : #include <glib.h>
27 :
28 : #include "gnc-commodity.h"
29 : #include "qof.h"
30 : #include "gnc-budget.h"
31 : #include <optional>
32 :
33 : #include "gnc-xml-helper.h"
34 :
35 : std::optional<GncGUID> dom_tree_to_guid (xmlNodePtr node);
36 :
37 : std::string gnc_strstrip (std::string_view sv);
38 :
39 : gnc_commodity* dom_tree_to_commodity_ref (xmlNodePtr node, QofBook* book);
40 : gnc_commodity* dom_tree_to_commodity_ref_no_engine (xmlNodePtr node, QofBook*);
41 :
42 : GList* dom_tree_freqSpec_to_recurrences (xmlNodePtr node, QofBook* book);
43 : Recurrence* dom_tree_to_recurrence (xmlNodePtr node);
44 :
45 : time64 dom_tree_to_time64 (xmlNodePtr node);
46 : gboolean dom_tree_valid_time64 (time64 ts, const xmlChar* name);
47 : std::optional<GDate> dom_tree_to_gdate (xmlNodePtr node);
48 : gnc_numeric dom_tree_to_gnc_numeric (xmlNodePtr node);
49 : std::optional<std::string> dom_tree_to_text (xmlNodePtr tree);
50 : const char* dom_node_to_text (xmlNodePtr node) noexcept;
51 : gboolean dom_tree_create_instance_slots (xmlNodePtr node, QofInstance* inst);
52 :
53 : gboolean dom_tree_to_integer (xmlNodePtr node, gint64* daint);
54 : gboolean dom_tree_to_guint16 (xmlNodePtr node, guint16* i);
55 : gboolean dom_tree_to_guint (xmlNodePtr node, guint* i);
56 : gboolean dom_tree_to_boolean (xmlNodePtr node, gboolean* b);
57 :
58 : /* higher level structures */
59 : Account* dom_tree_to_account (xmlNodePtr node, QofBook* book);
60 : QofBook* dom_tree_to_book (xmlNodePtr node, QofBook* book);
61 : GNCLot* dom_tree_to_lot (xmlNodePtr node, QofBook* book);
62 : Transaction* dom_tree_to_transaction (xmlNodePtr node, QofBook* book);
63 : GncBudget* dom_tree_to_budget (xmlNodePtr node, QofBook* book);
64 :
65 : struct dom_tree_handler
66 : {
67 : const char* tag;
68 :
69 : gboolean (*handler) (xmlNodePtr, gpointer data);
70 :
71 : int required;
72 : int gotten;
73 : };
74 :
75 : template <typename T, typename F,
76 : std::enable_if_t<std::is_invocable_r_v<void, F, const char*>, int> = 0>
77 : inline T
78 33970 : apply_xmlnode_text (F&& f, xmlNodePtr node, T default_val = T{})
79 : {
80 33970 : if (!node)
81 0 : return default_val;
82 :
83 33970 : if (auto txt = dom_node_to_text(node))
84 33404 : return f(txt);
85 :
86 1132 : if (auto txt = dom_tree_to_text(node))
87 566 : return f(txt->c_str());
88 :
89 0 : return default_val;
90 : }
91 :
92 : template <typename Obj, typename F,
93 : std::enable_if_t<std::is_invocable_r_v<void, F, Obj*, const char*>, int> = 0>
94 : inline bool
95 7566 : apply_xmlnode_text (F&& f, Obj* obj, xmlNodePtr node)
96 : {
97 15132 : auto set_str = [&](auto txt)
98 : {
99 7566 : f (obj, txt);
100 7566 : return true;
101 : };
102 15132 : return apply_xmlnode_text<bool> (set_str, node, false);
103 : }
104 :
105 : gboolean dom_tree_generic_parse (xmlNodePtr node,
106 : struct dom_tree_handler* handlers,
107 : gpointer data);
108 :
109 : #endif /* _SIXTP_DOM_PARSERS_H_ */
|