[834] | 1 | // Copyright FreeHEP, 2005. |
---|
| 2 | #ifndef CHEPREP_XMLWRITER_H |
---|
| 3 | #define CHEPREP_XMLWRITER_H 1 |
---|
| 4 | |
---|
| 5 | #include "cheprep/config.h" |
---|
| 6 | |
---|
| 7 | #include <iostream> |
---|
| 8 | #include <map> |
---|
| 9 | #include <stack> |
---|
| 10 | #include <vector> |
---|
| 11 | #include <string> |
---|
| 12 | |
---|
| 13 | #include "cheprep/AbstractXMLWriter.h" |
---|
| 14 | #include "cheprep/IndentPrintWriter.h" |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * @author Mark Donszelmann |
---|
| 18 | * @version $Id: XMLWriter.h,v 1.3 2005/06/02 21:28:45 duns Exp $ |
---|
| 19 | */ |
---|
| 20 | namespace cheprep { |
---|
| 21 | |
---|
| 22 | class XMLWriter : public AbstractXMLWriter { |
---|
| 23 | |
---|
| 24 | public: |
---|
| 25 | XMLWriter(std::ostream* out, std::string indentString = " ", std::string defaultNameSpace = ""); |
---|
| 26 | virtual ~XMLWriter(); |
---|
| 27 | void close(); |
---|
| 28 | void openDoc(std::string version = "1.0", std::string encoding = "", bool standalone = false); |
---|
| 29 | void referToDTD(std::string name, std::string pid, std::string ref); |
---|
| 30 | void referToDTD(std::string name, std::string system); |
---|
| 31 | void closeDoc(bool force = false); |
---|
| 32 | void printComment(std::string comment); |
---|
| 33 | void printPlain(std::string text); |
---|
| 34 | void print(std::string text); |
---|
| 35 | void println(std::string text); |
---|
| 36 | void openTag(std::string name); |
---|
| 37 | void closeTag(); |
---|
| 38 | void printTag(std::string name); |
---|
| 39 | void setAttribute(std::string name, char* value); |
---|
| 40 | void setAttribute(std::string name, std::string value); |
---|
| 41 | void setAttribute(std::string name, std::vector<double> value); |
---|
| 42 | void setAttribute(std::string name, int64 value); |
---|
| 43 | void setAttribute(std::string name, int value); |
---|
| 44 | void setAttribute(std::string name, bool value); |
---|
| 45 | void setAttribute(std::string name, double value); |
---|
| 46 | void printAttributes(int tagLength); |
---|
| 47 | std::string normalize(std::string s); |
---|
| 48 | std::string normalizeText(std::string s); |
---|
| 49 | void checkNameValid(std::string s); |
---|
| 50 | |
---|
| 51 | // |
---|
| 52 | // Can be removed when we can properly inherit those (since names are equal to overloaded ones). |
---|
| 53 | // |
---|
| 54 | void openTag(std::string ns, std::string name) { |
---|
| 55 | openTag(ns == defaultNameSpace ? name : ns.append(":").append(name)); |
---|
| 56 | } |
---|
| 57 | void printTag(std::string ns, std::string name) { |
---|
| 58 | printTag(ns == defaultNameSpace ? name : ns.append(":").append(name)); |
---|
| 59 | } |
---|
| 60 | void setAttribute(std::string ns, std::string name, std::string value) { |
---|
| 61 | setAttribute(ns.append(":").append(name), value); |
---|
| 62 | } |
---|
| 63 | void setAttribute(std::string ns, std::string name, double value) { |
---|
| 64 | setAttribute(ns.append(":").append(name), value); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | protected: |
---|
| 70 | bool closed; |
---|
| 71 | IndentPrintWriter* writer; |
---|
| 72 | |
---|
| 73 | private: |
---|
| 74 | std::string dtdName; |
---|
| 75 | std::map<std::string, std::string> attributes; |
---|
| 76 | std::stack<std::string> openTags; |
---|
| 77 | }; |
---|
| 78 | |
---|
| 79 | } // cheprep |
---|
| 80 | |
---|
| 81 | #endif |
---|