GnuCash 7574033+
Loading...
Searching...
No Matches
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
35std::optional<GncGUID> dom_tree_to_guid (xmlNodePtr node);
36
37std::string gnc_strstrip (std::string_view sv);
38
39gnc_commodity* dom_tree_to_commodity_ref (xmlNodePtr node, QofBook* book);
40gnc_commodity* dom_tree_to_commodity_ref_no_engine (xmlNodePtr node, QofBook*);
41
42GList* dom_tree_freqSpec_to_recurrences (xmlNodePtr node, QofBook* book);
43Recurrence* dom_tree_to_recurrence (xmlNodePtr node);
44
45time64 dom_tree_to_time64 (xmlNodePtr node);
46gboolean dom_tree_valid_time64 (time64 ts, const xmlChar* name);
47std::optional<GDate> dom_tree_to_gdate (xmlNodePtr node);
48gnc_numeric dom_tree_to_gnc_numeric (xmlNodePtr node);
49std::optional<std::string> dom_tree_to_text (xmlNodePtr tree);
50const char* dom_node_to_text (xmlNodePtr node) noexcept;
51gboolean dom_tree_create_instance_slots (xmlNodePtr node, QofInstance* inst);
52
53gboolean dom_tree_to_integer (xmlNodePtr node, gint64* daint);
54gboolean dom_tree_to_guint16 (xmlNodePtr node, guint16* i);
55gboolean dom_tree_to_guint (xmlNodePtr node, guint* i);
56gboolean dom_tree_to_boolean (xmlNodePtr node, gboolean* b);
57
58/* higher level structures */
59Account* dom_tree_to_account (xmlNodePtr node, QofBook* book);
60QofBook* dom_tree_to_book (xmlNodePtr node, QofBook* book);
61GNCLot* dom_tree_to_lot (xmlNodePtr node, QofBook* book);
62Transaction* dom_tree_to_transaction (xmlNodePtr node, QofBook* book);
63GncBudget* dom_tree_to_budget (xmlNodePtr node, QofBook* book);
64
66{
67 const char* tag;
68
69 gboolean (*handler) (xmlNodePtr, gpointer data);
70
71 int required;
72 int gotten;
73};
74
75template <typename T, typename F,
76 std::enable_if_t<std::is_invocable_r_v<void, F, const char*>, int> = 0>
77inline T
78apply_xmlnode_text (F&& f, xmlNodePtr node, T default_val = T{})
79{
80 if (!node)
81 return default_val;
82
83 if (auto txt = dom_node_to_text(node))
84 return f(txt);
85
86 if (auto txt = dom_tree_to_text(node))
87 return f(txt->c_str());
88
89 return default_val;
90}
91
92template <typename Obj, typename F,
93 std::enable_if_t<std::is_invocable_r_v<void, F, Obj*, const char*>, int> = 0>
94inline bool
95apply_xmlnode_text (F&& f, Obj* obj, xmlNodePtr node)
96{
97 auto set_str = [&](auto txt)
98 {
99 f (obj, txt);
100 return true;
101 };
102 return apply_xmlnode_text<bool> (set_str, node, false);
103}
104
105gboolean dom_tree_generic_parse (xmlNodePtr node,
106 struct dom_tree_handler* handlers,
107 gpointer data);
108
109#endif /* _SIXTP_DOM_PARSERS_H_ */
GnuCash Budgets.
Commodity handling public routines.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
STRUCTS.
QofBook reference.
Definition qofbook-p.hpp:47