~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unireg.h

  • Committer: Brian Aker
  • Date: 2011-07-18 02:56:15 UTC
  • mto: (2392.1.1 drizzle-autoconf)
  • mto: This revision was merged to the branch mainline in revision 2399.
  • Revision ID: brian@tangent.org-20110718025615-2an7nztjcb38c2ur
Add better error messages for issues on startup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#pragma once
24
24
 
25
25
#include <drizzled/visibility.h>
 
26
#include <sstream>
26
27
 
27
28
namespace drizzled
28
29
{
29
30
 
30
 
DRIZZLED_API void unireg_abort(int exit_code) __attribute__((noreturn));
 
31
void unireg_exit() __attribute__((noreturn));
 
32
DRIZZLED_API void unireg_actual_abort(const char *file, int line, const char *func, const std::string& message) __attribute__((noreturn));
 
33
 
 
34
namespace stream {
 
35
 
 
36
namespace detail {
 
37
 
 
38
template<class Ch, class Tr, class A>
 
39
  class _unireg {
 
40
  private:
 
41
 
 
42
  public:
 
43
    typedef std::basic_ostringstream<Ch, Tr, A> stream_buffer;
 
44
 
 
45
  public:
 
46
    void operator()(const stream_buffer &s, const char *filename, int line, const char *func)
 
47
    {
 
48
      unireg_actual_abort(filename, line, func, s.str());
 
49
    }
 
50
  };
 
51
 
 
52
template<template <class Ch, class Tr, class A> class OutputPolicy, class Ch = char, class Tr = std::char_traits<Ch>, class A = std::allocator<Ch> >
 
53
  class log {
 
54
  private:
 
55
    typedef OutputPolicy<Ch, Tr, A> output_policy;
 
56
    const char *_filename;
 
57
    int _line_number;
 
58
    const char *_func;
 
59
 
 
60
  public:
 
61
    log() :
 
62
      _filename(NULL),
 
63
      _line_number(0),
 
64
      _func(NULL)
 
65
    { }
 
66
 
 
67
    void set_filename(const char *filename, int line_number, const char *func)
 
68
    {
 
69
      _filename= filename;
 
70
      _line_number= line_number;
 
71
      _func= func;
 
72
    }
 
73
 
 
74
    ~log()
 
75
    {
 
76
      output_policy()(arg, _filename, _line_number, _func);
 
77
    }
 
78
 
 
79
  public:
 
80
    template<class T>
 
81
      log &operator<<(const T &x)
 
82
      {
 
83
        arg << x;
 
84
        return *this;
 
85
      }
 
86
 
 
87
  private:
 
88
    typename output_policy::stream_buffer arg;
 
89
  };
 
90
} // namespace detail
 
91
 
 
92
class _unireg : public detail::log<detail::_unireg> {
 
93
public:
 
94
  _unireg(const char *filename, int line_number, const char *func)
 
95
  {
 
96
    set_filename(filename, line_number, func);
 
97
  }
 
98
};
 
99
 
 
100
} // namespace stream
 
101
 
 
102
#define unireg_abort stream::_unireg(__FILE__, __LINE__, __func__)
31
103
 
32
104
} /* namespace drizzled */
33