X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Ffatal.hpp;h=6ac62b775f84b224ce0673cea507b2e8a3f43f3f;hb=00a8f6f7d315dc3fce0b0e5a1987c8663488ae1c;hp=54f672b652a8808973de15800def96a430e8d009;hpb=f363012dbad70fe0d1e6d714f432e1567cef4935;p=awesomized%2Flibmemcached diff --git a/libtest/fatal.hpp b/libtest/fatal.hpp index 54f672b6..6ac62b77 100644 --- a/libtest/fatal.hpp +++ b/libtest/fatal.hpp @@ -42,18 +42,35 @@ #define __PRETTY_FUNCTION__ __func__ #endif +#define YATL_STRINGIFY(x) #x +#define YATL_TOSTRING(x) YATL_STRINGIFY(x) +#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__) +#define YATL_AT_PARAM __func__, AT +#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique" +#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func" + #define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__ namespace libtest { -class fatal : std::runtime_error +class exception : public std::runtime_error { public: - fatal(const char *file, int line, const char *func, const char *format, ...); + exception(const char *, int, const char *); - const char* what() const throw() + int line() const { - return _error_message; + return _line; + } + + const char* file() const + { + return _file; + } + + const char* func() const + { + return _func; } const char* mesg() const throw() @@ -61,6 +78,26 @@ public: return _error_message; } + +protected: + char _error_message[BUFSIZ]; + +private: + const char* _file; + int _line; + const char* _func; +}; + +class fatal : public exception +{ +public: + fatal(const char *file, int line, const char *func, const char *format, ...); + + const char* what() const throw() + { + return _error_message; + } + // The following are just for unittesting the exception class static bool is_disabled(); static void disable(); @@ -68,33 +105,35 @@ public: static uint32_t disabled_counter(); static void increment_disabled_counter(); - int line() - { - return _line; - } +private: +}; - const char* file() - { - return _file; - } +class disconnected : public exception +{ +public: + disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, const char *format, ...); - const char* func() + const char* what() const throw() { - return _func; + return _error_message; } + // The following are just for unittesting the exception class + static bool is_disabled(); + static void disable(); + static void enable(); + static uint32_t disabled_counter(); + static void increment_disabled_counter(); + private: - char _error_message[BUFSIZ]; - char _mesg[BUFSIZ]; - int _line; - const char* _file; - const char* _func; + in_port_t _port; + char _instance[1024]; }; -class disconnected : std::runtime_error +class start : public exception { public: - disconnected(const char *file, int line, const char *func, const char *instance, const in_port_t port, const char *format, ...); + start(const char *file, int line, const char *func, const std::string&, const in_port_t port, const char *format, ...); const char* what() const throw() { @@ -109,7 +148,6 @@ public: static void increment_disabled_counter(); private: - char _error_message[BUFSIZ]; in_port_t _port; char _instance[1024]; };