Loading...
Searching...
No Matches
session.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 "account.h"
45#include "journal.h"
46#include "context.h"
47#include "option.h"
48#include "commodity.h"
49
50namespace ledger {
51
52class xact_t;
53
55{
56 bool operator()(const path& p1, const path& p2) const
57 {
58 return p1 < p2 && !boost::filesystem::equivalent(p1, p2);
59 }
60};
61
62#define COMMA ,
63
65{
66 friend void set_session_context(session_t * session);
67
68public:
70
71 unique_ptr<journal_t> journal;
74
75 explicit session_t();
76 virtual ~session_t() {
79 }
80
81 virtual string description() {
82 return _("current session");
83 }
84
88
89 journal_t * read_journal(const path& pathname);
90 journal_t * read_journal_from_string(const string& data);
91 std::size_t read_data(const string& master_account = "");
92
95
97
106
107 void report_options(std::ostream& out)
108 {
109 HANDLER(check_payees).report(out);
110 HANDLER(day_break).report(out);
111 HANDLER(download).report(out);
112 HANDLER(decimal_comma).report(out);
113 HANDLER(time_colon).report(out);
114 HANDLER(file_).report(out);
115 HANDLER(hashes_).report(out);
116 HANDLER(input_date_format_).report(out);
117 HANDLER(explicit).report(out);
118 HANDLER(master_account_).report(out);
119 HANDLER(pedantic).report(out);
120 HANDLER(permissive).report(out);
121 HANDLER(price_db_).report(out);
122 HANDLER(price_exp_).report(out);
123 HANDLER(recursive_aliases).report(out);
124 HANDLER(no_aliases).report(out);
125 HANDLER(strict).report(out);
126 HANDLER(value_expr_).report(out);
127 }
128
130
132 const string& name);
133
138 OPTION(session_t, check_payees);
139 OPTION(session_t, day_break);
141
144 });
145
148 });
149
151 (session_t, price_exp_, // -Z
152 CTOR(session_t, price_exp_) { value = "24"; });
153
155 (session_t, file_, // -f
156 std::list<path> data_files;
157 CTOR(session_t, file_) {}
158 DO_(str) {
159 if (parent->flush_on_next_data_file) {
160 data_files.clear();
161 parent->flush_on_next_data_file = false;
162 }
163 data_files.push_back(str);
164 });
165
168 hash_type_t hash_type = NO_HASHES;
170 DO_(str) {
171 if (str == "sha512" || str == "SHA512") {
172 hash_type = HASH_SHA512;
173 } else if (str == "sha512_half" || str == "SHA512_Half") {
174 hash_type = HASH_SHA512_Half;
175 } else {
176 throw_(std::invalid_argument, _f("Unrecognized hash type"));
177 }
178 });
179
181 // This changes static variables inside times.h, which affects the
182 // basic date parser.
183 set_input_date_format(str.c_str());
184 });
185
186 OPTION(session_t, explicit);
193 OPTION(session_t, recursive_aliases);
194 OPTION(session_t, no_aliases);
195};
196
206
207} // namespace ledger
#define TRACE_DTOR(cls)
Definition utils.h:144
Basic type and macros for handling command-line options.
#define HANDLER(name)
Definition option.h:263
#define DO_(var)
Definition option.h:219
#define OPTION(type, name)
Definition option.h:266
#define CTOR(type, name)
Definition option.h:210
#define OPTION_(type, name, body)
Definition option.h:273
#define DO()
Definition option.h:218
#define OPTION__(type, name, body)
Definition option.h:281
#define throw_(cls, msg)
Definition error.h:55
Types for handling commodities.
void set_session_context(session_t *session)
Set the current session context, transferring all static globals to point at the data structures rela...
void set_input_date_format(const char *format)
hash_type_t
Definition utils.h:618
@ HASH_SHA512_Half
Definition utils.h:621
@ NO_HASHES
Definition utils.h:619
@ HASH_SHA512
Definition utils.h:620
boost::filesystem::path path
Definition utils.h:68
T & downcast(U &object)
Definition utils.h:468
static bool time_colon_by_default
Definition commodity.h:145
static bool decimal_comma_by_default
Definition commodity.h:144
intrusive_ptr< op_t > ptr_op_t
Definition expr.h:57
scope_t * parent
Definition scope.h:138
bool operator()(const path &p1, const path &p2) const
Definition session.h:56
value_t fn_lot_date(call_scope_t &scope)
value_t fn_account(call_scope_t &scope)
value_t fn_min(call_scope_t &scope)
value_t fn_int(call_scope_t &scope)
virtual string description()
Definition session.h:81
void set_flush_on_next_data_file(const bool truth)
Definition session.h:85
journal_t * read_journal(const path &pathname)
friend void set_session_context(session_t *session)
Set the current session context, transferring all static globals to point at the data structures rela...
option_t< session_t > * lookup_option(const char *p)
optional< expr_t > value_expr
Definition session.h:73
void close_journal_files()
value_t fn_max(call_scope_t &scope)
bool flush_on_next_data_file
Definition session.h:69
value_t fn_str(call_scope_t &scope)
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, const string &name)
journal_t * get_journal()
value_t fn_lot_price(call_scope_t &scope)
journal_t * read_journal_files()
void report_options(std::ostream &out)
Definition session.h:107
journal_t * read_journal_from_string(const string &data)
parse_context_stack_t parsing_context
Definition session.h:72
virtual ~session_t()
Definition session.h:76
std::size_t read_data(const string &master_account="")
unique_ptr< journal_t > journal
Definition session.h:71
value_t fn_lot_tag(call_scope_t &scope)
Dynamic type representing various numeric types.
Definition value.h:83