diff options
author | chai <chaifix@163.com> | 2018-11-03 21:11:41 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-11-03 21:11:41 +0800 |
commit | 281f8feabffd69928a0a0f08aa31f70b36f5e6bd (patch) | |
tree | a22413447a5480a5dffe625c677ad7c4140350c5 /src/libjin/Common | |
parent | f6ef5d6c0188e7dc6b39803ca37fe736f0eb3962 (diff) |
*增加游戏目录选择
Diffstat (limited to 'src/libjin/Common')
-rw-r--r-- | src/libjin/Common/je_common.h | 1 | ||||
-rw-r--r-- | src/libjin/Common/je_exception.cpp | 46 | ||||
-rw-r--r-- | src/libjin/Common/je_exception.h | 29 |
3 files changed, 73 insertions, 3 deletions
diff --git a/src/libjin/Common/je_common.h b/src/libjin/Common/je_common.h index 67505c1..31b67c6 100644 --- a/src/libjin/Common/je_common.h +++ b/src/libjin/Common/je_common.h @@ -1,6 +1,7 @@ #ifndef __JE_COMMON_H__ #define __JE_COMMON_H__ +#include "je_exception.h" #include "je_array.hpp" #endif
\ No newline at end of file diff --git a/src/libjin/Common/je_exception.cpp b/src/libjin/Common/je_exception.cpp index e69de29..5489a42 100644 --- a/src/libjin/Common/je_exception.cpp +++ b/src/libjin/Common/je_exception.cpp @@ -0,0 +1,46 @@ +#include <stdarg.h> + +#include "je_exception.h" + +namespace JinEngine +{ + + Exception::Exception(const char *fmt, ...) + { + va_list args; + int size_buffer = 256, size_out; + char *buffer; + while (true) + { + buffer = new char[size_buffer]; + memset(buffer, 0, size_buffer); + + va_start(args, fmt); + size_out = vsnprintf(buffer, size_buffer, fmt, args); + va_end(args); + + // see http://perfec.to/vsnprintf/pasprintf.c + // if size_out ... + // == -1 --> output was truncated + // == size_buffer --> output was truncated + // == size_buffer-1 --> ambiguous, /may/ have been truncated + // > size_buffer --> output was truncated, and size_out + // bytes would have been written + if (size_out == size_buffer || size_out == -1 || size_out == size_buffer - 1) + size_buffer *= 2; + else if (size_out > size_buffer) + size_buffer = size_out + 2; // to avoid the ambiguous case + else + break; + + delete[] buffer; + } + mMessage = std::string(buffer); + delete[] buffer; + } + + Exception::~Exception() throw() + { + } + +} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Common/je_exception.h b/src/libjin/Common/je_exception.h index cf11f51..c319ebd 100644 --- a/src/libjin/Common/je_exception.h +++ b/src/libjin/Common/je_exception.h @@ -2,18 +2,41 @@ #define __JE_EXCEPTION_H__ #include <exception> +#include <string> namespace JinEngine { /// - /// Built-in exception class. + /// Jin Exception. /// class Exception : public std::exception { public: - Exception(); - const char* what() const throw(); + + /// + /// Creates a new Exception according to printf-rules. + /// + /// @param fmt The format string (see printf). + /// + Exception(const char *fmt, ...); + virtual ~Exception() throw(); + + /// + /// Returns a string containing reason for the exception. + /// + /// @return A description of the exception. + /// + inline virtual const char *what() const throw() + { + return mMessage.c_str(); + } + + private: + /// + /// Exception message. + /// + std::string mMessage; }; |