AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
/**
* Relational pipes
* Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AbstractParser.h"
namespace relpipe {
namespace in {
namespace asn1 {
namespace lib {
class AbstractParserImpl {
private:
AbstractParser* interface;
public:
AbstractParserImpl(AbstractParser* interface) : interface(interface) {
}
virtual ~AbstractParserImpl() {
}
void write(const char* buffer, const size_t length) {
// TODO: update pointers and positions
try {
// TODO: call an overridable method to get preferred minimum block size and run cycle only if we have enough data or EOF
interface->update();
commit();
} catch (const AbstractParser::ReadBufferUnderflowException& e) {
rollback();
} catch (const AbstractParser::ExplicitRollbackException& e) {
rollback();
}
}
void rollback() {
// FIXME: store content of the current buffer + update pointers and positions
// TODO: notify rollback listeners? (they can monitor the performance / frequency of rollbacks)
}
void commit() {
}
void read(char* buffer, const size_t length) {
}
void peek(char* buffer, const size_t length) {
}
};
AbstractParser::AbstractParser() {
implementation = new AbstractParserImpl(this);
}
AbstractParser::~AbstractParser() {
delete (AbstractParserImpl*) implementation;
}
void AbstractParser::write(const char* buffer, const size_t length) {
((AbstractParserImpl*) implementation)->write(buffer, length);
}
void AbstractParser::commit() {
((AbstractParserImpl*) implementation)->commit();
}
void AbstractParser::rollback() {
((AbstractParserImpl*) implementation)->rollback();
}
void AbstractParser::read(char* buffer, const size_t length) {
((AbstractParserImpl*) implementation)->read(buffer, length);
}
void AbstractParser::peek(char* buffer, const size_t length) {
((AbstractParserImpl*) implementation)->peek(buffer, length);
}
}
}
}
}