Drizzled Public API Documentation

cache.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 <drizzled/item/basic_constant.h>
00023 #include <drizzled/item/field.h>
00024 #include <drizzled/item/ident.h>
00025 #include <drizzled/type/decimal.h>
00026 #include <drizzled/util/test.h>
00027 
00028 namespace drizzled
00029 {
00030 
00031 class Item_cache: public Item_basic_constant
00032 {
00033 protected:
00034   Item *example;
00035   table_map used_table_map;
00036   /*
00037     Field that this object will get value from. This is set/used by
00038     index-based subquery engines to detect and remove the equality injected
00039     by IN->EXISTS transformation.
00040     For all other uses of Item_cache, cached_field doesn't matter.
00041   */
00042   Field *cached_field;
00043   enum enum_field_types cached_field_type;
00044 public:
00045   Item_cache():
00046     example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
00047   {
00048     fixed= 1;
00049     null_value= 1;
00050   }
00051   Item_cache(enum_field_types field_type_arg):
00052     example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
00053   {
00054     fixed= 1;
00055     null_value= 1;
00056   }
00057 
00058   void set_used_tables(table_map map) { used_table_map= map; }
00059 
00060   virtual bool allocate(uint32_t)
00061   { return 0; }
00062   virtual bool setup(Item *item)
00063   {
00064     example= item;
00065     max_length= item->max_length;
00066     decimals= item->decimals;
00067     collation.set(item->collation);
00068     unsigned_flag= item->unsigned_flag;
00069     if (item->type() == FIELD_ITEM)
00070       cached_field= ((Item_field *)item)->field;
00071     return 0;
00072   };
00073   virtual void store(Item *)= 0;
00074   enum Type type() const { return CACHE_ITEM; }
00075   enum_field_types field_type() const { return cached_field_type; }
00076   static Item_cache* get_cache(const Item *item);
00077   table_map used_tables() const { return used_table_map; }
00078   virtual void keep_array() {}
00079   virtual void print(String *str);
00080   bool eq_def(Field *field);
00081   bool eq(const Item *item, bool) const
00082   {
00083     return this == item;
00084   }
00085   bool basic_const_item() const
00086   {
00087     return test(example && example->basic_const_item());
00088   }
00089 };
00090 
00091 } /* namespace drizzled */
00092