nlib
ExiErrorStatus.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_EXI_EXIERRORSTATUS_H_
4 #define INCLUDE_NN_NLIB_EXI_EXIERRORSTATUS_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 namespace exi {
16 
18  public:
19  enum ErrorValue {
20  OK = 0,
40  FUNC_NOT_AVAILABLE
41  };
42 
43  public:
44  ExiErrorStatus() NLIB_NOEXCEPT : error_(OK), line_(0), filename_(NULL) {}
45  ErrorValue GetError() const NLIB_NOEXCEPT { return static_cast<ErrorValue>(error_); }
46  int GetLineNo() const NLIB_NOEXCEPT { return line_; }
47  const char* GetFileName() const NLIB_NOEXCEPT { return filename_; }
48  bool SetError(ErrorValue e, int line, const char* filename) NLIB_NOEXCEPT;
49  void Reset() NLIB_NOEXCEPT;
50  NLIB_SAFE_BOOL(ExiErrorStatus, error_ == OK)
51 
52  private:
53  int error_; // ErrorValue
54  int line_; // __LINE__
55  const char* filename_; // __FILE__
56  NEXI_DISALLOW_NEW_DELETE(ExiErrorStatus);
58 };
59 
60 // for unit-tests, make NEXI_SET_ERROR() work if ErrorStatus is not set.
61 #define NEXI_SET_ERROR(e) \
62  (this->GetExiErrorStatus() ? this->GetExiErrorStatus()->SetError((e), __LINE__, __FILE__) \
63  : false)
64 #define NEXI_IS_ERROR (nlib_is_error(*this->GetExiErrorStatus()))
65 #define NEXI_RESET_ERROR this->GetExiErrorStatus()->Reset()
66 #define NEXI_CHECK_OUT_OF_MEMORY \
67  if (ExiAllocator::IsOutOfMemory()) NEXI_SET_ERROR(ExiErrorStatus::OUT_OF_MEMORY)
68 
69 } // namespace exi
70 NLIB_NAMESPACE_END
71 
72 #if defined(_MSC_VER) && defined(nx_exi_EXPORTS)
73 #undef NLIB_VIS_PUBLIC
74 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
75 #endif
76 
77 #endif // INCLUDE_NN_NLIB_EXI_EXIERRORSTATUS_H_
ExiErrorStatus() noexcept
Instantiates the object.
Defines constructs such as string-type typedef statements and utility macros.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:145
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
Definition: Config.h:160
Defines the allocator used by the XML parser.
Binary data may be invalid. An error occurred while parsing the EXI header. Either the data is invali...
Binary data may be invalid. Specified event was either invalid or could not be found.
Cannot turn an attribute namespace into the default namespace.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
Sets and stores the error status of the XML parser.
int GetLineNo() const noexcept
Returns the line number of the code that generated the error.
const char * GetFileName() const noexcept
Returns the filename of the code that generated the error.
ErrorValue
Enumerates error statuses.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
Attempted to delete (undeclare) a prefix.
ErrorValue GetError() const noexcept
Gets a value that indicates the error status.
Attempted to read or write an invalid character.
Attempted to define a reserved prefix (xml or xmlns).
Binary data may be invalid. Index exceeds the expected range.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
Unsupported feature or format.