GnuCash c935c2f+
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);
47GDate* 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 string_to_binary (const gchar* str, void** v, guint64* data_len);
52gboolean dom_tree_create_instance_slots (xmlNodePtr node, QofInstance* inst);
53
54gboolean dom_tree_to_integer (xmlNodePtr node, gint64* daint);
55gboolean dom_tree_to_guint16 (xmlNodePtr node, guint16* i);
56gboolean dom_tree_to_guint (xmlNodePtr node, guint* i);
57gboolean dom_tree_to_boolean (xmlNodePtr node, gboolean* b);
58
59/* higher level structures */
60Account* dom_tree_to_account (xmlNodePtr node, QofBook* book);
61QofBook* dom_tree_to_book (xmlNodePtr node, QofBook* book);
62GNCLot* dom_tree_to_lot (xmlNodePtr node, QofBook* book);
63Transaction* dom_tree_to_transaction (xmlNodePtr node, QofBook* book);
64GncBudget* 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
76template <typename T, typename F,
77 std::enable_if_t<std::is_invocable_r_v<void, F, const char*>, int> = 0>
78inline T
79apply_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
93template <typename Obj, typename F,
94 std::enable_if_t<std::is_invocable_r_v<void, F, Obj*, const char*>, int> = 0>
95inline bool
96apply_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
106gboolean dom_tree_generic_parse (xmlNodePtr node,
107 struct dom_tree_handler* handlers,
108 gpointer data);
109
110#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