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  kNone = -1,
60  kStartElement = 1,
61  kEndElement = 2,
62  kProcessingInstruction = 3,
63  kCharacters = 4,
64  kComment = 5,
65  kStartDocument = 7,
66  kEndDocument = 8,
67  kCdata = 12,
68  NONE = -1,
69  START_ELEMENT = 1,
70  END_ELEMENT = 2,
71  PROCESSING_INSTRUCTION = 3,
72  CHARACTERS = 4,
73  COMMENT = 5,
74  // SPACE = 6,
75  START_DOCUMENT = 7,
76  END_DOCUMENT = 8,
77  // ENTITY_REFERENCE = 9,
78  // ATTRIBUTE = 10,
79  // DTD = 11,
80  CDATA = 12
81  // NAMESPACE = 13,
82  // NOTATION_DECLARATION = 14,
83  // ENTITY_DECLARATION = 15
84  };
85  static XmlStreamReader* Create(InputStream* stream, const XmlStreamReaderSettings& settings,
86  const ExiAllocatorEx& al) NLIB_NOEXCEPT;
87  static XmlStreamReader*
89  ExiAllocatorEx al;
90  return Create(stream, settings, al);
91  }
94  return Create(stream, settings);
95  }
98  return Create(stream, settings, al);
99  }
100 
101  public:
103  if (is_local_al_) ExiAllocator::Swap(al_);
104  }
106  ExiAllocatorSwapper swapper(al_);
107  this->CloseV();
108  }
110  ExiAllocatorSwapper swapper(al_);
111  return this->GetAttributeCountV();
112  }
114  ExiAllocatorSwapper swapper(al_);
115  return this->GetAttributeLocalNameV(index);
116  }
118  ExiAllocatorSwapper swapper(al_);
119  return this->GetAttributeNamespaceUriV(index);
120  }
121  const ExiChar* GetAttributePrefix(size_t index) NLIB_NOEXCEPT {
122  ExiAllocatorSwapper swapper(al_);
123  return this->GetAttributePrefixV(index);
124  }
125  const ExiChar* GetAttributeType(size_t index) NLIB_NOEXCEPT {
126  ExiAllocatorSwapper swapper(al_);
127  return this->GetAttributeTypeV(index);
128  }
129  const ExiChar* GetAttributeValue(size_t index) NLIB_NOEXCEPT {
130  ExiAllocatorSwapper swapper(al_);
131  return this->GetAttributeValueV(index);
132  }
133  const ExiChar*
134  GetAttributeValue(const ExiChar* namespace_uri, const ExiChar* local_name) NLIB_NOEXCEPT {
135  ExiAllocatorSwapper swapper(al_);
136  return this->GetAttributeValueV(namespace_uri, local_name);
137  }
139  ExiAllocatorSwapper swapper(al_);
140  return this->GetNamespaceCountV();
141  }
142  const ExiChar* GetNamespacePrefix(size_t index) NLIB_NOEXCEPT {
143  ExiAllocatorSwapper swapper(al_);
144  return this->GetNamespacePrefixV(index);
145  }
146  const ExiChar* GetNamespaceUri(size_t index) NLIB_NOEXCEPT {
147  ExiAllocatorSwapper swapper(al_);
148  return this->GetNamespaceUriV(index);
149  }
151  ExiAllocatorSwapper swapper(al_);
152  return this->GetElementTextV();
153  }
155  ExiAllocatorSwapper swapper(al_);
156  return this->GetLocalNameV();
157  }
159  ExiAllocatorSwapper swapper(al_);
160  return this->GetNamespaceUriV();
161  }
163  ExiAllocatorSwapper swapper(al_);
164  return this->GetPrefixV();
165  }
167  ExiAllocatorSwapper swapper(al_);
168  return this->GetTextV();
169  }
170  int GetLineNo() const NLIB_NOEXCEPT { return this->GetLineNoV(); }
171  int GetColumnNo() const NLIB_NOEXCEPT { return this->GetColumnNoV(); }
173  ExiAllocatorSwapper swapper(al_);
174  return this->NextV();
175  }
177  return static_cast<XmlStreamConstants>(state_);
178  }
179  bool HasName() const NLIB_NOEXCEPT {
180  return state_ == START_ELEMENT || state_ == END_ELEMENT || state_ == PROCESSING_INSTRUCTION;
181  }
182  bool HasNext() const NLIB_NOEXCEPT { return state_ != END_DOCUMENT && state_ != NONE; }
183  bool HasText() const NLIB_NOEXCEPT {
184  return state_ == CHARACTERS || state_ == CDATA || state_ == COMMENT ||
185  state_ == PROCESSING_INSTRUCTION;
186  }
187  bool IsCharacters() const NLIB_NOEXCEPT { return state_ == CHARACTERS || state_ == CDATA; }
188  bool IsEndElement() const NLIB_NOEXCEPT { return state_ == END_ELEMENT; }
189  bool IsStartElement() const NLIB_NOEXCEPT { return state_ == START_ELEMENT; }
190  ExiErrorStatus::ErrorValue GetError() const NLIB_NOEXCEPT { return error_status_->GetError(); }
191  ExiErrorStatus* GetErrorStatus() const NLIB_NOEXCEPT { return error_status_; }
192  NLIB_SAFE_BOOL(XmlStreamReader, !!*error_status_)
193 
194  protected:
195  explicit XmlStreamReader(const ExiAllocatorEx& al) NLIB_NOEXCEPT : error_status_(nullptr),
196  al_(al),
197  is_local_al_(al),
198  state_(START_DOCUMENT) {}
199 
200  void SetExiErrorStatus(ExiErrorStatus* p) NLIB_NOEXCEPT { error_status_ = p; }
201  ExiErrorStatus* GetExiErrorStatus() const NLIB_NOEXCEPT { return error_status_; }
202 
203  // template functions to override virtual functions:
204  template<class DECODER>
205  size_t GetAttributeCount_(DECODER* decoder) NLIB_NOEXCEPT;
206  template<class DECODER>
207  const ExiChar* GetAttributeLocalName_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
208  template<class DECODER>
209  const ExiChar* GetAttributeNamespaceUri_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
210  template<class DECODER>
211  const ExiChar* GetAttributePrefix_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
212  template<class DECODER>
213  const ExiChar* GetAttributeValue_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
214  template<class DECODER>
215  const ExiChar* GetAttributeValue_(DECODER* decoder, const ExiChar* namespace_uri,
216  const ExiChar* local_name) NLIB_NOEXCEPT;
217  template<class DECODER>
218  size_t GetNamespaceCount_(DECODER* decoder) NLIB_NOEXCEPT;
219  template<class DECODER>
220  const ExiChar* GetNamespacePrefix_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
221  template<class DECODER>
222  const ExiChar* GetNamespaceUri_(DECODER* decoder, size_t index) NLIB_NOEXCEPT;
223 
224  template<class DECODER>
225  const ExiChar* GetLocalName_(DECODER* decoder) NLIB_NOEXCEPT;
226  template<class DECODER>
227  const ExiChar* GetNamespaceUri_(DECODER* decoder) NLIB_NOEXCEPT;
228  template<class DECODER>
229  const ExiChar* GetPrefix_(DECODER* decoder) NLIB_NOEXCEPT;
230  template<class DECODER>
231  const ExiChar* GetText_(DECODER* decoder) NLIB_NOEXCEPT;
232  const ExiChar* GetElementText_(core::ExiStringAllocator* alloc) NLIB_NOEXCEPT;
233 
234  private:
235  virtual void CloseV() NLIB_NOEXCEPT = 0;
236  virtual size_t GetAttributeCountV() NLIB_NOEXCEPT = 0;
237  virtual const ExiChar* GetAttributeLocalNameV(size_t index) NLIB_NOEXCEPT = 0;
238  virtual const ExiChar* GetAttributeNamespaceUriV(size_t index) NLIB_NOEXCEPT = 0;
239  virtual const ExiChar* GetAttributePrefixV(size_t index) NLIB_NOEXCEPT = 0;
240  virtual const ExiChar* GetAttributeTypeV(size_t index) NLIB_NOEXCEPT = 0;
241  virtual const ExiChar* GetAttributeValueV(size_t index) NLIB_NOEXCEPT = 0;
242  virtual const ExiChar*
243  GetAttributeValueV(const ExiChar* namespace_uri, const ExiChar* local_name) NLIB_NOEXCEPT = 0;
244  virtual size_t GetNamespaceCountV() NLIB_NOEXCEPT = 0;
245  virtual const ExiChar* GetNamespacePrefixV(size_t index) NLIB_NOEXCEPT = 0;
246  virtual const ExiChar* GetNamespaceUriV(size_t index) NLIB_NOEXCEPT = 0;
247  virtual const ExiChar* GetElementTextV() NLIB_NOEXCEPT = 0;
248  virtual const ExiChar* GetLocalNameV() NLIB_NOEXCEPT = 0;
249  virtual const ExiChar* GetNamespaceUriV() NLIB_NOEXCEPT = 0;
250  virtual const ExiChar* GetPrefixV() NLIB_NOEXCEPT = 0;
251  virtual const ExiChar* GetTextV() NLIB_NOEXCEPT = 0;
252  virtual int GetLineNoV() const NLIB_NOEXCEPT { return 0; }
253  virtual int GetColumnNoV() const NLIB_NOEXCEPT { return 0; }
254  virtual XmlStreamConstants NextV() NLIB_NOEXCEPT = 0;
255 
256  private:
257  ExiErrorStatus* error_status_;
258 
259  protected:
260  ExiAllocatorEx al_;
261  bool is_local_al_;
262  int state_; // XmlStreamConstants
263  NLIB_DISALLOW_COPY_AND_ASSIGN(XmlStreamReader);
264 };
265 
266 } // namespace exi
267 NLIB_NAMESPACE_END
268 
269 #if defined(_MSC_VER) && defined(nx_exi_EXPORTS)
270 #undef NLIB_VIS_PUBLIC
271 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
272 #endif
273 
274 #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:183
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:199
const ExiChar * GetAttributePrefix(size_t index) noexcept
属性のプレフィックスを取得します。
読み書きするバイナリXMLのデータ保持オプションです。
Definition: Types.h:52
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:67
const ExiChar * GetAttributeValue(size_t index) noexcept
属性の値を取得します。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
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:67
size_t tempStringMaxLength
XMLコメントとProcessingInstructionの読み込みに用いるテンポラリバッファが格納できる文字列長を指定しま...
ErrorValue
エラー状態を示す列挙型です。
XmlProcessor processor
バイナリXMLを読み込むかテキストXMLを読み込むか指定します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:111
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:46
bool HasText() const noexcept
GetText()でテキストを取得できる状態かどうかを返します。
nlib_utf8_t ExiChar
XMLパーサーの内部文字列型のtypedefです。
Definition: Types.h:40
XmlStreamReaderの初期化オプションとなる構造体です。