drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled_abort.h
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 * Copyright (C) 2011 Brian Aker
6 * Copyright (C) 2013 Stewart Smith
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22#pragma once
23
24#include <drizzled/visibility.h>
25#include <sstream>
26
27namespace drizzled
28{
29
30void drizzled_exit() __attribute__((noreturn));
31DRIZZLED_API void drizzled_actual_abort(const char *file, int line, const char *func, const std::string& message) __attribute__((noreturn));
32void drizzled_startup_finished();
33
34namespace stream {
35
36namespace detail {
37
38template<class Ch, class Tr, class A>
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 drizzled_actual_abort(filename, line, func, s.str());
49 }
50 };
51
52template<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
92class _drizzled_abort_log : public detail::log<detail::_drizzled_abort_log> {
93public:
94 _drizzled_abort_log(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 drizzled_abort stream::_drizzled_abort_log(__FILE__, __LINE__, __func__)
103
104} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38