Loading...
Searching...
No Matches
xact.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2023, John Wiegley. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of New Artisans LLC nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
42#pragma once
43
44#include "item.h"
45#include "predicate.h"
46
47namespace ledger {
48
49class post_t;
50class journal_t;
51class parse_context_t;
52
53typedef std::list<post_t *> posts_list;
54
55class xact_base_t : public item_t
56{
57public:
60
65
66 virtual ~xact_base_t();
67
68 virtual void add_post(post_t * post);
69 virtual bool remove_post(post_t * post);
70
71 posts_list::iterator posts_begin() {
72 return posts.begin();
73 }
74 posts_list::iterator posts_end() {
75 return posts.end();
76 }
77
79
80 bool finalize();
81 bool verify();
82
83 bool has_xdata();
85
86 virtual bool valid() const {
87 return true;
88 }
89};
90
91class xact_t : public xact_base_t
92{
93public:
95 string payee;
96
97#if DOCUMENT_MODEL
98 mutable void * data;
99#endif
100
102#if DOCUMENT_MODEL
103 : data(NULL)
104#endif
105 {
106 TRACE_CTOR(xact_t, "");
107 }
108 xact_t(const xact_t& e);
109
110 virtual ~xact_t() {
112 }
113
114 virtual string description() {
115 if (pos) {
116 std::ostringstream buf;
117 buf << _f("transaction at line %1%") % pos->beg_line;
118 return buf.str();
119 } else {
120 return string(_("generated transaction"));
121 }
122 }
123
124 virtual void add_post(post_t * post);
125
127 const string& name);
128
129 virtual bool valid() const;
130
131 string hash(string nonce, hash_type_t hash_type) const;
132};
133
135{
136public:
139 std::map<string, bool> memoized_results;
140
142
153
154 typedef std::list<deferred_tag_data_t> deferred_notes_list;
155
158
173
174 virtual ~auto_xact_t() {
176 }
177
178 virtual string description() {
179 if (pos) {
180 std::ostringstream buf;
181 buf << _f("automated transaction at line %1%") % pos->beg_line;
182 return buf.str();
183 } else {
184 return string(_("generated automated transaction"));
185 }
186 }
187
188 virtual void parse_tags(const char * p, scope_t&,
189 bool overwrite_existing = true) {
190 if (! deferred_notes)
192 deferred_notes->push_back(deferred_tag_data_t(p, overwrite_existing));
193 deferred_notes->back().apply_to_post = active_post;
194 }
195
196 virtual void extend_xact(xact_base_t& xact, parse_context_t& context);
197};
198
200{
201 public:
204
212 period_xact_t(const string& _period)
214 TRACE_CTOR(period_xact_t, "const string&");
215 }
216
217 virtual ~period_xact_t() {
219 }
220
221 virtual string description() {
222 if (pos) {
223 std::ostringstream buf;
224 buf << _f("periodic transaction at line %1%") % pos->beg_line;
225 return buf.str();
226 } else {
227 return string(_("generated periodic transaction"));
228 }
229 }
230};
231
232typedef std::list<xact_t *> xacts_list;
233typedef std::list<auto_xact_t *> auto_xacts_list;
234typedef std::list<period_xact_t *> period_xacts_list;
235
236void put_xact(property_tree::ptree& pt, const xact_t& xact);
237
238} // namespace ledger
#define TRACE_DTOR(cls)
Definition utils.h:144
#define TRACE_CTOR(cls, args)
Definition utils.h:143
std::list< auto_xact_t * > auto_xacts_list
Definition journal.h:61
hash_type_t
Definition utils.h:618
std::string string
Definition utils.h:59
void put_xact(property_tree::ptree &pt, const xact_t &xact)
std::list< xact_t * > xacts_list
Definition journal.h:60
T & downcast(U &object)
Definition utils.h:468
std::list< post_t * > posts_list
Definition account.h:54
std::list< period_xact_t * > period_xacts_list
Definition journal.h:62
intrusive_ptr< op_t > ptr_op_t
Definition expr.h:57
optional< position_t > pos
Definition item.h:101
Dynamic type representing various numeric types.
Definition value.h:83
virtual void add_post(post_t *post)
virtual ~xact_base_t()
virtual bool valid() const
Definition xact.h:86
journal_t * journal
Definition xact.h:58
virtual bool remove_post(post_t *post)
value_t magnitude() const
xact_base_t(const xact_base_t &e)
posts_list::iterator posts_begin()
Definition xact.h:71
posts_list::iterator posts_end()
Definition xact.h:74
posts_list posts
Definition xact.h:59
string hash(string nonce, hash_type_t hash_type) const
virtual bool valid() const
string payee
Definition xact.h:95
virtual string description()
Definition xact.h:114
xact_t(const xact_t &e)
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, const string &name)
virtual void add_post(post_t *post)
optional< string > code
Definition xact.h:94
virtual ~xact_t()
Definition xact.h:110
auto_xact_t(const auto_xact_t &other)
Definition xact.h:162
auto_xact_t(const predicate_t &_predicate)
Definition xact.h:168
virtual void extend_xact(xact_base_t &xact, parse_context_t &context)
std::map< string, bool > memoized_results
Definition xact.h:139
optional< deferred_notes_list > deferred_notes
Definition xact.h:156
optional< expr_t::check_expr_list > check_exprs
Definition xact.h:141
std::list< deferred_tag_data_t > deferred_notes_list
Definition xact.h:154
predicate_t predicate
Definition xact.h:137
bool try_quick_match
Definition xact.h:138
post_t * active_post
Definition xact.h:157
virtual void parse_tags(const char *p, scope_t &, bool overwrite_existing=true)
Definition xact.h:188
virtual string description()
Definition xact.h:178
virtual ~auto_xact_t()
Definition xact.h:174
deferred_tag_data_t(string _tag_data, bool _overwrite_existing)
Definition xact.h:148
period_xact_t(const period_xact_t &e)
Definition xact.h:208
date_interval_t period
Definition xact.h:202
virtual ~period_xact_t()
Definition xact.h:217
period_xact_t(const string &_period)
Definition xact.h:212
string period_string
Definition xact.h:203
virtual string description()
Definition xact.h:221