~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/lex_string.h

Fix merge issues with 1.0 CC fix.

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
 
#ifndef DRIZZLED_LEX_STRING_H
21
 
#define DRIZZLED_LEX_STRING_H
22
 
 
23
 
#include <stddef.h>
 
20
#pragma once
 
21
 
 
22
#include <cstddef>
 
23
#include <drizzled/util/data_ref.h>
 
24
 
 
25
namespace drizzled {
24
26
 
25
27
/*
26
 
  LEX_STRING -- a pair of a C-string and its length.
 
28
  lex_string_t -- a pair of a C-string and its length.
27
29
*/
28
30
 
29
31
/* This definition must match the one given in mysql/plugin.h */
30
 
typedef struct st_mysql_lex_string
31
 
{
32
 
  char *str;
33
 
  size_t length;
34
 
} LEX_STRING;
35
 
 
36
 
 
37
 
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
38
 
#define USTRING_WITH_LEN(X) ((unsigned char*) X), ((size_t) (sizeof(X) - 1))
39
 
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
40
 
 
41
 
 
42
 
#endif /* DRIZZLED_LEX_STRING_H */
 
32
struct lex_string_t
 
33
{
 
34
  const char* begin() const
 
35
  {
 
36
    return data();
 
37
  }
 
38
 
 
39
  const char* end() const
 
40
  {
 
41
    return data() + size();
 
42
  }
 
43
 
 
44
  const char* data() const
 
45
  {
 
46
    return str_;
 
47
  }
 
48
 
 
49
  size_t size() const
 
50
  {
 
51
    return length_;
 
52
  }
 
53
 
 
54
  void assign(const char* d, size_t s)
 
55
  {
 
56
    str_= const_cast<char*>(d);
 
57
    length_ = s;
 
58
  }
 
59
 
 
60
  void operator=(str_ref v)
 
61
  {
 
62
    assign(v.data(), v.size());
 
63
  }
 
64
 
 
65
  char* str_;
 
66
  size_t length_;
 
67
};
 
68
 
 
69
inline const lex_string_t &null_lex_string()
 
70
{
 
71
  static lex_string_t tmp= { NULL, 0 };
 
72
  return tmp;
 
73
}
 
74
 
 
75
struct execute_string_t : public lex_string_t
 
76
{
 
77
private:
 
78
  bool is_variable;
 
79
public:
 
80
 
 
81
  bool isVariable() const
 
82
  {
 
83
    return is_variable;
 
84
  }
 
85
 
 
86
  void set(const lex_string_t& s, bool is_variable_arg= false)
 
87
  {
 
88
    is_variable= is_variable_arg;
 
89
    static_cast<lex_string_t&>(*this) = s;
 
90
  }
 
91
 
 
92
};
 
93
 
 
94
#define STRING_WITH_LEN(X) (X), (sizeof(X) - 1)
 
95
#define C_STRING_WITH_LEN(X) const_cast<char*>(X), (sizeof(X) - 1)
 
96
 
 
97
} /* namespace drizzled */
 
98