Drizzled Public API Documentation

functions.cc
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 #include <config.h>
00021 
00022 #include <drizzled/function/bit/functions.h>
00023 
00024 namespace drizzled
00025 {
00026 
00027 namespace function
00028 {
00029 
00030 namespace bit
00031 {
00032 
00033 int64_t ShiftLeft::val_int()
00034 {
00035   assert(fixed == 1);
00036   uint32_t shift;
00037   uint64_t res= ((uint64_t) args[0]->val_int() <<
00038       (shift=(uint) args[1]->val_int()));
00039   if (args[0]->null_value || args[1]->null_value)
00040   {
00041     null_value=1;
00042     return 0;
00043   }
00044   null_value=0;
00045 
00046   return (shift < sizeof(int64_t)*8 ? (int64_t) res : 0LL);
00047 }
00048 
00049 int64_t ShiftRight::val_int()
00050 {
00051   assert(fixed == 1);
00052   uint32_t shift;
00053   uint64_t res= (uint64_t) args[0]->val_int() >>
00054     (shift=(uint) args[1]->val_int());
00055 
00056   if (args[0]->null_value || args[1]->null_value)
00057   {
00058     null_value=1;
00059     return 0;
00060   }
00061   null_value=0;
00062 
00063   return (shift < sizeof(int64_t)*8 ? (int64_t) res : 0LL);
00064 }
00065 
00066 
00067 int64_t Neg::val_int()
00068 {
00069   assert(fixed == 1);
00070   uint64_t res= (uint64_t) args[0]->val_int();
00071 
00072   if ((null_value=args[0]->null_value))
00073     return 0;
00074 
00075   return ~res;
00076 }
00077 
00078 
00079 int64_t Xor::val_int()
00080 {
00081   assert(fixed == 1);
00082   uint64_t arg1= (uint64_t) args[0]->val_int();
00083   uint64_t arg2= (uint64_t) args[1]->val_int();
00084 
00085   if ((null_value= (args[0]->null_value || args[1]->null_value)))
00086     return 0;
00087 
00088   return (int64_t) (arg1 ^ arg2);
00089 }
00090 
00091 int64_t Or::val_int()
00092 {
00093   assert(fixed == 1);
00094 
00095   uint64_t arg1= (uint64_t) args[0]->val_int();
00096   if (args[0]->null_value)
00097   {
00098     null_value=1; /* purecov: inspected */
00099     return 0; /* purecov: inspected */
00100   }
00101 
00102   uint64_t arg2= (uint64_t) args[1]->val_int();
00103   if (args[1]->null_value)
00104   {
00105     null_value=1;
00106     return 0;
00107   }
00108   null_value=0;
00109 
00110   return (int64_t) (arg1 | arg2);
00111 }
00112 
00113 int64_t And::val_int()
00114 {
00115   assert(fixed == 1);
00116 
00117   uint64_t arg1= (uint64_t) args[0]->val_int();
00118 
00119   if (args[0]->null_value)
00120   {
00121     null_value=1; /* purecov: inspected */
00122     return 0; /* purecov: inspected */
00123   }
00124 
00125   uint64_t arg2= (uint64_t) args[1]->val_int();
00126 
00127   if (args[1]->null_value)
00128   {
00129     null_value=1; /* purecov: inspected */
00130     return 0; /* purecov: inspected */
00131   }
00132   null_value=0;
00133 
00134   return (int64_t) (arg1 & arg2);
00135 }
00136 
00137 } /* namespace bit */
00138 } /* namespace function */
00139 } // namespace drizzled