Drizzled Public API Documentation

enum.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 MySQL
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; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <drizzled/field/str.h>
00024 
00025 namespace drizzled
00026 {
00027 
00028 class Field_enum :public Field_str
00029 {
00030 public:
00031 
00032   using Field::store;
00033   using Field::val_int;
00034   using Field::val_str;
00035   using Field::cmp;
00036 
00037   static const int max_supported_elements = 0x10000;
00038 
00040   TYPELIB *typelib;
00041   Field_enum(unsigned char *ptr_arg,
00042              uint32_t len_arg,
00043              unsigned char *null_ptr_arg,
00044              unsigned char null_bit_arg,
00045              const char *field_name_arg,
00046              TYPELIB *typelib_arg,
00047              const CHARSET_INFO * const charset_arg)
00048     :Field_str(ptr_arg,
00049                len_arg,
00050                null_ptr_arg,
00051                null_bit_arg,
00052                field_name_arg,
00053                charset_arg),
00054     typelib(typelib_arg)
00055   {
00056     flags|= ENUM_FLAG;
00057   }
00058   Field *new_field(memory::Root *root, Table *new_table, bool keep_type);
00059   enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
00060   int  store(const char *to, uint32_t length, const CHARSET_INFO * const);
00061   int  store(double nr);
00062   int  store(int64_t nr, bool unsigned_val);
00063   double val_real(void) const;
00064   int64_t val_int(void) const;
00065   String *val_str(String*, String *) const;
00066   int cmp(const unsigned char *, const unsigned char *);
00067   void sort_string(unsigned char *buff, uint32_t length);
00068   void store_type(uint64_t value);
00069   void sql_type(String &str) const;
00070   bool eq_def(Field *field);
00071   enum_field_types type() const
00072   {
00073     return DRIZZLE_TYPE_ENUM;
00074   }
00075   enum Item_result cmp_type () const
00076   {
00077     return INT_RESULT;
00078   }
00079   enum Item_result cast_to_int_type () const
00080   {
00081     return INT_RESULT;
00082   }
00083   uint32_t pack_length() const { return 4; }
00084   uint32_t size_of() const
00085   {
00086     return sizeof(*this);
00087   }
00088   enum_field_types real_type() const
00089   {
00090     return DRIZZLE_TYPE_ENUM;
00091   }
00092   virtual bool zero_pack() const
00093   {
00094     return false;
00095   }
00096   bool optimize_range(uint32_t, uint32_t)
00097   {
00098     return false;
00099   }
00100   bool has_charset(void) const
00101   {
00102     return true;
00103   }
00104   /* enum and set are sorted as integers */
00105   const CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
00106 };
00107 
00108 } /* namespace drizzled */
00109