30 AbstractParserImpl(AbstractParser* interface) : interface(interface) { |
30 AbstractParserImpl(AbstractParser* interface) : interface(interface) { |
31 } |
31 } |
32 |
32 |
33 virtual ~AbstractParserImpl() { |
33 virtual ~AbstractParserImpl() { |
34 } |
34 } |
35 |
|
36 void write(const char* buffer, const size_t length) { |
|
37 // TODO: update pointers and positions |
|
38 try { |
|
39 // TODO: call an overridable method to get preferred minimum block size and run cycle only if we have enough data or EOF |
|
40 interface->update(); |
|
41 commit(); |
|
42 } catch (const AbstractParser::ReadBufferUnderflowException& e) { |
|
43 rollback(); |
|
44 } catch (const AbstractParser::ExplicitRollbackException& e) { |
|
45 rollback(); |
|
46 } |
|
47 } |
|
48 |
|
49 void rollback() { |
|
50 // FIXME: store content of the current buffer + update pointers and positions |
|
51 // TODO: notify rollback listeners? (they can monitor the performance / frequency of rollbacks) |
|
52 } |
|
53 |
|
54 void commit() { |
|
55 } |
|
56 |
|
57 void read(char* buffer, const size_t length) { |
|
58 } |
|
59 |
|
60 void peek(char* buffer, const size_t length) { |
|
61 } |
|
62 }; |
35 }; |
63 |
36 |
64 AbstractParser::AbstractParser() { |
37 AbstractParser::AbstractParser() { |
65 implementation = new AbstractParserImpl(this); |
38 implementation = new AbstractParserImpl(this); |
66 } |
39 } |
67 |
40 |
68 AbstractParser::~AbstractParser() { |
41 AbstractParser::~AbstractParser() { |
69 delete (AbstractParserImpl*) implementation; |
42 delete implementation; |
70 } |
43 } |
71 |
44 |
72 void AbstractParser::write(const char* buffer, const size_t length) { |
45 void AbstractParser::write(const char* buffer, const size_t length) { |
73 ((AbstractParserImpl*) implementation)->write(buffer, length); |
46 // TODO: update pointers and positions |
|
47 try { |
|
48 // TODO: call an overridable method to get preferred minimum block size and run cycle only if we have enough data or EOF |
|
49 update(); |
|
50 commit(); |
|
51 } catch (const AbstractParser::ReadBufferUnderflowException& e) { |
|
52 rollback(); |
|
53 } catch (const AbstractParser::ExplicitRollbackException& e) { |
|
54 rollback(); |
|
55 } |
|
56 } |
|
57 |
|
58 void AbstractParser::rollback() { |
|
59 // FIXME: store content of the current buffer + update pointers and positions |
|
60 // TODO: notify rollback listeners? (they can monitor the performance / frequency of rollbacks) |
74 } |
61 } |
75 |
62 |
76 void AbstractParser::commit() { |
63 void AbstractParser::commit() { |
77 ((AbstractParserImpl*) implementation)->commit(); |
|
78 } |
|
79 |
|
80 void AbstractParser::rollback() { |
|
81 ((AbstractParserImpl*) implementation)->rollback(); |
|
82 } |
64 } |
83 |
65 |
84 void AbstractParser::read(char* buffer, const size_t length) { |
66 void AbstractParser::read(char* buffer, const size_t length) { |
85 ((AbstractParserImpl*) implementation)->read(buffer, length); |
|
86 } |
67 } |
87 |
68 |
88 void AbstractParser::peek(char* buffer, const size_t length) { |
69 void AbstractParser::peek(char* buffer, const size_t length) { |
89 ((AbstractParserImpl*) implementation)->peek(buffer, length); |
|
90 } |
70 } |
91 |
71 |
92 } |
72 } |
93 } |
73 } |
94 } |
74 } |