46 #if !defined(THEOLIZER_INTERNAL_REPORT_H) 47 #define THEOLIZER_INTERNAL_REPORT_H 50 #include "internal/base.h" 62 #pragma warning(disable:4100 4251) 74 #ifndef THEOLIZER_INTERNAL_DOXYGEN 80 THEOLIZER_INTERNAL_DLL
81 void abort[[ noreturn ]](
char const* iFile,
unsigned iLine, u8string
const& iMessage);
83 #define THEOLIZER_INTERNAL_ABORT(...) \ 84 theolizer::internal::abort \ 86 THEOLIZER_INTERNAL_FILE, \ 88 theolizer::print(__VA_ARGS__) \ 95 void asserted(std::string
const& iMessage,
char const* iFile,
unsigned iLine);
96 #define THEOLIZER_INTERNAL_ASSERT(dJudge, ...) \ 97 do {if (!(dJudge)) THEOLIZER_INTERNAL_ABORT(__VA_ARGS__);}while(0) \ 108 class THEOLIZER_INTERNAL_DLL Format
113 std::unique_ptr<Indep> mIndep;
116 Format(Format
const&) =
delete;
117 Format& operator=(Format
const&) =
delete;
121 Format(u8string
const& iFormat) noexcept;
125 Format(Format&& iRhs);
126 Format& operator=(Format&& iRhs);
132 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \ 133 Format& operator%(dType iValue); 134 #define THEOLIZER_INTERNAL_DEF_CHAR(dType, dSymbol) \ 135 Format& operator%(dType const* iValue); 136 Format& operator%(
const u8string& iValue);
138 #define THEOLIZER_INTERNAL_DEF_BOOL(dType, dSymbol) 139 #define THEOLIZER_INTERNAL_DEF_STRING(dType, dSymbol) 140 #define THEOLIZER_INTERNAL_DEF_WCHAR(dType, dSymbol) 141 #define THEOLIZER_INTERNAL_DEF_CHAR16(dType, dSymbol) 142 #define THEOLIZER_INTERNAL_DEF_CHAR32(dType, dSymbol) 143 #include "internal/primitive.inc" 145 Format& operator%(
void* iValue);
156 inline u8string printImpl(Format& iFormat)
158 return iFormat.str();
161 template<
typename tFirst,
typename... tParams>
162 u8string printImpl(Format& iFormat, tFirst iFirst, tParams... iParams)
165 return printImpl(iFormat, iParams...);
168 #endif // THEOLIZER_INTERNAL_DOXYGEN 180 template<
typename... tParams>
183 internal::Format aFormat(iFormat);
184 return internal::printImpl(aFormat, iParams...);
189 #ifndef THEOLIZER_INTERNAL_DOXYGEN 245 template<
typename tData>
249 template<
typename tData2, WeakData<tData2>*>
friend class AutoSet;
251 void set(
const tData& iData)
255 const tData&
get() {
return mData;}
260 static_assert(std::is_scalar<tData>::value,
261 "Please use tData is scalar type for WeekData.");
269 template<
typename tData, WeakData<tData>* tWeakData>
270 class THEOLIZER_INTERNAL_DLL AutoSet
274 tWeakData->set(tData());
278 static AutoSet& getInstance();
282 AutoSet(
const AutoSet&) =
delete;
283 AutoSet( AutoSet&&) =
delete;
284 AutoSet& operator=(
const AutoSet&) =
delete;
285 AutoSet& operator=( AutoSet&&) =
delete;
288 static int set(
const tData& iData,
char const* iFile,
int iLineNo,
int*)
291 if ((tWeakData->get() != tData())
292 && (tWeakData->get() != iData))
294 std::cout <<
"\n" << iFile <<
"(" << iLineNo <<
")" 295 <<
" : Multiple setup the WeakData.\n";
298 tWeakData->set(iData);
303 static tData
const&
get()
306 return tWeakData->get();
324 #define THEOLIZER_INTERNAL_GET_WEAK_DATA(dWeakData, dType) \ 325 theolizer::internal::AutoSet<dType, &dWeakData>::get() 328 #define THEOLIZER_INTERNAL_SET_WEAK_DATA(dWeakData, dType, dData, dUnique) \ 331 int dUnique=theolizer::internal::AutoSet<dType, &dWeakData>:: \ 332 set(dData, THEOLIZER_INTERNAL_FILE, __LINE__, &dUnique); \ 335 #endif // THEOLIZER_INTERNAL_DOXYGEN 359 void operator =(
const LogStream&) =
delete;
372 template<
typename Type>
375 mWorkingLog->getOStream() << iObject;
386 std::unique_ptr<Impl> mImpl;
387 static std::string mErrorLogPath;
390 std::ostream& getOStream();
407 size_t iFileSize=1024*1024,
408 unsigned iFileCount=2
419 static time_t getTime(
bool iIsUTC=
false);
437 static bool getLineHeader
439 std::string
const& iLine,
457 #ifndef THEOLIZER_INTERNAL_DOXYGEN 459 struct THEOLIZER_INTERNAL_DLL BaseAdditionalInfo
461 BaseAdditionalInfo() { }
467 virtual void setError(ErrorInfo
const& iErrorInfo,
bool iConstructor)
472 #endif // THEOLIZER_INTERNAL_DOXYGEN 487 THEOLIZER_INTERNAL_DLL std::ostream&
operator<<(std::ostream& iOStream,
ErrorType iErrorType);
507 THEOLIZER_INTERNAL_DLL std::ostream&
operator<<(std::ostream& iOStream,
ErrorKind iErrorKind);
526 char const* mFileName;
541 void setMessage(
u8string const& iMessage);
543 void setAdditionalInfo(
u8string const& iAdditionalInfo);
550 char const*
getFileName()
const {
return (mFileName)?mFileName:
"<none>";}
554 #if defined(__MINGW32__) 555 u8string const getMessage()
const {
return mMessage; }
560 #if defined(__MINGW32__) 561 u8string const getAdditionalInfo()
const {
return mAdditionalInfo; }
566 std::string getString()
const;
581 #if defined(__MINGW32__) 583 char mAdditionalInfo[256];
591 THEOLIZER_INTERNAL_DLL std::ostream&
operator<<(std::ostream& iOStream,
ErrorInfo iErrorInfo);
602 #ifndef THEOLIZER_INTERNAL_DOXYGEN 603 THEOLIZER_INTERNAL_DLL
extern WeakData<char const*> gErrorLogPath;
604 #endif // THEOLIZER_INTERNAL_DOXYGEN 608 #define THEOLIZER_ERRORLOG_FILE(dErrorLogName) \ 609 THEOLIZER_INTERNAL_SET_WEAK_DATA(theolizer::internal::gErrorLogPath, \ 610 char const*, dErrorLogName, ErrorLogPathDummy) 618 #ifndef THEOLIZER_INTERNAL_DOXYGEN 621 void throwDeferred(u8string
const&,
ErrorKind,
char const*,
unsigned);
622 bool writeWarning(u8string
const&,
ErrorKind,
char const*,
unsigned) noexcept;
623 #endif // THEOLIZER_INTERNAL_DOXYGEN 639 friend class internal::Releasing;
640 friend class internal::ApiBoundary;
641 friend void internal::throwDeferred(
u8string const&,
ErrorKind,
char const*,
unsigned);
642 friend bool internal::writeWarning(
u8string const&,
ErrorKind,
char const*,
unsigned) noexcept;
644 unsigned mReleaseCount;
647 internal::BaseAdditionalInfo* mAdditionalInfo;
662 mAdditionalInfo(
nullptr),
676 char const* iFileName,
681 void throwDeferredImpl
685 char const* iFileName,
690 bool writeWarningImpl
694 char const* iFileName,
699 void clearError() noexcept;
705 return getInstance().mErrorInfo;
711 return getInstance().mErrorInfo.
isError();
717 return getInstance().clearError();
723 #ifndef THEOLIZER_INTERNAL_DOXYGEN 730 inline void throwDeferred
734 char const* iFileName=
nullptr,
738 ErrorReporter::getInstance().throwDeferredImpl(iMessage, iErrorKind, iFileName, iLineNo);
743 inline bool writeWarning
747 char const* iFileName=
nullptr,
751 return ErrorReporter::getInstance().writeWarningImpl(iMessage, iErrorKind, iFileName, iLineNo);
763 ErrorReporter::getInstance().mReleaseCount++;
765 ~Releasing() noexcept(
false)
767 auto&& aErrorReporter=ErrorReporter::getInstance();
769 THEOLIZER_INTERNAL_ASSERT(aErrorReporter.mReleaseCount,
770 "mReleaseCount is zero at ~Releasing().");
772 aErrorReporter.mReleaseCount--;
775 if ((aErrorReporter.mReleaseCount == 0) && (aErrorReporter.mIsDeferred))
777 aErrorReporter.mIsDeferred=
false;
778 throw aErrorReporter.mErrorInfo;
799 ApiBoundary(BaseAdditionalInfo* iAdditionalInfo,
bool iConstructor=
false) noexcept :
800 mRegistered(
false), mConstructor(iConstructor)
802 auto&& aErrorReporter=ErrorReporter::getInstance();
803 if (aErrorReporter.mRegistered)
807 aErrorReporter.resetError();
808 aErrorReporter.mAdditionalInfo=iAdditionalInfo;
809 aErrorReporter.mRegistered=
true;
811 ~ApiBoundary() noexcept
813 auto&& aErrorReporter=ErrorReporter::getInstance();
817 if (aErrorReporter.mAdditionalInfo)
819 aErrorReporter.mAdditionalInfo->setError(aErrorReporter.mErrorInfo, mConstructor);
821 aErrorReporter.mRegistered=
false;
822 aErrorReporter.mAdditionalInfo=
nullptr;
823 aErrorReporter.mProcessing=
false;
824 aErrorReporter.mIsDeferred=
false;
829 #endif // THEOLIZER_INTERNAL_DOXYGEN 840 bool mConstructorError;
847 std::unique_ptr<Impl> mImpl;
854 void setError(
ErrorInfo const& iErrorInfo,
bool iConstructor) noexcept;
879 #ifndef THEOLIZER_INTERNAL_DOXYGEN 886 #define THEOLIZER_INTERNAL_IO_ERROR(...) \ 887 theolizer::internal::throwDeferred \ 889 theolizer::print(__VA_ARGS__), \ 890 theolizer::ErrorKind::IOError, \ 891 THEOLIZER_INTERNAL_FILE, \ 895 #define THEOLIZER_INTERNAL_WRONG_USING(...) \ 896 theolizer::internal::throwDeferred \ 898 theolizer::print(__VA_ARGS__), \ 899 theolizer::ErrorKind::WrongUsing, \ 900 THEOLIZER_INTERNAL_FILE, \ 904 #define THEOLIZER_INTERNAL_DATA_ERROR(...) \ 905 theolizer::internal::throwDeferred \ 907 theolizer::print(__VA_ARGS__), \ 908 theolizer::ErrorKind::UnknownData, \ 909 THEOLIZER_INTERNAL_FILE, \ 913 #define THEOLIZER_INTERNAL_VERSION_ERROR(...) \ 914 theolizer::internal::throwDeferred \ 916 theolizer::print(__VA_ARGS__), \ 917 theolizer::ErrorKind::UnknownVerson, \ 918 THEOLIZER_INTERNAL_FILE, \ 924 #define THEOLIZER_INTERNAL_ERROR(...) \ 925 theolizer::internal::throwDeferred \ 927 theolizer::print(__VA_ARGS__), \ 928 theolizer::ErrorKind::Unclassified, \ 929 THEOLIZER_INTERNAL_FILE, \ 933 #define THEOLIZER_INTERNAL_WARNING(...) \ 934 theolizer::internal::writeWarning \ 936 theolizer::print(__VA_ARGS__), \ 937 theolizer::ErrorKind::Unclassified, \ 938 THEOLIZER_INTERNAL_FILE, \ 942 #endif // THEOLIZER_INTERNAL_DOXYGEN 959 #endif // THEOLIZER_INTERNAL_REPORT_H ErrorInfo const & getErrorInfo() const
エラー情報返却(3-1-2.メンバ関数 参照)
bool isError() const
エラーならtrue
unsigned getLineNo() const
エラーを検出したソース・ファイルの行番号返却
LogStream & operator<<(Type iObject)
出力演算子
static void resetError() noexcept
エラー状態を解除する
Unicode記録用文字列クラスu8string.
void setUTCTime(bool iIsUTC)
行ヘッダの時刻を設定する(UTCタイム or ローカルタイム)
ErrorType getErrorType() const
エラー種別コード返却
u8string const & getMessage() const
メッセージ返却
u8string const & getAdditionalInfo() const
追加情報返却
bool isError()
エラー発生ならtrue(3-1-2.メンバ関数 参照)
u8string print(u8string const &iFormat, tParams... iParams)
boost::formatのラッパ。
static ErrorInfo const & getErrorInfo() noexcept
エラー情報返却
char const * getFileName() const
エラーを検出したソース・ファイル名返却
ErrorKind getErrorKind() const
エラー分類コード返却
THEOLIZER_INTERNAL_DLL std::ostream & operator<<(std::ostream &iOStream, CheckMode iCheckMode)
CheckModeの表示用オーバーロード
static bool isError() noexcept
エラー発生ならtrue
bool operator!() const
エラーも警告もないならtrue