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