Drizzled Public API Documentation

lex_string.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <cstddef>
00023 #include <drizzled/util/data_ref.h>
00024 
00025 namespace drizzled {
00026 
00027 /*
00028   lex_string_t -- a pair of a C-string and its length.
00029 */
00030 
00031 /* This definition must match the one given in mysql/plugin.h */
00032 struct lex_string_t
00033 {
00034   const char* begin() const
00035   {
00036     return data();
00037   }
00038 
00039   const char* end() const
00040   {
00041     return data() + size();
00042   }
00043 
00044   const char* data() const
00045   {
00046     return str_;
00047   }
00048 
00049   size_t size() const
00050   {
00051     return length_;
00052   }
00053 
00054   void assign(const char* d, size_t s)
00055   {
00056     str_= const_cast<char*>(d);
00057     length_ = s;
00058   }
00059 
00060   void operator=(str_ref v)
00061   {
00062     assign(v.data(), v.size());
00063   }
00064 
00065   char* str_;
00066   size_t length_;
00067 };
00068 
00069 inline const lex_string_t &null_lex_string()
00070 {
00071   static lex_string_t tmp= { NULL, 0 };
00072   return tmp;
00073 }
00074 
00075 struct execute_string_t : public lex_string_t
00076 {
00077 private:
00078   bool is_variable;
00079 public:
00080 
00081   bool isVariable() const
00082   {
00083     return is_variable;
00084   }
00085 
00086   void set(const lex_string_t& s, bool is_variable_arg= false)
00087   {
00088     is_variable= is_variable_arg;
00089     static_cast<lex_string_t&>(*this) = s;
00090   }
00091 
00092 };
00093 
00094 #define STRING_WITH_LEN(X) (X), (sizeof(X) - 1)
00095 #define C_STRING_WITH_LEN(X) const_cast<char*>(X), (sizeof(X) - 1)
00096 
00097 } /* namespace drizzled */
00098