Loading...
Searching...
No Matches
output.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 "chain.h"
45#include "predicate.h"
46#include "format.h"
47#include "account.h"
48
49namespace ledger {
50
51class xact_t;
52class post_t;
53class item_t;
54class report_t;
55
56class format_posts : public item_handler<post_t>
57{
58protected:
64 std::size_t prepend_width;
69
70public:
71 format_posts(report_t& _report, const string& format,
73 std::size_t _prepend_width = 0);
74 virtual ~format_posts() {
76 }
77
78 virtual void title(const string& str) {
79 report_title = str;
80 }
81
82 virtual void flush();
83 virtual void operator()(post_t& post);
84
85 virtual void clear() {
88
89 report_title = "";
90
92 }
93};
94
95class format_accounts : public item_handler<account_t>
96{
97protected:
103 std::size_t prepend_width;
107
108 std::list<account_t *> posted_accounts;
109
110public:
113 std::size_t _prepend_width = 0);
117
118 std::pair<std::size_t, std::size_t>
119 mark_accounts(account_t& account, const bool flat);
120
121 virtual void title(const string& str) {
122 report_title = str;
123 }
124
125 virtual std::size_t post_account(account_t& account, const bool flat);
126 virtual void flush();
127
128 virtual void operator()(account_t& account);
129
130 virtual void clear() {
132 posted_accounts.clear();
133
134 report_title = "";
135
137 }
138};
139
140class report_accounts : public item_handler<post_t>
141{
142protected:
144
145 typedef std::map<account_t *, std::size_t>::value_type accounts_pair;
146 typedef std::map<account_t *, std::size_t, account_compare> accounts_report_map;
147
149
150public:
157
158 virtual void flush();
159 virtual void operator()(post_t& post);
160
161 virtual void clear() {
162 accounts.clear();
164 }
165};
166
167class report_payees : public item_handler<post_t>
168{
169protected:
171
172 std::map<string, std::size_t> payees;
173
174 typedef std::map<string, std::size_t>::value_type payees_pair;
175
176public:
180 virtual ~report_payees() {
182 }
183
184 virtual void flush();
185 virtual void operator()(post_t& post);
186
187 virtual void clear() {
188 payees.clear();
190 }
191};
192
193class report_tags : public item_handler<post_t>
194{
195protected:
197
198 std::map<string, std::size_t> tags;
199
200 typedef std::map<string, std::size_t>::value_type tags_pair;
201
202public:
206 virtual ~report_tags() {
208 }
209
210 virtual void flush();
212 virtual void operator()(post_t& post);
213
214 virtual void clear() {
215 tags.clear();
217 }
218};
219
220
221class report_commodities : public item_handler<post_t>
222{
223protected:
225
226 typedef std::map<commodity_t *, std::size_t>::value_type commodities_pair;
227 typedef std::map<commodity_t *, std::size_t, commodity_compare> commodities_report_map;
228
230
231public:
238
239 virtual void flush();
240 virtual void operator()(post_t& post);
241
242 virtual void clear() {
243 commodities.clear();
245 }
246};
247
248} // namespace ledger
#define TRACE_DTOR(cls)
Definition utils.h:144
#define TRACE_CTOR(cls, args)
Definition utils.h:143
T & downcast(U &object)
Definition utils.h:468
virtual void clear()
Definition chain.h:84
virtual void mark_uncompiled()
Definition exprbase.h:134
format_t first_line_format
Definition output.h:60
virtual void clear()
Definition output.h:85
virtual void title(const string &str)
Definition output.h:78
std::size_t prepend_width
Definition output.h:64
post_t * last_post
Definition output.h:66
virtual void flush()
xact_t * last_xact
Definition output.h:65
format_posts(report_t &_report, const string &format, const optional< string > &_prepend_format=none, std::size_t _prepend_width=0)
format_t between_format
Definition output.h:62
virtual ~format_posts()
Definition output.h:74
format_t next_lines_format
Definition output.h:61
virtual void operator()(post_t &post)
report_t & report
Definition output.h:59
format_t prepend_format
Definition output.h:63
bool first_report_title
Definition output.h:67
string report_title
Definition output.h:68
std::pair< std::size_t, std::size_t > mark_accounts(account_t &account, const bool flat)
virtual void title(const string &str)
Definition output.h:121
predicate_t disp_pred
Definition output.h:104
virtual std::size_t post_account(account_t &account, const bool flat)
std::list< account_t * > posted_accounts
Definition output.h:108
format_accounts(report_t &_report, const string &_format, const optional< string > &_prepend_format=none, std::size_t _prepend_width=0)
format_t separator_format
Definition output.h:101
report_t & report
Definition output.h:98
virtual void operator()(account_t &account)
format_t account_line_format
Definition output.h:99
virtual ~format_accounts()
Definition output.h:114
format_t prepend_format
Definition output.h:102
virtual void clear()
Definition output.h:130
std::size_t prepend_width
Definition output.h:103
virtual void flush()
format_t total_line_format
Definition output.h:100
accounts_report_map accounts
Definition output.h:148
virtual void operator()(post_t &post)
virtual void clear()
Definition output.h:161
std::map< account_t *, std::size_t >::value_type accounts_pair
Definition output.h:145
virtual ~report_accounts()
Definition output.h:154
std::map< account_t *, std::size_t, account_compare > accounts_report_map
Definition output.h:146
report_accounts(report_t &_report)
Definition output.h:151
virtual void flush()
virtual void operator()(post_t &post)
virtual ~report_payees()
Definition output.h:180
std::map< string, std::size_t > payees
Definition output.h:172
report_payees(report_t &_report)
Definition output.h:177
virtual void flush()
virtual void clear()
Definition output.h:187
std::map< string, std::size_t >::value_type payees_pair
Definition output.h:174
report_t & report
Definition output.h:170
virtual ~report_tags()
Definition output.h:206
virtual void gather_metadata(item_t &item)
virtual void operator()(post_t &post)
virtual void flush()
std::map< string, std::size_t >::value_type tags_pair
Definition output.h:200
report_t & report
Definition output.h:196
report_tags(report_t &_report)
Definition output.h:203
virtual void clear()
Definition output.h:214
std::map< string, std::size_t > tags
Definition output.h:198
commodities_report_map commodities
Definition output.h:229
std::map< commodity_t *, std::size_t, commodity_compare > commodities_report_map
Definition output.h:227
report_commodities(report_t &_report)
Definition output.h:232
virtual void operator()(post_t &post)
virtual ~report_commodities()
Definition output.h:235
std::map< commodity_t *, std::size_t >::value_type commodities_pair
Definition output.h:226
virtual void clear()
Definition output.h:242