src/lib/AbstractParser.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 14 Mar 2021 19:58:35 +0100
branchv_0
changeset 3 68026fe3aaf5
parent 2 8b8175615adb
child 10 6904e4448807
permissions -rw-r--r--
AbstractParser: documentation + close() method

/**
 * 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() {
	}
};

AbstractParser::AbstractParser() {
	implementation = new AbstractParserImpl(this);
}

AbstractParser::~AbstractParser() {
	delete implementation;
}

void AbstractParser::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
		update();
		commit();
	} catch (const AbstractParser::ReadBufferUnderflowException& e) {
		rollback();
	} catch (const AbstractParser::ExplicitRollbackException& e) {
		rollback();
	}
}

void AbstractParser::close() {
}

void AbstractParser::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 AbstractParser::commit() {
}

void AbstractParser::read(char* buffer, const size_t length) {
}

void AbstractParser::peek(char* buffer, const size_t length) {
}

}
}
}
}