00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024
00025 #include <drizzled/visibility.h>
00026 #include <sstream>
00027
00028 namespace drizzled
00029 {
00030
00031 void unireg_exit() __attribute__((noreturn));
00032 DRIZZLED_API void unireg_actual_abort(const char *file, int line, const char *func, const std::string& message) __attribute__((noreturn));
00033 void unireg_startup_finished();
00034
00035 namespace stream {
00036
00037 namespace detail {
00038
00039 template<class Ch, class Tr, class A>
00040 class _unireg {
00041 private:
00042
00043 public:
00044 typedef std::basic_ostringstream<Ch, Tr, A> stream_buffer;
00045
00046 public:
00047 void operator()(const stream_buffer &s, const char *filename, int line, const char *func)
00048 {
00049 unireg_actual_abort(filename, line, func, s.str());
00050 }
00051 };
00052
00053 template<template <class Ch, class Tr, class A> class OutputPolicy, class Ch = char, class Tr = std::char_traits<Ch>, class A = std::allocator<Ch> >
00054 class log {
00055 private:
00056 typedef OutputPolicy<Ch, Tr, A> output_policy;
00057 const char *_filename;
00058 int _line_number;
00059 const char *_func;
00060
00061 public:
00062 log() :
00063 _filename(NULL),
00064 _line_number(0),
00065 _func(NULL)
00066 { }
00067
00068 void set_filename(const char *filename, int line_number, const char *func)
00069 {
00070 _filename= filename;
00071 _line_number= line_number;
00072 _func= func;
00073 }
00074
00075 ~log()
00076 {
00077 output_policy()(arg, _filename, _line_number, _func);
00078 }
00079
00080 public:
00081 template<class T>
00082 log &operator<<(const T &x)
00083 {
00084 arg << x;
00085 return *this;
00086 }
00087
00088 private:
00089 typename output_policy::stream_buffer arg;
00090 };
00091 }
00092
00093 class _unireg : public detail::log<detail::_unireg> {
00094 public:
00095 _unireg(const char *filename, int line_number, const char *func)
00096 {
00097 set_filename(filename, line_number, func);
00098 }
00099 };
00100
00101 }
00102
00103 #define unireg_abort stream::_unireg(__FILE__, __LINE__, __func__)
00104
00105 }