drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
lex_string.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; 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#pragma once
21
22#include <cstddef>
23#include <drizzled/util/data_ref.h>
24
25namespace drizzled {
26
27/*
28 lex_string_t -- a pair of a C-string and its length.
29*/
30
31/* This definition must match the one given in mysql/plugin.h */
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
69inline const lex_string_t &null_lex_string()
70{
71 static lex_string_t tmp= { NULL, 0 };
72 return tmp;
73}
74
76{
77private:
78 bool is_variable;
79public:
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
TODO: Rename this file - func.h is stupid.