nlib
ExiErrorStatus.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_EXIERRORSTATUS_H_
17 #define INCLUDE_NN_NLIB_EXI_EXIERRORSTATUS_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 namespace exi {
29 
31  public:
32  enum ErrorValue {
33  kOk = 0,
34  kOutOfMemory,
35  kArgumentError,
36  kIoError,
37  kUnexpectedEos,
38  kStreamDetached,
39  kIllegalCharacter,
40  kInternalError,
41  kNotSupported,
42  kDuplicateAttribute,
43  kReservedPrefix,
44  kUndeclaringPrefix,
45  kAttributeDefaultNs,
46  kIllegalComment,
47  kIllegalPi,
48  kIllegalBinary,
49  kIllegalBinaryIdx,
50  kIllegalBinaryEvt,
51  kSyntaxError,
52  kIllegalBinaryHdr,
53  kFuncNotAvailable,
54  OK = kOk,
55  OUT_OF_MEMORY = kOutOfMemory,
56  ARGUMENT_ERROR = kArgumentError,
57  IO_ERROR = kIoError,
58  UNEXPECTED_EOS = kUnexpectedEos,
59  STREAM_DETACHED = kStreamDetached,
60  ILLEGAL_CHARACTER = kIllegalCharacter,
61  INTERNAL_ERROR = kInternalError,
62  NOT_SUPPORTED = kNotSupported,
63  DUPLICATE_ATTRIBUTE = kDuplicateAttribute,
64  RESERVED_PREFIX = kReservedPrefix,
65  UNDECLARING_PREFIX = kUndeclaringPrefix,
66  ATTRIBUTE_DEFAULT_NS = kAttributeDefaultNs,
67  ILLEGAL_COMMENT = kIllegalComment,
68  ILLEGAL_PI = kIllegalPi,
69  ILLEGAL_BINARY = kIllegalBinary,
70  ILLEGAL_BINARY_IDX = kIllegalBinaryIdx,
71  ILLEGAL_BINARY_EVT = kIllegalBinaryEvt,
72  SYNTAX_ERROR = kSyntaxError,
73  ILLEGAL_BINARY_HDR = kIllegalBinaryHdr,
74  FUNC_NOT_AVAILABLE = kFuncNotAvailable
75  };
76 
77  public:
78  ExiErrorStatus() NLIB_NOEXCEPT : error_(OK), line_(0), filename_(nullptr) {}
79  ErrorValue GetError() const NLIB_NOEXCEPT { return static_cast<ErrorValue>(error_); }
80  int GetLineNo() const NLIB_NOEXCEPT { return line_; }
81  const char* GetFileName() const NLIB_NOEXCEPT { return filename_; }
82  bool SetError(ErrorValue e, int line, const char* filename) NLIB_NOEXCEPT;
83  void Reset() NLIB_NOEXCEPT;
84  NLIB_SAFE_BOOL(ExiErrorStatus, error_ == OK)
85 
86  private:
87  int error_; // ErrorValue
88  int line_; // __LINE__
89  const char* filename_; // __FILE__
90  NEXI_DISALLOW_NEW_DELETE(ExiErrorStatus);
92 };
93 
94 // for unit-tests, make NEXI_SET_ERROR() work if ErrorStatus is not set.
95 #define NEXI_SET_ERROR(e) \
96  (this->GetExiErrorStatus() ? this->GetExiErrorStatus()->SetError((e), __LINE__, __FILE__) \
97  : false)
98 #define NEXI_IS_ERROR (nlib_is_error(*this->GetExiErrorStatus()))
99 #define NEXI_RESET_ERROR this->GetExiErrorStatus()->Reset()
100 #define NEXI_CHECK_OUT_OF_MEMORY \
101  if (ExiAllocator::IsOutOfMemory()) NEXI_SET_ERROR(ExiErrorStatus::OUT_OF_MEMORY)
102 
103 } // namespace exi
104 NLIB_NAMESPACE_END
105 
106 #if defined(_MSC_VER) && defined(nx_exi_EXPORTS)
107 #undef NLIB_VIS_PUBLIC
108 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
109 #endif
110 
111 #endif // INCLUDE_NN_NLIB_EXI_EXIERRORSTATUS_H_
ExiErrorStatus() noexcept
コンストラクタです。
文字列型のtypedefやユーティリティマクロ等が定義されています。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:183
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:199
XMLパーサーが利用するアロケータを定義しています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
XMLパーサーのエラー状態を設定・格納します。
int GetLineNo() const noexcept
エラーを発生させたコードの行番号を返します。
const char * GetFileName() const noexcept
エラーを発生させたコードのファイル名を返します。
ErrorValue
エラー状態を示す列挙型です。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
ErrorValue GetError() const noexcept
エラー状態を示す値を取得します。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:250