Loading...
Searching...
No Matches
journal.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 "utils.h"
45#include "times.h"
46#include "mask.h"
47#include "expr.h"
48
49namespace ledger {
50
51class xact_base_t;
52class xact_t;
53class auto_xact_t;
54class period_xact_t;
55class post_t;
56class account_t;
57class parse_context_t;
58class parse_context_stack_t;
59
60typedef std::list<xact_t *> xacts_list;
61typedef std::list<auto_xact_t *> auto_xacts_list;
62typedef std::list<period_xact_t *> period_xacts_list;
63typedef std::pair<mask_t, string> payee_alias_mapping_t;
64typedef std::list<payee_alias_mapping_t> payee_alias_mappings_t;
65typedef std::pair<string, string> payee_uuid_mapping_t;
66typedef std::list<payee_uuid_mapping_t> payee_uuid_mappings_t;
67typedef std::pair<mask_t, account_t *> account_mapping_t;
68typedef std::list<account_mapping_t> account_mappings_t;
69typedef std::map<string, account_t *> accounts_map;
70typedef std::map<string, xact_t *> checksum_map_t;
71
72typedef std::multimap<string, expr_t::check_expr_pair> tag_check_exprs_map;
73
74class journal_t : public noncopyable
75{
76public:
101
107 std::list<fileinfo_t> sources;
108 std::set<string> known_payees;
109 std::set<string> known_tags;
124
131
133#if 0
134 journal_t(const path& pathname);
135 journal_t(const string& str);
136#endif
138
140
141 std::list<fileinfo_t>::iterator sources_begin() {
142 return sources.begin();
143 }
144 std::list<fileinfo_t>::iterator sources_end() {
145 return sources.end();
146 }
147
150 account_t * find_account(const string& name, bool auto_create = true);
152
153 account_t * expand_aliases(string name);
154
155 account_t * register_account(const string& name, post_t * post,
156 account_t * master = NULL);
157 string register_payee(const string& name);
158 string validate_payee(const string& name_or_alias);
161 void register_metadata(const string& key, const value_t& value,
163
164 bool add_xact(xact_t * xact);
166 bool remove_xact(xact_t * xact);
167
168 xacts_list::iterator xacts_begin() {
169 return xacts.begin();
170 }
171 xacts_list::iterator xacts_end() {
172 return xacts.end();
173 }
174 auto_xacts_list::iterator auto_xacts_begin() {
175 return auto_xacts.begin();
176 }
177 auto_xacts_list::iterator auto_xacts_end() {
178 return auto_xacts.end();
179 }
180 period_xacts_list::iterator period_xacts_begin() {
181 return period_xacts.begin();
182 }
183 period_xacts_list::iterator period_xacts_end() {
184 return period_xacts.end();
185 }
186
187 std::size_t read(parse_context_stack_t& context,
188 hash_type_t hash_type);
189
190 bool has_xdata();
192
193 bool valid() const;
194
195private:
196
197 std::size_t read_textual(parse_context_stack_t& context,
198 hash_type_t hash_type);
199
200 bool should_check_payees();
201 bool payee_not_registered(const string& name);
202 string translate_payee_name(const string& name);
203};
204
205} // namespace ledger
General utility facilities used by Ledger.
#define TRACE_DTOR(cls)
Definition utils.h:144
#define TRACE_CTOR(cls, args)
Definition utils.h:143
datetime_t and date_t objects
Regular expression masking.
std::list< account_mapping_t > account_mappings_t
Definition journal.h:68
std::list< auto_xact_t * > auto_xacts_list
Definition journal.h:61
std::list< payee_alias_mapping_t > payee_alias_mappings_t
Definition journal.h:64
std::pair< string, string > payee_uuid_mapping_t
Definition journal.h:65
hash_type_t
Definition utils.h:618
std::pair< mask_t, account_t * > account_mapping_t
Definition journal.h:67
boost::filesystem::path path
Definition utils.h:68
std::map< string, account_t * > accounts_map
Definition account.h:55
std::list< xact_t * > xacts_list
Definition journal.h:60
T & downcast(U &object)
Definition utils.h:468
std::pair< mask_t, string > payee_alias_mapping_t
Definition journal.h:63
std::multimap< string, expr_t::check_expr_pair > tag_check_exprs_map
Definition journal.h:72
std::map< string, xact_t * > checksum_map_t
Definition journal.h:70
boost::posix_time::ptime datetime_t
Definition times.h:53
std::list< payee_uuid_mapping_t > payee_uuid_mappings_t
Definition journal.h:66
std::list< period_xact_t * > period_xacts_list
Definition journal.h:62
std::set< string > known_tags
Definition journal.h:109
account_t * find_account_re(const string &regexp)
account_t * bucket
Definition journal.h:103
account_t * master
Definition journal.h:102
void register_commodity(commodity_t &comm, variant< int, xact_t *, post_t * > context)
xacts_list xacts
Definition journal.h:104
checksum_map_t checksum_map
Definition journal.h:120
void register_metadata(const string &key, const value_t &value, variant< int, xact_t *, post_t * > context)
bool remove_xact(xact_t *xact)
xacts_list::iterator xacts_begin()
Definition journal.h:168
std::size_t read(parse_context_stack_t &context, hash_type_t hash_type)
account_t * register_account(const string &name, post_t *post, account_t *master=NULL)
tag_check_exprs_map tag_check_exprs
Definition journal.h:121
account_t * find_account(const string &name, bool auto_create=true)
account_mappings_t payees_for_unknown_accounts
Definition journal.h:119
std::list< fileinfo_t > sources
Definition journal.h:107
void add_account(account_t *acct)
payee_alias_mappings_t payee_alias_mappings
Definition journal.h:115
payee_uuid_mappings_t payee_uuid_mappings
Definition journal.h:116
std::list< fileinfo_t >::iterator sources_end()
Definition journal.h:144
period_xacts_list::iterator period_xacts_begin()
Definition journal.h:180
bool recursive_aliases
Definition journal.h:113
string validate_payee(const string &name_or_alias)
account_mappings_t account_mappings
Definition journal.h:117
bool add_xact(xact_t *xact)
account_t * expand_aliases(string name)
bool remove_account(account_t *acct)
std::list< fileinfo_t >::iterator sources_begin()
Definition journal.h:141
parse_context_t * current_context
Definition journal.h:123
auto_xacts_list::iterator auto_xacts_begin()
Definition journal.h:174
period_xacts_list::iterator period_xacts_end()
Definition journal.h:183
auto_xacts_list auto_xacts
Definition journal.h:105
auto_xacts_list::iterator auto_xacts_end()
Definition journal.h:177
xacts_list::iterator xacts_end()
Definition journal.h:171
optional< expr_t > value_expr
Definition journal.h:122
enum ledger::journal_t::checking_style_t checking_style
period_xacts_list period_xacts
Definition journal.h:106
void extend_xact(xact_base_t *xact)
string register_payee(const string &name)
std::set< string > known_payees
Definition journal.h:108
accounts_map account_aliases
Definition journal.h:118
bool valid() const
fileinfo_t(const fileinfo_t &info)
Definition journal.h:91
fileinfo_t(const path &_filename)
Definition journal.h:86
optional< path > filename
Definition journal.h:79
Dynamic type representing various numeric types.
Definition value.h:83