Loading...
Searching...
No Matches
chain.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
46namespace ledger {
47
48class post_t;
49class account_t;
50
51template <typename T>
52class item_handler : public noncopyable
53{
54protected:
56
57public:
64 virtual ~item_handler() {
66 }
67
68 virtual void title(const string& str) {
69 if (handler)
70 handler->title(str);
71 }
72
73 virtual void flush() {
74 if (handler)
75 handler->flush();
76 }
77 virtual void operator()(T& item) {
78 if (handler) {
80 (*handler)(item);
81 }
82 }
83
84 virtual void clear() {
85 if (handler)
86 handler->clear();
87 }
88};
89
92
93class report_t;
94
97 report_t& report);
98
101 report_t& report,
102 bool for_accounts_report = false);
103
104inline post_handler_ptr
106 report_t& report,
107 bool for_accounts_report = false) {
108 handler = chain_post_handlers(handler, report, for_accounts_report);
109 handler = chain_pre_post_handlers(handler, report);
110 return handler;
111}
112
113} // 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
void check_for_signal()
Definition utils.h:446
post_handler_ptr chain_pre_post_handlers(post_handler_ptr base_handler, report_t &report)
shared_ptr< item_handler< post_t > > post_handler_ptr
Definition chain.h:90
post_handler_ptr chain_handlers(post_handler_ptr handler, report_t &report, bool for_accounts_report=false)
Definition chain.h:105
post_handler_ptr chain_post_handlers(post_handler_ptr base_handler, report_t &report, bool for_accounts_report=false)
T & downcast(U &object)
Definition utils.h:468
shared_ptr< item_handler< account_t > > acct_handler_ptr
Definition chain.h:91
virtual void clear()
Definition chain.h:84
item_handler(shared_ptr< item_handler > _handler)
Definition chain.h:61
virtual ~item_handler()
Definition chain.h:64
virtual void operator()(T &item)
Definition chain.h:77
virtual void flush()
Definition chain.h:73
virtual void title(const string &str)
Definition chain.h:68
shared_ptr< item_handler > handler
Definition chain.h:55