CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
xml_text_writer.h
1
2
3#pragma once
4
5#include <xml/xml_writer.h>
6#include <xml/xml_space.h>
7#include <xml/xml_char_type.h>
8#include <xml/write_state.h>
9#include <xml/formatting.h>
10#include <system/array.h>
11#include <cstdint>
12
13
15namespace System
16{
17namespace Collections
18{
19namespace Generic
20{
21template <typename, typename> class Dictionary;
22} // namespace Generic
23} // namespace Collections
24namespace IO
25{
26class Stream;
27class TextWriter;
28} // namespace IO
29namespace Text
30{
31class Encoding;
32} // namespace Text
33namespace Xml
34{
35class XmlTextEncoder;
36class XmlTextWriterBase64Encoder;
37} // namespace Xml
38} // namespace System
40
41namespace System {
42
43namespace Xml {
44
51class ASPOSECPP_SHARED_CLASS XmlTextWriter : public XmlWriter
52{
53 typedef XmlTextWriter ThisType;
54 typedef XmlWriter BaseType;
55
56 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
57 ASPOSECPP_SHARED_RTTI_INFO_DECL();
58
59public:
60
63
64public:
65 using XmlWriter::XmlWriter::WriteStartElement;
66
67public:
68 using XmlWriter::XmlWriter::WriteStartAttribute;
69
70private:
71
72 enum class NamespaceState
73 {
74 Uninitialized,
75 NotDeclaredButInScope,
76 DeclaredButNotWrittenOut,
77 DeclaredAndWrittenOut
78 };
79
80 enum class SpecialAttr
81 {
82 None,
84 XmlLang,
85 XmlNs
86 };
87
88 enum class State
89 {
90 Start,
91 Prolog,
92 PostDTD,
93 Element,
95 Content,
96 AttrOnly,
97 Epilog,
98 Error,
99 Closed
100 };
101
102 enum class Token
103 {
104 PI,
105 Doctype,
106 Comment,
107 CData,
108 StartElement,
109 EndElement,
110 LongEndElement,
111 StartAttribute,
112 EndAttribute,
113 Content,
114 Base64,
115 RawData,
116 Whitespace,
117 Empty
118 };
119
120
121private:
122
123 class TagInfo : public System::Object
124 {
125 typedef TagInfo ThisType;
126 typedef System::Object BaseType;
127
128 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
129 RTTI_INFO_DECL();
130
131 public:
132
134 String name;
135 String prefix;
136 String defaultNs;
137 XmlTextWriter::NamespaceState defaultNsState;
138 XmlSpace xmlSpace;
139 String xmlLang;
140 int32_t prevNsTop;
141 int32_t prefixCount;
142 bool mixed;
143
144 void Init(int32_t nsTop);
146
147 TagInfo();
148
149 protected:
150
151 #ifdef ASPOSE_GET_SHARED_MEMBERS
152 void GetSharedMembers(System::Object::shared_members_type& result) const override;
153 #endif
154
155
156 };
157
158 class Namespace : public System::Object
159 {
160 typedef Namespace ThisType;
161 typedef System::Object BaseType;
162
163 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
164 RTTI_INFO_DECL();
165
166 public:
167
169 String prefix;
170 String ns;
171 bool declared;
172 int32_t prevNsIndex;
173
174 void Set(const String& prefix, const String& ns, bool declared);
176
177 Namespace();
178
179 };
180
181
182public:
183
187 ASPOSECPP_SHARED_API SharedPtr<IO::Stream> get_BaseStream();
191 ASPOSECPP_SHARED_API bool get_Namespaces();
195 ASPOSECPP_SHARED_API void set_Namespaces(bool value);
201 ASPOSECPP_SHARED_API void set_Formatting(System::Xml::Formatting value);
205 ASPOSECPP_SHARED_API int32_t get_Indentation();
210 ASPOSECPP_SHARED_API void set_Indentation(int32_t value);
213 ASPOSECPP_SHARED_API char16_t get_IndentChar();
216 ASPOSECPP_SHARED_API void set_IndentChar(char16_t value);
220 ASPOSECPP_SHARED_API char16_t get_QuoteChar();
224 ASPOSECPP_SHARED_API void set_QuoteChar(char16_t value);
227 ASPOSECPP_SHARED_API System::Xml::WriteState get_WriteState() override;
240 ASPOSECPP_SHARED_API System::Xml::XmlSpace get_XmlSpace() override;
243 ASPOSECPP_SHARED_API String get_XmlLang() override;
244
252 ASPOSECPP_SHARED_API XmlTextWriter(const SharedPtr<IO::Stream>& w, const SharedPtr<Text::Encoding>& encoding);
266 ASPOSECPP_SHARED_API XmlTextWriter(const String& filename, const SharedPtr<Text::Encoding>& encoding);
269 ASPOSECPP_SHARED_API XmlTextWriter(const SharedPtr<IO::TextWriter>& w);
270
273 ASPOSECPP_SHARED_API void WriteStartDocument() override;
277 ASPOSECPP_SHARED_API void WriteStartDocument(bool standalone) override;
280 ASPOSECPP_SHARED_API void WriteEndDocument() override;
289 ASPOSECPP_SHARED_API void WriteDocType(const String& name, const String& pubid, const String& sysid, const String& subset) override;
296 ASPOSECPP_SHARED_API void WriteStartElement(const String& prefix, const String& localName, const String& ns) override;
298 ASPOSECPP_SHARED_API void WriteEndElement() override;
300 ASPOSECPP_SHARED_API void WriteFullEndElement() override;
306 ASPOSECPP_SHARED_API void WriteStartAttribute(const String& prefix, const String& localName, const String& ns) override;
308 ASPOSECPP_SHARED_API void WriteEndAttribute() override;
313 ASPOSECPP_SHARED_API void WriteCData(String text) override;
318 ASPOSECPP_SHARED_API void WriteComment(String text) override;
326 ASPOSECPP_SHARED_API void WriteProcessingInstruction(String name, String text) override;
330 ASPOSECPP_SHARED_API void WriteEntityRef(const String& name) override;
336 ASPOSECPP_SHARED_API void WriteCharEntity(char16_t ch) override;
340 ASPOSECPP_SHARED_API void WriteWhitespace(String ws) override;
344 ASPOSECPP_SHARED_API void WriteString(const String& text) override;
349 ASPOSECPP_SHARED_API void WriteSurrogateCharEntity(char16_t lowChar, char16_t highChar) override;
359 ASPOSECPP_SHARED_API void WriteChars(ArrayPtr<char16_t> buffer, int32_t index, int32_t count) override;
367 ASPOSECPP_SHARED_API void WriteRaw(ArrayPtr<char16_t> buffer, int32_t index, int32_t count) override;
370 ASPOSECPP_SHARED_API void WriteRaw(const String& data) override;
379 ASPOSECPP_SHARED_API void WriteBase64(ArrayPtr<uint8_t> buffer, int32_t index, int32_t count) override;
388 ASPOSECPP_SHARED_API void WriteBinHex(ArrayPtr<uint8_t> buffer, int32_t index, int32_t count) override;
390 ASPOSECPP_SHARED_API void Close() override;
392 ASPOSECPP_SHARED_API void Flush() override;
397 ASPOSECPP_SHARED_API void WriteName(const String& name) override;
403 ASPOSECPP_SHARED_API void WriteQualifiedName(const String& localName, const String& ns) override;
408 ASPOSECPP_SHARED_API String LookupPrefix(String ns) override;
413 ASPOSECPP_SHARED_API void WriteNmToken(const String& name) override;
414
415protected:
416
419 MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(XmlTextWriter, CODEPORTING_ARGS());
421
422 virtual ASPOSECPP_SHARED_API ~XmlTextWriter();
423
425 #ifdef ASPOSE_GET_SHARED_MEMBERS
426 ASPOSECPP_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
427 #endif
429
430private:
431
432 SharedPtr<IO::TextWriter> _textWriter;
433 SharedPtr<XmlTextEncoder> _xmlEncoder;
435 System::Xml::Formatting _formatting;
436 bool _indented;
437 int32_t _indentation;
438 char16_t _indentChar;
440 int32_t _top;
442 XmlTextWriter::State _currentState;
443 XmlTextWriter::Token _lastToken;
445 char16_t _quoteChar;
446 char16_t _curQuoteChar;
447 bool _namespaces;
448 XmlTextWriter::SpecialAttr _specialAttr;
449 String _prefixForXmlNs;
450 bool _flush;
452 int32_t _nsTop;
454 bool _useNsHashtable;
455 XmlCharType _xmlCharType;
456 static const int32_t NamespaceStackInitialSize;
457 static const int32_t MaxNamespacesWalkCount;
458 static ArrayPtr<String> s_stateName;
459 static ArrayPtr<String> s_tokenName;
460 static ArrayPtr<XmlTextWriter::State> s_stateTableDefault;
461 static ArrayPtr<XmlTextWriter::State> s_stateTableDocument;
462
463 String PrepareElementPrefix(const String& prefix, const String& ns);
464 String PrepareAttributePrefix(const String& prefix, const String*& localName, const String& ns);
465 void StartDocument(int32_t standalone);
466 void AutoComplete(XmlTextWriter::Token token);
467 void AutoCompleteAll();
468 void InternalWriteEndElement(bool longFormat);
469 void WriteEndStartTag(bool empty);
470 void WriteEndAttributeQuote();
471 void Indent(bool beforeEndElement);
472 void PushNamespace(const String& prefix, const String& ns, bool declared);
473 void AddNamespace(const String& prefix, const String& ns, bool declared);
474 void AddToNamespaceHashtable(int32_t namespaceIndex);
475 void PopNamespaces(int32_t indexFrom, int32_t indexTo);
476 String GeneratePrefix();
477 void InternalWriteProcessingInstruction(const String& name, const String& text);
478 int32_t LookupNamespace(const String& prefix);
479 int32_t LookupNamespaceInCurrentScope(const String& prefix);
480 String FindPrefix(const String& ns);
481 void InternalWriteName(const String& name, bool isNCName);
482 void ValidateName(const String& name, bool isNCName);
483 void HandleSpecialAttribute();
484 void VerifyPrefixXml(const String& prefix, const String& ns);
485 void PushStack();
486 void FlushEncoders();
487
488 static struct __StaticConstructor__ { __StaticConstructor__(); } s_constructor__;
489
490};
491
492} // namespace Xml
493} // namespace System
494
495
A base class for custom attributes. Objects of this class should only be allocated using System::Make...
Definition: attribute.h:16
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
For internal purposes. Do not use this class directly.
Definition: xml_char_type.h:61
Represents a writer that provides a fast, non-cached, forward-only way of generating streams or files...
Definition: xml_text_writer.h:52
void WriteName(const String &name) override
Writes out the specified name, ensuring it is a valid name according to the W3C XML 1....
System::Xml::WriteState get_WriteState() override
Returns the state of the writer.
void WriteStartDocument() override
Writes the XML declaration with the version "1.0".
void WriteWhitespace(String ws) override
Writes out the given white space.
void Close() override
Closes this stream and the underlying stream.
bool get_Namespaces()
Returns a value indicating whether to do namespace support.
System::Xml::Formatting get_Formatting()
Indicates how the output is formatted.
void WriteComment(String text) override
Writes out a comment containing the specified text.
void WriteQualifiedName(const String &localName, const String &ns) override
Writes out the namespace-qualified name. This method looks up the prefix that is in scope for the giv...
void WriteChars(ArrayPtr< char16_t > buffer, int32_t index, int32_t count) override
Writes text one buffer at a time.
void set_Indentation(int32_t value)
Sets how many IndentChars to write for each level in the hierarchy when XmlTextWriter::set_Formatting...
void WriteCData(String text) override
Writes out a ... block containing the specified text.
void WriteStartElement(const String &prefix, const String &localName, const String &ns) override
Writes the specified start tag and associates it with the given namespace and prefix.
void WriteString(const String &text) override
Writes the given text content.
void WriteRaw(const String &data) override
Writes raw markup manually from a string.
void WriteSurrogateCharEntity(char16_t lowChar, char16_t highChar) override
Generates and writes the surrogate character entity for the surrogate character pair.
void WriteNmToken(const String &name) override
Writes out the specified name, ensuring it is a valid NmToken according to the W3C XML 1....
String LookupPrefix(String ns) override
Returns the closest prefix defined in the current namespace scope for the namespace URI.
void WriteBinHex(ArrayPtr< uint8_t > buffer, int32_t index, int32_t count) override
Encodes the specified binary bytes as binhex and writes out the resulting text.
void WriteFullEndElement() override
Closes one element and pops the corresponding namespace scope.
void set_QuoteChar(char16_t value)
Sets which character to use to quote attribute values.
void WriteDocType(const String &name, const String &pubid, const String &sysid, const String &subset) override
Writes the DOCTYPE declaration with the specified name and optional attributes.
String get_XmlLang() override
Returns the current xml:lang scope.
System::Xml::XmlSpace get_XmlSpace() override
Returns an XmlSpace representing the current xml:space scope.
void WriteStartDocument(bool standalone) override
Writes the XML declaration with the version "1.0" and the standalone attribute.
void WriteProcessingInstruction(String name, String text) override
Writes out a processing instruction with a space between the name and text as follows: <?...
void set_Formatting(System::Xml::Formatting value)
Indicates how the output is formatted.
void WriteEndElement() override
Closes one element and pops the corresponding namespace scope.
XmlTextWriter(const String &filename, const SharedPtr< Text::Encoding > &encoding)
Creates an instance of the XmlTextWriter class using the specified file.
int32_t get_Indentation()
Returns how many IndentChars to write for each level in the hierarchy when XmlTextWriter::set_Formatt...
void WriteCharEntity(char16_t ch) override
Forces the generation of a character entity for the specified Unicode character value.
char16_t get_QuoteChar()
Returns which character to use to quote attribute values.
void WriteEndDocument() override
Closes any open elements or attributes and puts the writer back in the Start state.
char16_t get_IndentChar()
Returns which character to use for indenting when XmlTextWriter::set_Formatting is set to Formatting:...
void WriteRaw(ArrayPtr< char16_t > buffer, int32_t index, int32_t count) override
Writes raw markup manually from a character buffer.
XmlTextWriter(const SharedPtr< IO::Stream > &w, const SharedPtr< Text::Encoding > &encoding)
Creates an instance of the XmlTextWriter class using the specified stream and encoding.
void WriteEntityRef(const String &name) override
Writes out an entity reference as &name;.
SharedPtr< IO::Stream > get_BaseStream()
Returns the underlying stream object.
void WriteStartAttribute(const String &prefix, const String &localName, const String &ns) override
Writes the start of an attribute.
void WriteBase64(ArrayPtr< uint8_t > buffer, int32_t index, int32_t count) override
Encodes the specified binary bytes as base64 and writes out the resulting text.
void set_Namespaces(bool value)
Sets a value indicating whether to do namespace support.
void set_IndentChar(char16_t value)
Sets which character to use for indenting when XmlTextWriter::set_Formatting is set to Formatting::In...
void WriteEndAttribute() override
Closes the previous XmlTextWriter::WriteStartAttribute call.
void Flush() override
Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
XmlTextWriter(const SharedPtr< IO::TextWriter > &w)
Creates an instance of the XmlTextWriter class using the specified TextWriter.
Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files t...
Definition: xml_writer.h:45
@ Text
Defines color adjustment information for text.
@ Stream
The type that supports reliable, two-way, connection-based byte streams without duplication of data a...
@ Namespace
This value is used for internal purposes and is not intended to be used directly from your code.
XmlSpace
Specifies the current xml:space scope.
Definition: xml_space.h:15
@ Xml
Serialize according to the XML 1.0 rules.
WriteState
Specifies the state of the XmlWriter.
Definition: write_state.h:15
Formatting
Specifies formatting options for the XmlTextWriter.
Definition: formatting.h:15
Definition: db_command.h:9