GnuCash  5.6-150-g038405b370+
sixtp-dom-parsers.h
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 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 string_to_binary (const gchar* str, void** v, guint64* data_len);
52 gboolean dom_tree_create_instance_slots (xmlNodePtr node, QofInstance* inst);
53 
54 gboolean dom_tree_to_integer (xmlNodePtr node, gint64* daint);
55 gboolean dom_tree_to_guint16 (xmlNodePtr node, guint16* i);
56 gboolean dom_tree_to_guint (xmlNodePtr node, guint* i);
57 gboolean dom_tree_to_boolean (xmlNodePtr node, gboolean* b);
58 
59 /* higher level structures */
60 Account* dom_tree_to_account (xmlNodePtr node, QofBook* book);
61 QofBook* dom_tree_to_book (xmlNodePtr node, QofBook* book);
62 GNCLot* dom_tree_to_lot (xmlNodePtr node, QofBook* book);
63 Transaction* dom_tree_to_transaction (xmlNodePtr node, QofBook* book);
64 GncBudget* dom_tree_to_budget (xmlNodePtr node, QofBook* book);
65 
67 {
68  const char* tag;
69 
70  gboolean (*handler) (xmlNodePtr, gpointer data);
71 
72  int required;
73  int gotten;
74 };
75 
76 template <typename T, typename F,
77  std::enable_if_t<std::is_invocable_r_v<void, F, const char*>, int> = 0>
78 inline T
79 apply_xmlnode_text (F&& f, xmlNodePtr node, T default_val = T{})
80 {
81  if (!node)
82  return default_val;
83 
84  if (auto txt = dom_node_to_text(node))
85  return f(txt);
86 
87  if (auto txt = dom_tree_to_text(node))
88  return f(txt->c_str());
89 
90  return default_val;
91 }
92 
93 template <typename Obj, typename F,
94  std::enable_if_t<std::is_invocable_r_v<void, F, Obj*, const char*>, int> = 0>
95 inline bool
96 apply_xmlnode_text (F&& f, Obj* obj, xmlNodePtr node)
97 {
98  auto set_str = [&](auto txt)
99  {
100  f (obj, txt);
101  return true;
102  };
103  return apply_xmlnode_text<bool> (set_str, node, false);
104 }
105 
106 gboolean dom_tree_generic_parse (xmlNodePtr node,
107  struct dom_tree_handler* handlers,
108  gpointer data);
109 
110 #endif /* _SIXTP_DOM_PARSERS_H_ */
STRUCTS.
GnuCash Budgets.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
Commodity handling public routines.