1 #ifndef _XEXMLWRITER_HPP
2 #define _XEXMLWRITER_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Test Executor
5 * ------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 *//*--------------------------------------------------------------------*/
38 class EscapeStreambuf : public std::streambuf
41 EscapeStreambuf (std::ostream& dst) : m_dst(dst) {}
44 std::streamsize xsputn (const char* s, std::streamsize count);
45 int overflow (int ch = -1);
57 BeginElement (const char* element_) : element(element_) {}
64 Attribute (const char* name_, const char* value_) : name(name_), value(value_) {}
65 Attribute (const char* name_, const std::string& value_) : name(name_), value(value_) {}
66 Attribute (const std::string& name_, const std::string& value_) : name(name_), value(value_) {}
69 static const struct EndElementType {} EndElement;
71 Writer (std::ostream& dst);
74 Writer& operator<< (const BeginElement& begin);
75 Writer& operator<< (const Attribute& attribute);
76 Writer& operator<< (const EndElementType& end);
79 Writer& operator<< (const T& value); //!< Write data.
82 Writer (const Writer& other);
83 Writer& operator= (const Writer& other);
94 std::ostream& m_rawDst;
95 EscapeStreambuf m_dataBuf;
96 std::ostream m_dataStr;
98 std::vector<std::string> m_elementStack;
101 template <typename T>
102 Writer& Writer::operator<< (const T& value)
104 if (m_state == STATE_ELEMENT)
108 m_state = STATE_DATA;
116 #endif // _XEXMLWRITER_HPP