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 #ifdef __DBG_FOR_EACH_MEMBER
156 public:
159 ASPOSECPP_SHARED_API void DBG_for_each_member(DBG::for_each_member_visitor& visitor) const override;
162 const char* DBG_class_name() const override { return "XmlTextWriter"; }
163 #endif
164
165
166 };
167
168 class Namespace : public System::Object
169 {
170 typedef Namespace ThisType;
171 typedef System::Object BaseType;
172
173 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
174 RTTI_INFO_DECL();
175
176 public:
177
179 String prefix;
180 String ns;
181 bool declared;
182 int32_t prevNsIndex;
183
184 void Set(const String& prefix, const String& ns, bool declared);
186
187 Namespace();
188
189 };
190
191
192public:
193
197 ASPOSECPP_SHARED_API SharedPtr<IO::Stream> get_BaseStream();
201 ASPOSECPP_SHARED_API bool get_Namespaces();
205 ASPOSECPP_SHARED_API void set_Namespaces(bool value);
211 ASPOSECPP_SHARED_API void set_Formatting(System::Xml::Formatting value);
215 ASPOSECPP_SHARED_API int32_t get_Indentation();
220 ASPOSECPP_SHARED_API void set_Indentation(int32_t value);
223 ASPOSECPP_SHARED_API char16_t get_IndentChar();
226 ASPOSECPP_SHARED_API void set_IndentChar(char16_t value);
230 ASPOSECPP_SHARED_API char16_t get_QuoteChar();
234 ASPOSECPP_SHARED_API void set_QuoteChar(char16_t value);
237 ASPOSECPP_SHARED_API System::Xml::WriteState get_WriteState() override;
250 ASPOSECPP_SHARED_API System::Xml::XmlSpace get_XmlSpace() override;
253 ASPOSECPP_SHARED_API String get_XmlLang() override;
254
262 ASPOSECPP_SHARED_API XmlTextWriter(const SharedPtr<IO::Stream>& w, const SharedPtr<Text::Encoding>& encoding);
276 ASPOSECPP_SHARED_API XmlTextWriter(const String& filename, const SharedPtr<Text::Encoding>& encoding);
279 ASPOSECPP_SHARED_API XmlTextWriter(const SharedPtr<IO::TextWriter>& w);
280
283 ASPOSECPP_SHARED_API void WriteStartDocument() override;
287 ASPOSECPP_SHARED_API void WriteStartDocument(bool standalone) override;
290 ASPOSECPP_SHARED_API void WriteEndDocument() override;
299 ASPOSECPP_SHARED_API void WriteDocType(const String& name, const String& pubid, const String& sysid, const String& subset) override;
306 ASPOSECPP_SHARED_API void WriteStartElement(const String& prefix, const String& localName, const String& ns) override;
308 ASPOSECPP_SHARED_API void WriteEndElement() override;
310 ASPOSECPP_SHARED_API void WriteFullEndElement() override;
316 ASPOSECPP_SHARED_API void WriteStartAttribute(const String& prefix, const String& localName, const String& ns) override;
318 ASPOSECPP_SHARED_API void WriteEndAttribute() override;
323 ASPOSECPP_SHARED_API void WriteCData(String text) override;
328 ASPOSECPP_SHARED_API void WriteComment(String text) override;
336 ASPOSECPP_SHARED_API void WriteProcessingInstruction(String name, String text) override;
340 ASPOSECPP_SHARED_API void WriteEntityRef(const String& name) override;
346 ASPOSECPP_SHARED_API void WriteCharEntity(char16_t ch) override;
350 ASPOSECPP_SHARED_API void WriteWhitespace(String ws) override;
354 ASPOSECPP_SHARED_API void WriteString(const String& text) override;
359 ASPOSECPP_SHARED_API void WriteSurrogateCharEntity(char16_t lowChar, char16_t highChar) override;
369 ASPOSECPP_SHARED_API void WriteChars(ArrayPtr<char16_t> buffer, int32_t index, int32_t count) override;
377 ASPOSECPP_SHARED_API void WriteRaw(ArrayPtr<char16_t> buffer, int32_t index, int32_t count) override;
380 ASPOSECPP_SHARED_API void WriteRaw(const String& data) override;
389 ASPOSECPP_SHARED_API void WriteBase64(ArrayPtr<uint8_t> buffer, int32_t index, int32_t count) override;
398 ASPOSECPP_SHARED_API void WriteBinHex(ArrayPtr<uint8_t> buffer, int32_t index, int32_t count) override;
400 ASPOSECPP_SHARED_API void Close() override;
402 ASPOSECPP_SHARED_API void Flush() override;
407 ASPOSECPP_SHARED_API void WriteName(const String& name) override;
413 ASPOSECPP_SHARED_API void WriteQualifiedName(const String& localName, const String& ns) override;
418 ASPOSECPP_SHARED_API String LookupPrefix(String ns) override;
423 ASPOSECPP_SHARED_API void WriteNmToken(const String& name) override;
424
425protected:
426
429 MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(XmlTextWriter, CODEPORTING_ARGS());
431
432 virtual ASPOSECPP_SHARED_API ~XmlTextWriter();
433
435 #ifdef ASPOSE_GET_SHARED_MEMBERS
436 ASPOSECPP_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
437 #endif
438
439 #ifdef __DBG_FOR_EACH_MEMBER
440public:
443 ASPOSECPP_SHARED_API void DBG_for_each_member(DBG::for_each_member_visitor& visitor) const override;
446 const char* DBG_class_name() const override { return "XmlTextWriter"; }
447 #endif
449
450private:
451
452 SharedPtr<IO::TextWriter> _textWriter;
453 SharedPtr<XmlTextEncoder> _xmlEncoder;
455 System::Xml::Formatting _formatting;
456 bool _indented;
457 int32_t _indentation;
458 char16_t _indentChar;
460 int32_t _top;
462 XmlTextWriter::State _currentState;
463 XmlTextWriter::Token _lastToken;
465 char16_t _quoteChar;
466 char16_t _curQuoteChar;
467 bool _namespaces;
468 XmlTextWriter::SpecialAttr _specialAttr;
469 String _prefixForXmlNs;
470 bool _flush;
472 int32_t _nsTop;
474 bool _useNsHashtable;
475 XmlCharType _xmlCharType;
476 static const int32_t NamespaceStackInitialSize;
477 static const int32_t MaxNamespacesWalkCount;
478 static ArrayPtr<String> s_stateName;
479 static ArrayPtr<String> s_tokenName;
480 static ArrayPtr<XmlTextWriter::State> s_stateTableDefault;
481 static ArrayPtr<XmlTextWriter::State> s_stateTableDocument;
482
483 String PrepareElementPrefix(const String& prefix, const String& ns);
484 String PrepareAttributePrefix(const String& prefix, const String*& localName, const String& ns);
485 void StartDocument(int32_t standalone);
486 void AutoComplete(XmlTextWriter::Token token);
487 void AutoCompleteAll();
488 void InternalWriteEndElement(bool longFormat);
489 void WriteEndStartTag(bool empty);
490 void WriteEndAttributeQuote();
491 void Indent(bool beforeEndElement);
492 void PushNamespace(const String& prefix, const String& ns, bool declared);
493 void AddNamespace(const String& prefix, const String& ns, bool declared);
494 void AddToNamespaceHashtable(int32_t namespaceIndex);
495 void PopNamespaces(int32_t indexFrom, int32_t indexTo);
496 String GeneratePrefix();
497 void InternalWriteProcessingInstruction(const String& name, const String& text);
498 int32_t LookupNamespace(const String& prefix);
499 int32_t LookupNamespaceInCurrentScope(const String& prefix);
500 String FindPrefix(const String& ns);
501 void InternalWriteName(const String& name, bool isNCName);
502 void ValidateName(const String& name, bool isNCName);
503 void HandleSpecialAttribute();
504 void VerifyPrefixXml(const String& prefix, const String& ns);
505 void PushStack();
506 void FlushEncoders();
507
508 static struct __StaticConstructor__ { __StaticConstructor__(); } s_constructor__;
509
510};
511
512} // namespace Xml
513} // namespace System
514
515
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