GnuCash  5.6-150-g038405b370+
SX-ttinfo.hpp
1 /********************************************************************\
2  * SX-ttinfo.h -- Template Transaction manipulation functions *
3  * for scheduled transactions *
4  * Copyright (C) 2001 Robert Merkel <rgmerk@mira.net> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License*
17  * along with this program; if not, contact: *
18  * *
19  * Free Software Foundation Voice: +1-617-542-5942 *
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21  * Boston, MA 02110-1301, USA gnu@gnu.org *
22  * *
23 \********************************************************************/
24 
25 #ifndef GNC_SX_TTINFO_H
26 #define GNC_SX_TTINFO_H
27 
28 #include <glib.h>
29 #include "qof.h"
30 #include "SchedXaction.h"
31 #include "Account.h"
32 #include "gnc-commodity.h"
33 #include "gnc-numeric.hpp"
34 
35 #include <vector>
36 #include <optional>
37 #include <string>
38 #include <algorithm>
39 #include <memory>
40 
42 {
43  const char* operator* () const { return m_str ? m_str->c_str() : nullptr; };
44  void operator= (const char* str) { if (str) m_str = str; else reset(); };
45  void reset () { m_str = std::nullopt; };
46 protected:
47  std::optional<std::string> m_str;
48 };
49 
51 {
52  using OptionalString::operator=;
53  void operator= (std::optional<gnc_numeric> num)
54  { if (num) m_str = GncNumeric (*num).to_string(); else reset(); }
55 };
56 
58 {
59  OptionalString m_action;
60  OptionalString m_memo;
61  OptionalStringFromNumeric m_credit_formula, m_debit_formula;
62  Account *m_acc = nullptr;
63 
64  const char* get_action () const { return *m_action; };
65  const char* get_memo () const { return *m_memo; };
66  const Account* get_account () const { return m_acc; };
67  const char* get_credit_formula () const { return *m_credit_formula; };
68  const char* get_debit_formula () const { return *m_debit_formula; };
69 
70  void set_action (const char *action) { m_action = action; };
71  void set_memo (const char *memo) { m_memo = memo; };
72  void set_account (Account *acc) { m_acc = acc; };
73  void set_credit_formula (const char *credit_formula) { set_formulas (nullptr, credit_formula); };
74  void set_debit_formula (const char *debit_formula) { set_formulas (debit_formula, nullptr); };
75  void set_credit_formula_numeric (gnc_numeric num) { set_formulas_numeric ({}, num); };
76  void set_debit_formula_numeric (gnc_numeric num) { set_formulas_numeric (num, {}); };
77 
78 private:
79  void set_formulas (const char* debit, const char *credit)
80  {
81  m_debit_formula = debit;
82  m_credit_formula = credit;
83  }
84  void set_formulas_numeric (std::optional<gnc_numeric> debit, std::optional<gnc_numeric> credit)
85  {
86  m_debit_formula = debit;
87  m_credit_formula = credit;
88  }
89 };
90 
91 using TTSplitInfoPtr = std::shared_ptr<TTSplitInfo>;
92 using TTSplitInfoVec = std::vector<TTSplitInfoPtr>;
93 
94 struct TTInfo
95 {
96  OptionalString m_description;
97  OptionalString m_num;
98  OptionalString m_notes;
99  gnc_commodity *m_common_currency = nullptr;
100  TTSplitInfoVec m_splits;
101 
102  const char* get_description () const { return *m_description; };
103  const char* get_num () const { return *m_num; };
104  const char* get_notes () const { return *m_notes; };
105  gnc_commodity* get_currency () const { return m_common_currency; };
106  const TTSplitInfoVec& get_template_splits () const { return m_splits; };
107 
108  void set_description (const char *description) { m_description = description; };
109  void set_num (const char *num) { m_num = num; };
110  void set_notes (const char *notes) { m_notes = notes; };
111  void set_currency (gnc_commodity *currency) { m_common_currency = currency; };
112  void clear_template_splits () { m_splits.clear(); };
113  void append_template_split (TTSplitInfoPtr& ttsi) { m_splits.push_back (ttsi); };
114 ;
115 };
116 
117 using TTInfoPtr = std::shared_ptr<TTInfo>;
118 using TTInfoVec = std::vector<TTInfoPtr>;
119 
120 #endif
STRUCTS.
The primary numeric class for representing amounts and values.
Definition: gnc-numeric.hpp:59
std::string to_string() const noexcept
Return a string representation of the GncNumeric.
Account handling public routines.
Scheduled Transactions public handling routines.
Commodity handling public routines.