Drizzled Public API Documentation

unireg.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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /* Extra functions used by unireg library */
22 
23 #pragma once
24 
25 #include <drizzled/visibility.h>
26 #include <sstream>
27 
28 namespace drizzled
29 {
30 
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 void unireg_startup_finished();
34 
35 namespace stream {
36 
37 namespace detail {
38 
39 template<class Ch, class Tr, class A>
40  class _unireg {
41  private:
42 
43  public:
44  typedef std::basic_ostringstream<Ch, Tr, A> stream_buffer;
45 
46  public:
47  void operator()(const stream_buffer &s, const char *filename, int line, const char *func)
48  {
49  unireg_actual_abort(filename, line, func, s.str());
50  }
51  };
52 
53 template<template <class Ch, class Tr, class A> class OutputPolicy, class Ch = char, class Tr = std::char_traits<Ch>, class A = std::allocator<Ch> >
54  class log {
55  private:
56  typedef OutputPolicy<Ch, Tr, A> output_policy;
57  const char *_filename;
58  int _line_number;
59  const char *_func;
60 
61  public:
62  log() :
63  _filename(NULL),
64  _line_number(0),
65  _func(NULL)
66  { }
67 
68  void set_filename(const char *filename, int line_number, const char *func)
69  {
70  _filename= filename;
71  _line_number= line_number;
72  _func= func;
73  }
74 
75  ~log()
76  {
77  output_policy()(arg, _filename, _line_number, _func);
78  }
79 
80  public:
81  template<class T>
82  log &operator<<(const T &x)
83  {
84  arg << x;
85  return *this;
86  }
87 
88  private:
89  typename output_policy::stream_buffer arg;
90  };
91 } // namespace detail
92 
93 class _unireg : public detail::log<detail::_unireg> {
94 public:
95  _unireg(const char *filename, int line_number, const char *func)
96  {
97  set_filename(filename, line_number, func);
98  }
99 };
100 
101 } // namespace stream
102 
103 #define unireg_abort stream::_unireg(__FILE__, __LINE__, __func__)
104 
105 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.
#define DRIZZLED_API
Definition: visibility.h:62
Visibility Control Macros.