~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/error.h

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
 
20
21
#ifndef DRIZZLED_ERROR_H
21
22
#define DRIZZLED_ERROR_H
22
23
 
23
24
#include <string>
 
25
#include <boost/unordered_map.hpp>
 
26
 
 
27
#include "drizzled/error_t.h"
24
28
#include "drizzled/definitions.h"
 
29
#include "drizzled/identifier.h"
 
30
 
 
31
#include "drizzled/visibility.h"
25
32
 
26
33
namespace drizzled
27
34
{
33
40
#define MY_FILE_ERROR   ((size_t) -1)
34
41
#define ME_FATALERROR   1024    /* Fatal statement error */
35
42
 
36
 
typedef void (*error_handler_func)(uint32_t my_err,
 
43
/*
 
44
 * Provides a mapping from the error enum values to std::strings.
 
45
 */
 
46
class ErrorMap
 
47
{
 
48
public:
 
49
  typedef std::pair<std::string, std::string> value_type;
 
50
  typedef boost::unordered_map<drizzled::error_t, value_type> ErrorMessageMap;
 
51
 
 
52
  ErrorMap();
 
53
 
 
54
  // Insert the message for the error.  If the error already has an existing
 
55
  // mapping, an error is logged, but the function continues.
 
56
  void add(drizzled::error_t error_num, const std::string &error_name, const std::string &message);
 
57
 
 
58
  // If there is no error mapping for the error_num, ErrorStringNotFound is raised.
 
59
  const std::string &find(drizzled::error_t error_num) const;
 
60
 
 
61
  static const ErrorMessageMap& get_error_message_map();
 
62
private:
 
63
  // Disable copy and assignment.
 
64
  ErrorMap(const ErrorMap &e);
 
65
  ErrorMap& operator=(const ErrorMap &e);
 
66
 
 
67
  ErrorMessageMap mapping_;
 
68
};
 
69
 
 
70
 
 
71
typedef void (*error_handler_func)(drizzled::error_t my_err,
37
72
                                   const char *str,
38
73
                                   myf MyFlags);
39
74
extern error_handler_func error_handler_hook;
40
75
 
41
76
// TODO: kill this method. Too much to do with this branch.
42
77
// This is called through the ER(x) macro.
43
 
const char * error_message(unsigned int err_index);
 
78
DRIZZLED_API const char * error_message(drizzled::error_t err_index);
44
79
 
45
80
// Adds the message to the global error dictionary.
46
 
void add_error_message(uint32_t error_code, std::string const& message);
 
81
void add_error_message(drizzled::error_t error_code, const std::string &error_name,
 
82
                       const std::string& message);
 
83
#define DRIZZLE_ADD_ERROR_MESSAGE(code, msg) add_error_message(code, STRINGIFY_ARG(code), msg)
47
84
 
48
 
void my_error(int nr, myf MyFlags, ...);
49
 
void my_message(uint32_t my_err, const char *str, myf MyFlags);
50
 
void my_printf_error(uint32_t my_err, const char *format,
 
85
DRIZZLED_API void my_error(const std::string &ref, error_t nr, myf MyFlags= MYF(0));
 
86
DRIZZLED_API void my_error(error_t nr, drizzled::Identifier::const_reference ref, myf MyFlags= MYF(0));
 
87
DRIZZLED_API void my_error(error_t nr);
 
88
DRIZZLED_API void my_error(error_t nr, myf MyFlags, ...);
 
89
void my_message(drizzled::error_t my_err, const char *str, myf MyFlags);
 
90
void my_printf_error(drizzled::error_t my_err, const char *format,
51
91
                     myf MyFlags, ...)
52
92
                     __attribute__((format(printf, 2, 4)));
53
93