src/lib/XMLContentHandler.h
branchv_0
changeset 24 114810ee2386
parent 9 7a6abdd00ab5
child 40 85b6f13f1088
equal deleted inserted replaced
23:8941a679299f 24:114810ee2386
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    16  */
    17 #pragma once
    17 #pragma once
    18 
    18 
    19 #include <vector>
    19 #include "ProxyVector.h"
    20 
    20 
    21 namespace relpipe {
    21 namespace relpipe {
    22 namespace in {
    22 namespace in {
    23 namespace asn1 {
    23 namespace asn1 {
    24 namespace lib {
    24 namespace lib {
    37 
    37 
    38 };
    38 };
    39 
    39 
    40 class XMLContentHandlerProxy : XMLContentHandler {
    40 class XMLContentHandlerProxy : XMLContentHandler {
    41 private:
    41 private:
    42 	std::vector<std::shared_ptr<XMLContentHandler>> handlers;
    42 	ProxyVector<XMLContentHandler> handlers;
    43 public:
    43 public:
    44 
    44 
    45 	void addHandler(std::shared_ptr<XMLContentHandler> handler) {
    45 	void addHandler(std::shared_ptr<XMLContentHandler> handler) {
    46 		handlers.push_back(handler);
    46 		handlers.push_back(handler);
    47 	}
    47 	}
    48 
    48 
    49 #define handler for (auto ___h : handlers) ___h
       
    50 
       
    51 	void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) override {
    49 	void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) override {
    52 		handler->writeStartElement(name, attributes);
    50 		handlers.forward(&XMLContentHandler::writeStartElement, name, attributes);
    53 	}
    51 	}
    54 
    52 
    55 	void writeEndElement() override {
    53 	void writeEndElement() override {
    56 		handler->writeEndElement();
    54 		handlers.forward(&XMLContentHandler::writeEndElement);
    57 	}
    55 	}
    58 
    56 
    59 	void writeCharacters(const std::string& value) override {
    57 	void writeCharacters(const std::string& value) override {
    60 		handler->writeCharacters(value);
    58 		handlers.forward(&XMLContentHandler::writeCharacters, value);
    61 	}
    59 	}
    62 
    60 
    63 	void writeComment(const std::string& value, bool addSpaces = true) override {
    61 	void writeComment(const std::string& value, bool addSpaces = true) override {
    64 		handler->writeComment(value, addSpaces);
    62 		handlers.forward(&XMLContentHandler::writeComment, value, addSpaces);
    65 	}
    63 	}
    66 
       
    67 #undef handler
       
    68 
    64 
    69 };
    65 };
    70 
    66 
    71 }
    67 }
    72 }
    68 }