|
1 /** |
|
2 * Relational pipes |
|
3 * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, version 3 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 #pragma once |
|
18 |
|
19 #include <cstring> |
|
20 |
|
21 namespace relpipe { |
|
22 namespace in { |
|
23 namespace asn1 { |
|
24 namespace lib { |
|
25 |
|
26 class AbstractParserImpl; |
|
27 |
|
28 class AbstractParser { |
|
29 private: |
|
30 friend AbstractParserImpl; |
|
31 AbstractParserImpl* implementation; |
|
32 public: |
|
33 virtual ~AbstractParser(); |
|
34 void write(const char* buffer, const size_t length); |
|
35 void rollback(); |
|
36 protected: |
|
37 AbstractParser(); |
|
38 |
|
39 /** |
|
40 * Is thrown from read() and peak() methods if there are not enough data. |
|
41 * Interrupts current update() cycle and causes rollback. |
|
42 */ |
|
43 class ReadBufferUnderflowException { |
|
44 // TODO: common super-class for exceptions, hidden implementation |
|
45 }; |
|
46 |
|
47 /** |
|
48 * May be thrown from the update() method in order to cancel currenty cycle and do explicit rollback. |
|
49 * Same data will be processed in the next cycle. |
|
50 */ |
|
51 class ExplicitRollbackException { |
|
52 // TODO: common super-class for exceptions, hidden implementation |
|
53 }; |
|
54 |
|
55 /** |
|
56 * May be called from the update() method in order to explicitly confirm that read data was successfully processed. |
|
57 * Such data will not be processed again during the next cycle (even if ReadBufferUnderflowException occurs later in this cycle). |
|
58 |
|
59 * Explicit commit() call is useful when we did some demanding work (so we are not willing to do it again in case of ReadBufferUnderflowException); |
|
60 * and is necessary when we already published some outputs or did other non-idempotent operation or caused some other significant side effects. |
|
61 |
|
62 * If there is no commit() called and update() just finishes, commit() is called implicitly. |
|
63 * |
|
64 * Note: There is no accessible rollback() method – throw ExplicitRollbackException instead. |
|
65 */ |
|
66 void commit(); |
|
67 |
|
68 /** |
|
69 * |
|
70 * @param buffer |
|
71 * @param length |
|
72 */ |
|
73 void read(char* buffer, const size_t length); |
|
74 |
|
75 /** |
|
76 * |
|
77 * @param buffer |
|
78 * @param length |
|
79 */ |
|
80 void peek(char* buffer, const size_t length); |
|
81 |
|
82 /** |
|
83 * |
|
84 */ |
|
85 virtual void update() = 0; |
|
86 }; |
|
87 |
|
88 } |
|
89 } |
|
90 } |
|
91 } |