AbstractParser: remove unnecessary delegation (put only private methods in AbstractParserImpl) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 13 Mar 2021 19:28:13 +0100
branchv_0
changeset 2 8b8175615adb
parent 1 2179f13227f4
child 3 68026fe3aaf5
AbstractParser: remove unnecessary delegation (put only private methods in AbstractParserImpl)
src/lib/AbstractParser.cpp
--- a/src/lib/AbstractParser.cpp	Sat Mar 13 17:58:09 2021 +0100
+++ b/src/lib/AbstractParser.cpp	Sat Mar 13 19:28:13 2021 +0100
@@ -32,33 +32,6 @@
 
 	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() {
@@ -66,30 +39,37 @@
 }
 
 AbstractParser::~AbstractParser() {
-	delete (AbstractParserImpl*) implementation;
+	delete implementation;
 }
 
 void AbstractParser::write(const char* buffer, const size_t length) {
-	((AbstractParserImpl*) implementation)->write(buffer, 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::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() {
-	((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);
 }
 
 }
 }
 }
-}
\ No newline at end of file
+}