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