# HG changeset patch # User František Kučera # Date 1625331375 -7200 # Node ID 114810ee23861762aa773c80dde794595e38d895 # Parent 8941a679299f95daafdfa29479d9233a3a422b05 replace macro with ProxyVector that forwards method calls to all its elements diff -r 8941a679299f -r 114810ee2386 nbproject/configurations.xml --- a/nbproject/configurations.xml Fri Jul 02 00:42:01 2021 +0200 +++ b/nbproject/configurations.xml Sat Jul 03 18:56:15 2021 +0200 @@ -50,6 +50,7 @@ BasicASN1Reader.h DOMBuildingXMLContentHandler.h GenericASN1ContentHandler.h + ProxyVector.h TransactionalBuffer.h XMLContentHandler.h @@ -133,6 +134,8 @@ tool="3" flavor2="0"> + + @@ -198,6 +201,8 @@ tool="3" flavor2="0"> + + diff -r 8941a679299f -r 114810ee2386 src/lib/ASN1ContentHandler.h --- a/src/lib/ASN1ContentHandler.h Fri Jul 02 00:42:01 2021 +0200 +++ b/src/lib/ASN1ContentHandler.h Sat Jul 03 18:56:15 2021 +0200 @@ -22,6 +22,8 @@ #include #include +#include "ProxyVector.h" + namespace relpipe { namespace in { namespace asn1 { @@ -264,65 +266,61 @@ class ASN1ContentHandlerProxy : public ASN1ContentHandler { private: - std::vector> handlers; + ProxyVector handlers; public: void addHandler(std::shared_ptr handler) { handlers.push_back(handler); } -#define handler for (auto ___h : handlers) ___h - void writeStreamStart() override { - handler->writeStreamStart(); + handlers.forward(&ASN1ContentHandler::writeStreamStart); } void writeStreamEnd() override { - handler->writeStreamEnd(); + handlers.forward(&ASN1ContentHandler::writeStreamEnd); } void writeCollectionStart(CollectionType type) override { - handler->writeCollectionStart(type); + handlers.forward(&ASN1ContentHandler::writeCollectionStart, type); } void writeCollectionEnd() override { - handler->writeCollectionEnd(); + handlers.forward(&ASN1ContentHandler::writeCollectionEnd); } void writeBoolean(bool value) override { - handler->writeBoolean(value); + handlers.forward(&ASN1ContentHandler::writeBoolean, value); } void writeNull() override { - handler->writeNull(); + handlers.forward(&ASN1ContentHandler::writeNull); } void writeInteger(Integer value) override { - handler->writeInteger(value); + handlers.forward(&ASN1ContentHandler::writeInteger, value); } void writeTextString(StringType type, std::string value) override { - handler->writeTextString(type, value); + handlers.forward(&ASN1ContentHandler::writeTextString, type, value); } void writeOctetString(std::string value) override { - handler->writeOctetString(value); + handlers.forward(&ASN1ContentHandler::writeOctetString, value); } void writeBitString(std::vector value) override { - handler->writeBitString(value); + handlers.forward(&ASN1ContentHandler::writeBitString, value); } void writeOID(ObjectIdentifier value) override { - handler->writeOID(value); + handlers.forward(&ASN1ContentHandler::writeOID, value); } void writeDateTime(DateTimeType type, DateTime value) override { - handler->writeDateTime(type, value); + handlers.forward(&ASN1ContentHandler::writeDateTime, type, value); } -#undef handler - }; diff -r 8941a679299f -r 114810ee2386 src/lib/ProxyVector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/ProxyVector.h Sat Jul 03 18:56:15 2021 +0200 @@ -0,0 +1,47 @@ +/** + * 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 . + */ +#pragma once + +#include + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +template +class ProxyVector : public std::vector> { +public: + + /** + * Call given method on all instances. + * + * @param method a method of Class + * @param arguments arguments of the method + */ + template void forward(Method method, Arguments&&... arguments) { + for (auto& h : * this) { + // TODO: optionally handle/collect exceptions + (h.get()->*method)(arguments...); + } + } +}; + +} +} +} +} diff -r 8941a679299f -r 114810ee2386 src/lib/XMLContentHandler.h --- a/src/lib/XMLContentHandler.h Fri Jul 02 00:42:01 2021 +0200 +++ b/src/lib/XMLContentHandler.h Sat Jul 03 18:56:15 2021 +0200 @@ -16,7 +16,7 @@ */ #pragma once -#include +#include "ProxyVector.h" namespace relpipe { namespace in { @@ -39,33 +39,29 @@ class XMLContentHandlerProxy : XMLContentHandler { private: - std::vector> handlers; + ProxyVector handlers; public: void addHandler(std::shared_ptr handler) { handlers.push_back(handler); } -#define handler for (auto ___h : handlers) ___h - void writeStartElement(const std::string& name, const std::vector& attributes = {}) override { - handler->writeStartElement(name, attributes); + handlers.forward(&XMLContentHandler::writeStartElement, name, attributes); } void writeEndElement() override { - handler->writeEndElement(); + handlers.forward(&XMLContentHandler::writeEndElement); } void writeCharacters(const std::string& value) override { - handler->writeCharacters(value); + handlers.forward(&XMLContentHandler::writeCharacters, value); } void writeComment(const std::string& value, bool addSpaces = true) override { - handler->writeComment(value, addSpaces); + handlers.forward(&XMLContentHandler::writeComment, value, addSpaces); } -#undef handler - }; }