nlib
XmlStreamReader.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_XMLSTREAMREADER_H_
17 #define INCLUDE_NN_NLIB_EXI_XMLSTREAMREADER_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 InputStream;
29 
30 namespace exi {
31 
32 // See:
33 // http://java.sun.com/javase/ja/6/docs/ja/api/javax/xml/stream/XMLStreamReader.html
34 
38  bool fragment;
42 
43  public:
45  alignment(ALIGNMENT_BIT_PACKED),
46  fragment(false),
47  isVersionIgnored(false),
48  processor(XML_PROCESSOR_EXI),
49  tempStringMaxLength(1023) {}
50 };
51 
52 namespace core {
53 class ExiStringAllocator;
54 }
55 
57  public:
59  NONE = -1,
60  START_ELEMENT = 1,
61  END_ELEMENT = 2,
62  PROCESSING_INSTRUCTION = 3,
63  CHARACTERS = 4,
64  COMMENT = 5,
65  // SPACE = 6,
66  START_DOCUMENT = 7,
67  END_DOCUMENT = 8,
68  // ENTITY_REFERENCE = 9,
69  // ATTRIBUTE = 10,
70  // DTD = 11,
71  CDATA = 12
72  // NAMESPACE = 13,
73  // NOTATION_DECLARATION = 14,
74  // ENTITY_DECLARATION = 15
75  };
76  static XmlStreamReader* Create(InputStream* stream, const XmlStreamReaderSettings& settings,
77  const ExiAllocatorEx& al) NLIB_NOEXCEPT;
79  const XmlStreamReaderSettings& settings) NLIB_NOEXCEPT {
80  ExiAllocatorEx al;
81  return Create(stream, settings, al);
82  }
83  static XmlStreamReader* Create(InputStream* stream) NLIB_NOEXCEPT {
85  return Create(stream, settings);
86  }
87  static XmlStreamReader* Create(InputStream* stream, const ExiAllocatorEx& al) NLIB_NOEXCEPT {
89  return Create(stream, settings, al);
90  }
91 
92  public:
93  virtual ~XmlStreamReader() NLIB_NOEXCEPT {
94  if (is_local_al_) ExiAllocator::Swap(al_);
95  }
96  void Close() NLIB_NOEXCEPT {
97  ExiAllocatorSwapper swapper(al_);
98  this->CloseV();
99  }
100  size_t GetAttributeCount() NLIB_NOEXCEPT {
101  ExiAllocatorSwapper swapper(al_);
102  return this->GetAttributeCountV();
103  }
104  const ExiChar* GetAttributeLocalName(size_t index) NLIB_NOEXCEPT {
105  ExiAllocatorSwapper swapper(al_);
106  return this->GetAttributeLocalNameV(index);
107  }
108  const ExiChar* GetAttributeNamespaceUri(size_t index) NLIB_NOEXCEPT {
109  ExiAllocatorSwapper swapper(al_);
110  return this->GetAttributeNamespaceUriV(index);
111  }
112  const ExiChar* GetAttributePrefix(size_t index) NLIB_NOEXCEPT {
113  ExiAllocatorSwapper swapper(al_);
114  return this->GetAttributePrefixV(index);
115  }
116  const ExiChar* GetAttributeType(size_t index) NLIB_NOEXCEPT {
117  ExiAllocatorSwapper swapper(al_);
118  return this->GetAttributeTypeV(index);
119  }
120  const ExiChar* GetAttributeValue(size_t index) NLIB_NOEXCEPT {
121  ExiAllocatorSwapper swapper(al_);
122  return this->GetAttributeValueV(index);
123  }
124  const ExiChar* GetAttributeValue(const ExiChar* namespace_uri,
125  const ExiChar* local_name) NLIB_NOEXCEPT {
126  ExiAllocatorSwapper swapper(al_);
127  return this->GetAttributeValueV(namespace_uri, local_name);
128  }
129  size_t GetNamespaceCount() NLIB_NOEXCEPT {
130  ExiAllocatorSwapper swapper(al_);
131  return this->GetNamespaceCountV();
132  }
133  const ExiChar* GetNamespacePrefix(size_t index) NLIB_NOEXCEPT {
134  ExiAllocatorSwapper swapper(al_);
135  return this->GetNamespacePrefixV(index);
136  }
137  const ExiChar* GetNamespaceUri(size_t index) NLIB_NOEXCEPT {
138  ExiAllocatorSwapper swapper(al_);
139  return this->GetNamespaceUriV(index);
140  }
141  const ExiChar* GetElementText() NLIB_NOEXCEPT {
142  ExiAllocatorSwapper swapper(al_);
143  return this->GetElementTextV();
144  }
145  const ExiChar* GetLocalName() NLIB_NOEXCEPT {
146  ExiAllocatorSwapper swapper(al_);
147  return this->GetLocalNameV();
148  }
149  const ExiChar* GetNamespaceUri() NLIB_NOEXCEPT {
150  ExiAllocatorSwapper swapper(al_);
151  return this->GetNamespaceUriV();
152  }
153  const ExiChar* GetPrefix() NLIB_NOEXCEPT {
154  ExiAllocatorSwapper swapper(al_);
155  return this->GetPrefixV();
156  }
157  const ExiChar* GetText() NLIB_NOEXCEPT {
158  ExiAllocatorSwapper swapper(al_);
159  return this->GetTextV();
160  }
161  int GetLineNo() const NLIB_NOEXCEPT { return this->GetLineNoV(); }
162  int GetColumnNo() const NLIB_NOEXCEPT { return this->GetColumnNoV(); }
163  XmlStreamConstants Next() NLIB_NOEXCEPT {
164  ExiAllocatorSwapper swapper(al_);
165  return this->NextV();
166  }
167  XmlStreamConstants GetEventType() const NLIB_NOEXCEPT {
168  return static_cast<XmlStreamConstants>(state_);
169  }
170  bool HasName() const NLIB_NOEXCEPT {
171  return state_ == START_ELEMENT || state_ == END_ELEMENT ||
172  state_ == PROCESSING_INSTRUCTION;
173  }
174  bool HasNext() const NLIB_NOEXCEPT { return state_ != END_DOCUMENT && state_ != NONE; }
175  bool HasText() const NLIB_NOEXCEPT {
176  return state_ == CHARACTERS || state_ == CDATA || state_ == COMMENT ||
177  state_ == PROCESSING_INSTRUCTION;
178  }
179  bool IsCharacters() const NLIB_NOEXCEPT { return state_ == CHARACTERS || state_ == CDATA; }
180  bool IsEndElement() const NLIB_NOEXCEPT { return state_ == END_ELEMENT; }
181  bool IsStartElement() const NLIB_NOEXCEPT { return state_ == START_ELEMENT; }
182  ExiErrorStatus::ErrorValue GetError() const NLIB_NOEXCEPT {
183  return error_status_->GetError();
184  }
185  ExiErrorStatus* GetErrorStatus() const NLIB_NOEXCEPT { return error_status_; }
186  NLIB_SAFE_BOOL(XmlStreamReader, !!*error_status_)
187 
188  protected:
189  explicit XmlStreamReader(const ExiAllocatorEx& al) NLIB_NOEXCEPT : error_status_(nullptr),
190  al_(al),
191  is_local_al_(al),
192  state_(START_DOCUMENT) {}
193 
194  void SetExiErrorStatus(ExiErrorStatus* p) NLIB_NOEXCEPT { error_status_ = p; }
195  ExiErrorStatus* GetExiErrorStatus() const NLIB_NOEXCEPT { return error_status_; }
196 
197  // template functions to override virtual functions:
198  template <class DECODER>
199  size_t GetAttributeCount_(DECODER* decoder) NLIB_NOEXCEPT;
200  template <class DECODER>
201  const ExiChar* GetAttributeLocalName_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
202  template <class DECODER>
203  const ExiChar* GetAttributeNamespaceUri_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
204  template <class DECODER>
205  const ExiChar* GetAttributePrefix_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
206  template <class DECODER>
207  const ExiChar* GetAttributeValue_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
208  template <class DECODER>
209  const ExiChar* GetAttributeValue_(DECODER* decoder, const ExiChar* namespace_uri,
210  const ExiChar* local_name) NLIB_NOEXCEPT;
211  template <class DECODER>
212  size_t GetNamespaceCount_(DECODER* decoder) NLIB_NOEXCEPT;
213  template <class DECODER>
214  const ExiChar* GetNamespacePrefix_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
215  template <class DECODER>
216  const ExiChar* GetNamespaceUri_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
217 
218  template <class DECODER>
219  const ExiChar* GetLocalName_(DECODER* decoder) NLIB_NOEXCEPT;
220  template <class DECODER>
221  const ExiChar* GetNamespaceUri_(DECODER* decoder) NLIB_NOEXCEPT;
222  template <class DECODER>
223  const ExiChar* GetPrefix_(DECODER* decoder) NLIB_NOEXCEPT;
224  template <class DECODER>
225  const ExiChar* GetText_(DECODER* decoder) NLIB_NOEXCEPT;
226  const ExiChar* GetElementText_(core::ExiStringAllocator* alloc) NLIB_NOEXCEPT;
227 
228  private:
229  virtual void CloseV() NLIB_NOEXCEPT = 0;
230  virtual size_t GetAttributeCountV() NLIB_NOEXCEPT = 0;
231  virtual const ExiChar* GetAttributeLocalNameV(size_t index) NLIB_NOEXCEPT = 0;
232  virtual const ExiChar* GetAttributeNamespaceUriV(size_t index) NLIB_NOEXCEPT = 0;
233  virtual const ExiChar* GetAttributePrefixV(size_t index) NLIB_NOEXCEPT = 0;
234  virtual const ExiChar* GetAttributeTypeV(size_t index) NLIB_NOEXCEPT = 0;
235  virtual const ExiChar* GetAttributeValueV(size_t index) NLIB_NOEXCEPT = 0;
236  virtual const ExiChar* GetAttributeValueV(const ExiChar* namespace_uri,
237  const ExiChar* local_name) NLIB_NOEXCEPT = 0;
238  virtual size_t GetNamespaceCountV() NLIB_NOEXCEPT = 0;
239  virtual const ExiChar* GetNamespacePrefixV(size_t index) NLIB_NOEXCEPT = 0;
240  virtual const ExiChar* GetNamespaceUriV(size_t index) NLIB_NOEXCEPT = 0;
241  virtual const ExiChar* GetElementTextV() NLIB_NOEXCEPT = 0;
242  virtual const ExiChar* GetLocalNameV() NLIB_NOEXCEPT = 0;
243  virtual const ExiChar* GetNamespaceUriV() NLIB_NOEXCEPT = 0;
244  virtual const ExiChar* GetPrefixV() NLIB_NOEXCEPT = 0;
245  virtual const ExiChar* GetTextV() NLIB_NOEXCEPT = 0;
246  virtual int GetLineNoV() const NLIB_NOEXCEPT { return 0; }
247  virtual int GetColumnNoV() const NLIB_NOEXCEPT { return 0; }
248  virtual XmlStreamConstants NextV() NLIB_NOEXCEPT = 0;
249 
250  private:
251  ExiErrorStatus* error_status_;
252 
253  protected:
254  ExiAllocatorEx al_;
255  bool is_local_al_;
256  int state_; // XmlStreamConstants
258 };
259 
260 } // namespace exi
261 NLIB_NAMESPACE_END
262 
263 #if defined(_MSC_VER) && defined(nx_exi_EXPORTS)
264 #undef NLIB_VIS_PUBLIC
265 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
266 #endif
267 
268 #endif // INCLUDE_NN_NLIB_EXI_XMLSTREAMREADER_H_
XmlStreamConstants Next() noexcept
ストリームから次のXMLストリームイベントを読み込みます。
static XmlStreamReader * Create(InputStream *stream, const ExiAllocatorEx &al) noexcept
オブジェクト単位のアロケータを指定してXmlStreamReaderのインスタンスを作成します。 ...
size_t GetAttributeCount() noexcept
属性の数を取得します。
文字列型のtypedefやユーティリティマクロ等が定義されています。
static XmlStreamReader * Create(InputStream *stream, const XmlStreamReaderSettings &settings) noexcept
XmlStreamReaderのインスタンスを作成します。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
const ExiChar * GetNamespacePrefix(size_t index) noexcept
名前空間宣言のプレフィックスを取得します。
const ExiChar * GetLocalName() noexcept
ローカル名を取得します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:194
const ExiChar * GetAttributePrefix(size_t index) noexcept
属性のプレフィックスを取得します。
読み書きするバイナリXMLのデータ保持オプションです。
Definition: Types.h:47
const ExiChar * GetAttributeValue(const ExiChar *namespace_uri, const ExiChar *local_name) noexcept
名前空間URIとローカル名を指定して属性の値を取得します。
const ExiChar * GetAttributeLocalName(size_t index) noexcept
属性のローカル名を取得します。
const ExiChar * GetNamespaceUri(size_t index) noexcept
名前空間宣言の名前空間URIを取得します。
const ExiChar * GetPrefix() noexcept
XMLの名前空間プレフィックスを取得します。
バイナリXMLの利用
Definition: Types.h:62
const ExiChar * GetAttributeValue(size_t index) noexcept
属性の値を取得します。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
constexpr XmlStreamReaderSettings() noexcept
デフォルト設定がセットされます。
static XmlStreamReader * Create(InputStream *stream) noexcept
XmlStreamReaderSettingsをデフォルト設定でXmlStreamReaderのインスタンスを作成します。 ...
virtual ~XmlStreamReader() noexcept
デストラクタです。
const ExiChar * GetText() noexcept
テキストデータを取得します。
XMLパーサーのエラー状態を設定・格納します。
const ExiChar * GetElementText() noexcept
連続したテキストイベントを読み込んで1つのテキストを返します。
int GetColumnNo() const noexcept
XmlStreamReader が指し示しているカラム番号を取得します。
Preserve preserve
各種フィデリティオプションを設定します。
const ExiChar * GetNamespaceUri() noexcept
XML名前空間のURIを取得します。
XMLストリームからの読み出しを行う抽象クラスです。
ExiErrorStatus::ErrorValue GetError() const noexcept
エラー値を取得します。
ExiErrorStatus * GetErrorStatus() const noexcept
エラー状態オブジェクトを取得します。
入力ストリームの基底クラスです。このクラスを実体化することはできません。
Definition: InputStream.h:29
int GetLineNo() const noexcept
XmlStreamReader が指し示している行番号を取得します。
Alignment
読み書きするバイナリXMLのアライメントを指定します。
Definition: Types.h:45
const ExiChar * GetAttributeNamespaceUri(size_t index) noexcept
属性の名前空間URIを取得します。
XmlStreamReader, XmlStreamWriter の各インスタンス毎に設定できるアロケータです。
Definition: ExiAllocator.h:35
size_t GetNamespaceCount() noexcept
新たに宣言された名前空間の数を取得します。
XmlProcessor
利用するXmlプロセッサの指定オプションです。
Definition: Types.h:62
size_t tempStringMaxLength
XMLコメントとProcessingInstructionの読み込みに用いるテンポラリバッファが格納できる文字列長を指定しま...
ErrorValue
エラー状態を示す列挙型です。
XmlProcessor processor
バイナリXMLを読み込むかテキストXMLを読み込むか指定します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
Alignment alignment
読み込むバイナリXMLのアライメントを指定します。
bool IsStartElement() const noexcept
読み込んだデータが開始タグかどうかを取得します。
XmlStreamConstants GetEventType() const noexcept
直近のXMLストリームイベントの値を返します。
XMLパーサーが返すエラーを定義しています。
bool HasName() const noexcept
ローカル名等を取得できるかどうかを返します。
bool isVersionIgnored
読み込み時にtrueにすると、バイナリXML読み込み時にバージョンのチェックを行いません。 ...
bool IsCharacters() const noexcept
読み込んだデータがテキストノードかどうかを取得します。
XmlStreamConstants
XMLストリームの読み込みで発生したXMLストリームイベントの値です。
bool IsEndElement() const noexcept
読み込んだデータが終了タグかどうかを取得します。
void Close() noexcept
XmlStreamReaderをクローズします。基となるストリームは参照されなくなるだけでクローズされません。 ...
bool fragment
複数のルートノードを持つXML(XMLフラグメント)をサポートしたバイナリXMLを読み込みます。 ...
bool HasNext() const noexcept
次のXMLストリームイベントを取得できるかどうかを返します。
ビット単位にデータが詰められたEXIストリームを読み書きします(デフォルト)。
Definition: Types.h:45
bool HasText() const noexcept
GetText()でテキストを取得できる状態かどうかを返します。
nlib_utf8_t ExiChar
XMLパーサーの内部文字列型のtypedefです。
Definition: Types.h:40
XmlStreamReaderの初期化オプションとなる構造体です。