Loading...
Searching...
No Matches
draft.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2025, 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
35
42#pragma once
43
44#include "exprbase.h"
45#include "value.h"
46
47namespace ledger {
48
49class journal_t;
50class xact_t;
51
52class draft_t : public expr_base_t<value_t>
53{
54 typedef expr_base_t<value_t> base_type;
55
56 struct xact_template_t
57 {
58 optional<date_t> date;
59 optional<string> date_string;
60 optional<string> code;
61 optional<string> note;
62 mask_t payee_mask;
63
65 bool from;
66 optional<mask_t> account_mask;
67 optional<amount_t> amount;
68 optional<string> cost_operator;
69 optional<amount_t> cost;
70
71 post_template_t() : from(false) {
73 }
77 };
78
79 std::list<post_template_t> posts;
80
81 xact_template_t() {
82 TRACE_CTOR(xact_template_t, "");
83 }
84 xact_template_t(const xact_template_t& other)
85 : date(other.date),
86 date_string(other.date_string),
87 code(other.code),
88 note(other.note),
89 payee_mask(other.payee_mask),
90 posts(other.posts)
91 {
92 TRACE_CTOR(xact_template_t, "copy");
93 }
94 ~xact_template_t() throw() {
95 TRACE_DTOR(xact_template_t);
96 }
97
98 void dump(std::ostream& out) const;
99 };
100
101 optional<xact_template_t> tmpl;
102
103public:
104 draft_t(const value_t& args) : base_type() {
105 if (! args.empty())
106 parse_args(args);
107 TRACE_CTOR(draft_t, "value_t");
108 }
109 virtual ~draft_t() throw() {
111 }
112
113 void parse_args(const value_t& args);
114
116 assert(false);
117 return true;
118 }
119
121
122 virtual void dump(std::ostream& out) const {
123 if (tmpl)
124 tmpl->dump(out);
125 }
126};
127
130
131} // namespace ledger
Abstract dynamic type representing various numeric types.
#define TRACE_DTOR(cls)
Definition utils.h:144
#define TRACE_CTOR(cls, args)
Definition utils.h:143
#define assert(x)
Definition utils.h:92
value_t xact_command(call_scope_t &args)
gregorian::date date
Definition utils.h:64
value_t template_command(call_scope_t &args)
virtual ~draft_t()
Definition draft.h:109
virtual result_type real_calc(scope_t &)
Definition draft.h:115
xact_t * insert(journal_t &journal)
draft_t(const value_t &args)
Definition draft.h:104
virtual void dump(std::ostream &out) const
Definition draft.h:122
void parse_args(const value_t &args)
expr_base_t(const expr_base_t &other)
Definition exprbase.h:85
Dynamic type representing various numeric types.
Definition value.h:86
bool empty() const
Definition value.h:941