~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/error.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#ifndef DRIZZLED_ERROR_H
21
 
#define DRIZZLED_ERROR_H
22
 
 
23
 
#include <string>
24
 
#include <boost/unordered_map.hpp>
25
 
 
26
 
#include "drizzled/definitions.h"
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
/* Max width of screen (for error messages) */
32
 
#define SC_MAXWIDTH 256
33
 
#define ERRMSGSIZE      (SC_MAXWIDTH)   /* Max length of a error message */
34
 
#define NRERRBUFFS      (2)     /* Buffers for parameters */
35
 
#define MY_FILE_ERROR   ((size_t) -1)
36
 
#define ME_FATALERROR   1024    /* Fatal statement error */
37
 
 
38
 
/*
39
 
 * Provides a mapping from the error enum values to std::strings.
40
 
 */
41
 
class ErrorMap
42
 
{
43
 
public:
44
 
  typedef std::pair<std::string, std::string> value_type;
45
 
  typedef boost::unordered_map<uint32_t, value_type> ErrorMessageMap;
46
 
 
47
 
  ErrorMap();
48
 
 
49
 
  // Insert the message for the error.  If the error already has an existing
50
 
  // mapping, an error is logged, but the function continues.
51
 
  void add(uint32_t error_num, const std::string &error_name, const std::string &message);
52
 
 
53
 
  // If there is no error mapping for the error_num, ErrorStringNotFound is raised.
54
 
  const std::string &find(uint32_t error_num) const;
55
 
 
56
 
  static const ErrorMessageMap& get_error_message_map();
57
 
private:
58
 
  // Disable copy and assignment.
59
 
  ErrorMap(const ErrorMap &e);
60
 
  ErrorMap& operator=(const ErrorMap &e);
61
 
 
62
 
  ErrorMessageMap mapping_;
63
 
};
64
 
 
65
 
 
66
 
typedef void (*error_handler_func)(uint32_t my_err,
67
 
                                   const char *str,
68
 
                                   myf MyFlags);
69
 
extern error_handler_func error_handler_hook;
70
 
 
71
 
// TODO: kill this method. Too much to do with this branch.
72
 
// This is called through the ER(x) macro.
73
 
const char * error_message(unsigned int err_index);
74
 
 
75
 
// Adds the message to the global error dictionary.
76
 
void add_error_message(uint32_t error_code, const std::string &error_name,
77
 
                       const std::string& message);
78
 
#define DRIZZLE_ADD_ERROR_MESSAGE(code, msg) add_error_message(code, STRINGIFY_ARG(code), msg)
79
 
 
80
 
void my_error(int nr, myf MyFlags, ...);
81
 
void my_message(uint32_t my_err, const char *str, myf MyFlags);
82
 
void my_printf_error(uint32_t my_err, const char *format,
83
 
                     myf MyFlags, ...)
84
 
                     __attribute__((format(printf, 2, 4)));
85
 
 
86
 
} /* namespace drizzled */
87
 
 
88
 
#endif /* DRIZZLED_ERROR_H */