nlib
XmlStreamWriter.h
[詳解]
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_EXI_XMLSTREAMWRITER_H_
17 #define INCLUDE_NN_NLIB_EXI_XMLSTREAMWRITER_H_
18 
20 #include "nn/nlib/exi/Types.h"
21 
22 #if defined(_MSC_VER) && defined(nx_exi_EXPORTS)
23 #undef NLIB_VIS_PUBLIC
24 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
25 #endif
26 
27 NLIB_NAMESPACE_BEGIN
28 class OutputStream;
29 
30 namespace exi {
31 
32 // See:
33 // http://java.sun.com/javase/ja/6/docs/ja/api/javax/xml/stream/XMLStreamWriter.html
34 
39  bool fragment;
41  int version;
43 
44  public:
46  encodeOptions(false),
47  alignment(ALIGNMENT_BIT_PACKED),
48  fragment(false),
49  preserve(),
50  version(0),
51  processor(XML_PROCESSOR_EXI) {}
52 };
53 
55  public:
56  static XmlStreamWriter* Create(OutputStream* stream, const XmlStreamWriterSettings& settings,
57  const ExiAllocatorEx& al) NLIB_NOEXCEPT;
58  static XmlStreamWriter*
60  ExiAllocatorEx al;
61  return Create(stream, settings, al);
62  }
65  return Create(stream, settings);
66  }
69  return Create(stream, settings, al);
70  }
71  virtual ~XmlStreamWriter() NLIB_NOEXCEPT {
72  if (is_local_al_) ExiAllocator::Swap(al_);
73  }
75  ExiAllocatorSwapper swapper(al_);
76  this->Close_();
77  }
79  ExiAllocatorSwapper swapper(al_);
80  this->Flush_();
81  }
82  const ExiChar* GetPrefix(const ExiChar* uri) NLIB_NOEXCEPT {
83  ExiAllocatorSwapper swapper(al_);
84  return this->GetPrefix_(uri ? uri : NLIB_EXI_ESTR);
85  }
86  void WriteAttribute(const ExiChar* local_name, const ExiChar* value) NLIB_NOEXCEPT {
87  this->WriteAttribute(NLIB_EXI_ESTR, NLIB_EXI_ESTR, local_name, value);
88  }
89  void WriteAttribute(const ExiChar* prefix, const ExiChar* namespace_uri,
90  const ExiChar* local_name, const ExiChar* value) NLIB_NOEXCEPT;
91  void WriteCData(const ExiChar* data) NLIB_NOEXCEPT {
92  if (NEXI_IS_ERROR) return;
93  ExiAllocatorSwapper swapper(al_);
94  this->WriteCData_(data ? data : NLIB_EXI_ESTR);
95  }
97  if (NEXI_IS_ERROR) return;
98  ExiAllocatorSwapper swapper(al_);
99  this->WriteCharacters_(text ? text : NLIB_EXI_ESTR);
100  }
101  void WriteComment(const ExiChar* data) NLIB_NOEXCEPT;
102  void WriteProcessingInstruction(const ExiChar* target, const ExiChar* data) NLIB_NOEXCEPT;
103  void WriteNamespace(const ExiChar* prefix, const ExiChar* namespace_uri) NLIB_NOEXCEPT {
104  if (NEXI_IS_ERROR) return;
105  ExiAllocatorSwapper swapper(al_);
106  this->WriteNamespace_(prefix ? prefix : NLIB_EXI_ESTR,
107  namespace_uri ? namespace_uri : NLIB_EXI_ESTR);
108  }
109  void WriteDefaultNamespace(const ExiChar* namespace_uri) NLIB_NOEXCEPT {
110  this->WriteNamespace(NLIB_EXI_ESTR, namespace_uri);
111  }
112  // virtual void WriteDtd(const ExiChar* dtd)=0;
113  void WriteEmptyElement(const ExiChar* local_name) NLIB_NOEXCEPT {
114  this->WriteEmptyElement(NLIB_EXI_ESTR, NLIB_EXI_ESTR, local_name);
115  }
116  void WriteEmptyElement(const ExiChar* prefix, const ExiChar* namespace_uri,
117  const ExiChar* local_name) NLIB_NOEXCEPT;
119  if (NEXI_IS_ERROR) return;
120  ExiAllocatorSwapper swapper(al_);
121  this->WriteStartDocument_();
122  }
123  // virtual void WriteStartDocument(const ExiChar* version)=0;
124  // virtual void WriteStartDocument(const ExiChar* encoding, const ExiChar* version)=0;
126  if (NEXI_IS_ERROR) return;
127  ExiAllocatorSwapper swapper(al_);
128  this->WriteEndDocument_();
129  }
131  if (NEXI_IS_ERROR) return;
132  ExiAllocatorSwapper swapper(al_);
133  this->WriteEndElement_();
134  }
135  // virtual void WriteEntityRef(const ExiChar* name)=0;
136  void WriteStartElement(const ExiChar* local_name) NLIB_NOEXCEPT {
137  this->WriteStartElement(NLIB_EXI_ESTR, NLIB_EXI_ESTR, local_name);
138  }
139  void WriteStartElement(const ExiChar* prefix, const ExiChar* namespace_uri,
140  const ExiChar* local_name) NLIB_NOEXCEPT;
141  ExiErrorStatus::ErrorValue GetError() const NLIB_NOEXCEPT { return error_status_->GetError(); }
142  ExiErrorStatus* GetErrorStatus() const NLIB_NOEXCEPT { return error_status_; }
143  NLIB_SAFE_BOOL(XmlStreamWriter, !!*error_status_)
144 
145  private:
146  virtual void Close_() NLIB_NOEXCEPT = 0;
147  virtual void Flush_() NLIB_NOEXCEPT = 0;
148  virtual const ExiChar* GetPrefix_(const ExiChar* uri) NLIB_NOEXCEPT = 0;
149  virtual void WriteAttribute_(const ExiChar* prefix, const ExiChar* namespace_uri,
150  const ExiChar* local_name, const ExiChar* value) NLIB_NOEXCEPT = 0;
151  virtual void WriteCData_(const ExiChar* data) NLIB_NOEXCEPT = 0;
152  virtual void WriteCharacters_(const ExiChar* text) NLIB_NOEXCEPT = 0;
153  virtual void WriteComment_(const ExiChar* data) NLIB_NOEXCEPT = 0;
154  virtual void
155  WriteProcessingInstruction_(const ExiChar* target, const ExiChar* data) NLIB_NOEXCEPT = 0;
156  virtual void WriteStartElement_(const ExiChar* prefix, const ExiChar* namespace_uri,
157  const ExiChar* local_name) NLIB_NOEXCEPT = 0;
158  virtual void WriteEmptyElement_(const ExiChar* prefix, const ExiChar* namespace_uri,
159  const ExiChar* local_name) NLIB_NOEXCEPT {
160  this->WriteStartElement_(prefix, namespace_uri, local_name);
161  this->WriteEndElement();
162  }
163  virtual void
164  WriteNamespace_(const ExiChar* prefix, const ExiChar* namespace_uri) NLIB_NOEXCEPT = 0;
165  virtual void WriteStartDocument_() NLIB_NOEXCEPT = 0;
166  virtual void WriteEndDocument_() NLIB_NOEXCEPT = 0;
167  virtual void WriteEndElement_() NLIB_NOEXCEPT = 0;
168 
169  protected:
170  static bool IsNullOrEmptyString(const ExiChar* p) NLIB_NOEXCEPT { return (!p) || (*p == '\0'); }
171  void SetExiErrorStatus(ExiErrorStatus* p) NLIB_NOEXCEPT { error_status_ = p; }
172  ExiErrorStatus* GetExiErrorStatus() const NLIB_NOEXCEPT { return error_status_; }
173  explicit XmlStreamWriter(const ExiAllocatorEx& al) NLIB_NOEXCEPT : error_status_(nullptr),
174  al_(al),
175  is_local_al_(al) {}
176 
177  private:
178  ExiErrorStatus* error_status_;
179 
180  protected:
181  ExiAllocatorEx al_;
182  bool is_local_al_;
183  NLIB_DISALLOW_COPY_AND_ASSIGN(XmlStreamWriter);
184 };
185 
186 } // namespace exi
187 NLIB_NAMESPACE_END
188 
189 #if defined(_MSC_VER) && defined(nx_exi_EXPORTS)
190 #undef NLIB_VIS_PUBLIC
191 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
192 #endif
193 
194 #endif // INCLUDE_NN_NLIB_EXI_XMLSTREAMWRITER_H_
bool encodeCookie
データの先頭に識別用の文字列を書きこむかを設定します。
void WriteDefaultNamespace(const ExiChar *namespace_uri) noexcept
デフォルト名前空間を宣言します。
void WriteStartElement(const ExiChar *local_name) noexcept
名前空間なしの要素で開始タグを書き込みます。
文字列型のtypedefやユーティリティマクロ等が定義されています。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:183
void WriteNamespace(const ExiChar *prefix, const ExiChar *namespace_uri) noexcept
XML名前空間を宣言します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:199
XmlProcessor processor
バイナリXMLを書きだすかテキストXMLを書きだすか指定します。
ExiErrorStatus::ErrorValue GetError() const noexcept
エラー値を取得します。
読み書きするバイナリXMLのデータ保持オプションです。
Definition: Types.h:52
int version
バイナリXMLに記録されるバージョン番号を指定します。
void WriteEndElement() noexcept
終了タグを書き込みます。
バイナリXMLの利用
Definition: Types.h:67
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
void WriteEmptyElement(const ExiChar *local_name) noexcept
名前空間なしの要素で開始タグと終了タグをを書き込みます。
XMLパーサーのエラー状態を設定・格納します。
ExiErrorStatus * GetErrorStatus() const noexcept
エラー状態オブジェクトを取得します。
constexpr XmlStreamWriterSettings() noexcept
デフォルト設定がセットされます。
bool encodeOptions
設定の自動認識のための情報を書き込むかを設定します。
void WriteEndDocument() noexcept
開いている任意の要素を全て閉じ、XMLライタをクローズします。
Alignment
読み書きするバイナリXMLのアライメントを指定します。
Definition: Types.h:45
XmlStreamReader, XmlStreamWriter の各インスタンス毎に設定できるアロケータです。
Definition: ExiAllocator.h:35
#define NLIB_EXI_ESTR
空文字列が定義されています。""又はL""です。
Definition: Types.h:41
XmlProcessor
利用するXmlプロセッサの指定オプションです。
Definition: Types.h:67
ErrorValue
エラー状態を示す列挙型です。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
Alignment alignment
バイナリXMLのアライメントを設定します。
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:111
bool fragment
複数のルートノードを持つXML(XMLフラグメント)の書き込みをサポートします。デフォルトはfalseです。 ...
static XmlStreamWriter * Create(OutputStream *stream) noexcept
XmlStreamWriterSettingsをデフォルト設定でXmlStreamReaderのインスタンスを作成します。 ...
Preserve preserve
各種フィデリティオプションを設定します。
XMLパーサーが返すエラーを定義しています。
static XmlStreamWriter * Create(OutputStream *stream, const XmlStreamWriterSettings &settings) noexcept
XmlStreamWriterのインスタンスを作成します。
XmlStreamWriter の初期化オプションとなる構造体です。
void WriteAttribute(const ExiChar *local_name, const ExiChar *value) noexcept
名前空間なしの属性と値を書き込みます。
void WriteCData(const ExiChar *data) noexcept
引数で指定したテキストを書き込みます。
static XmlStreamWriter * Create(OutputStream *stream, const ExiAllocatorEx &al) noexcept
オブジェクト単位のアロケータを指定してXmlStreamWriterのインスタンスを作成します。 ...
void Flush() noexcept
XMLライタをフラッシュします。
XMLのストリームへの書き出しを行う抽象クラスです。
void WriteCharacters(const ExiChar *text) noexcept
引数で指定したテキストを書き込みます。
void Close() noexcept
XmlStreamWriterをクローズします。基となるストリームは切り離されるだけでクローズされません。 ...
const ExiChar * GetPrefix(const ExiChar *uri) noexcept
名前空間URIに対応するプレフィックスを取得します。
ビット単位にデータが詰められたEXIストリームを読み書きします(デフォルト)。
Definition: Types.h:46
出力ストリームの基底クラスです。このクラスを実体化することはできません。
Definition: OutputStream.h:30
void WriteStartDocument() noexcept
XMLドキュメントの開始を宣言し、XML宣言等を書き込みます。
nlib_utf8_t ExiChar
XMLパーサーの内部文字列型のtypedefです。
Definition: Types.h:40