Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef CSV_TPL_PROCESSOR_HXX
21 : #define CSV_TPL_PROCESSOR_HXX
22 :
23 : // USED SERVICES
24 :
25 :
26 :
27 :
28 : namespace csv
29 : {
30 :
31 :
32 : /** Implements an acyclic visitor pattern. This is the abstract
33 : base for the classes doing the work (the "visitors").
34 : */
35 2 : class ProcessorIfc
36 : {
37 : public:
38 2 : virtual ~ProcessorIfc() {}
39 : };
40 :
41 :
42 :
43 : /** Implements an acyclic visitor pattern. This is the abstract
44 : base for the classes to be processed (the "visitables").
45 : */
46 70847 : class ConstProcessorClient
47 : {
48 : public:
49 65752 : virtual ~ConstProcessorClient() {}
50 :
51 23780 : void Accept(
52 : ProcessorIfc & io_processor ) const
53 23780 : { do_Accept(io_processor); }
54 : private:
55 : virtual void do_Accept(
56 : ProcessorIfc & io_processor ) const = 0;
57 : };
58 :
59 :
60 : /** Typed base for "visitor" classes, leaving the visited
61 : object const.
62 :
63 : @see ProcessorIfc
64 : @see Processor<>
65 : */
66 : template <typename X, typename R = void>
67 22 : class ConstProcessor
68 : {
69 : public:
70 22 : virtual ~ConstProcessor() {}
71 :
72 18094 : R Process(
73 : const X & i_object )
74 18094 : { return do_Process(i_object ); }
75 : private:
76 : virtual R do_Process(
77 : const X & i_object ) = 0;
78 : };
79 :
80 :
81 : /** Typed base for "visitor" classes which may change the visited
82 : object.
83 :
84 : @see ProcessorIfc
85 : @see ConstProcessor<>
86 : */
87 : template <typename X, typename R = void>
88 : class Processor
89 : {
90 : public:
91 : virtual ~Processor() {}
92 :
93 : R Process(
94 : X & i_object )
95 : { return do_Process(i_object ); }
96 : private:
97 : virtual R do_Process(
98 : X & i_object ) = 0;
99 : };
100 :
101 :
102 : template <class C>
103 : inline void
104 23780 : CheckedCall( ProcessorIfc & io_processor,
105 : const C & i_client )
106 : {
107 : ConstProcessor<C> *
108 : pProcessor = dynamic_cast< csv::ConstProcessor<C> * >
109 23780 : (&io_processor);
110 23780 : if (pProcessor != 0)
111 18094 : pProcessor->Process(i_client);
112 23780 : }
113 :
114 : template <class C>
115 : inline void
116 : CheckedCall( ProcessorIfc & io_processor,
117 : C & io_client )
118 : {
119 : Processor<C> *
120 : pProcessor = dynamic_cast< csv::Processor<C> * >
121 : (&io_processor);
122 : if (pProcessor != 0)
123 : pProcessor->Process(io_client);
124 : }
125 :
126 : } // namespace csv
127 : #endif
128 :
129 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|