src/lib/XMLContentHandler.h
branchv_0
changeset 9 7a6abdd00ab5
parent 7 afb7f3a4981a
child 24 114810ee2386
equal deleted inserted replaced
8:d37c1a5d09ce 9:7a6abdd00ab5
    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>
       
    20 
    19 namespace relpipe {
    21 namespace relpipe {
    20 namespace in {
    22 namespace in {
    21 namespace asn1 {
    23 namespace asn1 {
    22 namespace lib {
    24 namespace lib {
    23 
    25 
    24 class XMLContentHandler {
    26 class XMLContentHandler {
    25 public:
    27 public:
    26 
    28 
    27 	virtual ~XMLContentHandler() = default;
    29 	virtual ~XMLContentHandler() = default;
    28 
    30 
       
    31 	// FIXME: namespaces, check names
       
    32 
    29 	virtual void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) = 0;
    33 	virtual void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) = 0;
    30 	virtual void writeEndElement() = 0;
    34 	virtual void writeEndElement() = 0;
    31 	virtual void writeCharacters(const std::string& text) = 0;
    35 	virtual void writeCharacters(const std::string& value) = 0;
    32 	virtual void writeComment(const std::string& text, bool addSpaces = true) = 0;
    36 	virtual void writeComment(const std::string& value, bool addSpaces = true) = 0;
    33 
    37 
    34 };
    38 };
    35 
    39 
    36 class XMLContentHandlerProxy : XMLContentHandler {
    40 class XMLContentHandlerProxy : XMLContentHandler {
    37 private:
    41 private:
    42 		handlers.push_back(handler);
    46 		handlers.push_back(handler);
    43 	}
    47 	}
    44 
    48 
    45 #define handler for (auto ___h : handlers) ___h
    49 #define handler for (auto ___h : handlers) ___h
    46 
    50 
    47 	void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) {
    51 	void writeStartElement(const std::string& name, const std::vector<std::string>& attributes = {}) override {
    48 		handler->writeStartElement(name, attributes);
    52 		handler->writeStartElement(name, attributes);
    49 	}
    53 	}
    50 
    54 
    51 	void writeEndElement() {
    55 	void writeEndElement() override {
    52 		handler->writeEndElement();
    56 		handler->writeEndElement();
    53 	}
    57 	}
    54 
    58 
    55 	void writeCharacters(const std::string& text) {
    59 	void writeCharacters(const std::string& value) override {
    56 		handler->writeCharacters(text);
    60 		handler->writeCharacters(value);
    57 	}
    61 	}
    58 
    62 
    59 	void writeComment(const std::string& text, bool addSpaces = true) {
    63 	void writeComment(const std::string& value, bool addSpaces = true) override {
    60 		handler->writeComment(text, addSpaces);
    64 		handler->writeComment(value, addSpaces);
    61 	}
    65 	}
    62 
    66 
    63 #undef handler
    67 #undef handler
    64 
    68 
    65 };
    69 };