src/lib/SAXContentHandler.h
branchv_0
changeset 6 6a4a348426d9
parent 4 7230e1ea0b07
equal deleted inserted replaced
5:15c3221e66af 6:6a4a348426d9
    24 class SAXContentHandler {
    24 class SAXContentHandler {
    25 public:
    25 public:
    26 
    26 
    27 	virtual ~SAXContentHandler() = default;
    27 	virtual ~SAXContentHandler() = default;
    28 
    28 
    29 	virtual void abc() = 0; // FIXME: remove dummy method
    29 	virtual void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) = 0;
    30 	virtual void def(int a) = 0; // FIXME: remove dummy method
    30 	virtual void writeEndElement() = 0;
    31 	virtual void ghi(int a, int b) = 0; // FIXME: remove dummy method
    31 	virtual void writeCharacters(const std::string& text) = 0;
       
    32 	virtual void writeComment(const std::string& text, bool addSpaces = true) = 0;
    32 
    33 
    33 };
    34 };
    34 
    35 
    35 class SAXContentHandlerProxy : public SAXContentHandler {
    36 class SAXContentHandlerProxy : SAXContentHandler {
    36 private:
    37 private:
    37 	std::vector<std::shared_ptr<SAXContentHandler>> handlers;
    38 	std::vector<std::shared_ptr<SAXContentHandler>> handlers;
    38 public:
    39 public:
    39 
    40 
    40 	void addHandler(std::shared_ptr<SAXContentHandler> handler) {
    41 	void addHandler(std::shared_ptr<SAXContentHandler> handler) {
    41 		handlers.push_back(handler);
    42 		handlers.push_back(handler);
    42 	}
    43 	}
    43 
    44 
    44 #define handler for (auto ___h : handlers) ___h
    45 #define handler for (auto ___h : handlers) ___h
    45 
    46 
    46 	void abc() override {
    47 	void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) {
    47 		handler->abc();
    48 		handler->writeStartElement(name, attributes);
    48 	}
    49 	}
    49 
    50 
    50 	void def(int a) override {
    51 	void writeEndElement() {
    51 		handler->def(a);
    52 		handler->writeEndElement();
    52 	}
    53 	}
    53 
    54 
    54 	void ghi(int a, int b) override {
    55 	void writeCharacters(const std::string& text) {
    55 		handler->ghi(a, b);
    56 		handler->writeCharacters(text);
       
    57 	}
       
    58 
       
    59 	void writeComment(const std::string& text, bool addSpaces = true) {
       
    60 		handler->writeComment(text, addSpaces);
    56 	}
    61 	}
    57 
    62 
    58 #undef handler
    63 #undef handler
    59 
    64 
    60 };
    65 };