Bind.hh

00001 //********************************************************************
00002 //*** ResourcePool/SQL/Bind.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: Bind.hh,v 1.21 2009-05-04 16:11:32 mws Exp $
00005 //********************************************************************
00006 /*
00007 This file is part of ResourcePool.
00008 
00009 ResourcePool is free software; you can redistribute it
00010 and/or modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2 of 
00012 the License, or (at your option) any later version.
00013 
00014 ResourcePool is distributed in the hope that it will be
00015 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00016 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with ResourcePool; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00022 02111-1307  USA */
00023 
00024 #ifndef RESOURCEPOOL_SQL_BIND_HH
00025 #define RESOURCEPOOL_SQL_BIND_HH
00026 
00027 #include "ResourcePool/SQL/BindInterface.hh"
00028 
00029 #ifndef INCLUDED_GC_PTR_HH
00030 #include "mm/gc_ptr.hh"
00031 #endif
00032 
00033 #include <vector>
00034 
00035 namespace fatalmind {
00036 namespace SQL {
00037 
00042 template<class VBC, template <class> class CT>
00043 class Bind: public BindInterface {
00044     public:
00045         typedef VBC _datat;
00046         typedef gc_ptr<VBC> _ptrt;
00047         typedef std::vector<_ptrt> _argst;
00048     protected:
00049         _argst _args;
00050     public:
00051         virtual ~Bind() {
00052         }
00053 
00054                 virtual void bind(const unsigned int pos, const char& val, bool isnull = false) {
00055                         bindTpl(pos, val, isnull);
00056                 }
00057                 virtual void bind(const unsigned int pos, const signed char& val, bool isnull = false) {
00058                         bindTpl(pos, val, isnull);
00059                 }
00060                 virtual void bind(const unsigned int pos, const unsigned char& val, bool isnull = false) {
00061                         bindTpl(pos, val, isnull);
00062                 }
00063 
00064                 virtual void bind(const unsigned int pos, const short int& val, bool isnull = false) {
00065                         bindTpl(pos, val, isnull);
00066                 }
00067                 virtual void bind(const unsigned int pos, const unsigned short int& val, bool isnull = false) {
00068                         bindTpl(pos, val, isnull);
00069                 }
00070 
00071                 virtual void bind(const unsigned int pos, const int& val, bool isnull = false) {
00072                         bindTpl(pos, val, isnull);
00073                 }
00074                 virtual void bind(const unsigned int pos, const unsigned int& val, bool isnull = false) {
00075                         bindTpl(pos, val, isnull);
00076                 }
00077 
00078                 virtual void bind(const unsigned int pos, const long int& val, bool isnull = false) {
00079                         bindTpl(pos, val, isnull);
00080                 }
00081                 virtual void bind(const unsigned int pos, const unsigned long int& val, bool isnull = false) {
00082                         bindTpl(pos, val, isnull);
00083                 }
00084 
00085                 virtual void bind(const unsigned int pos, const float& val, bool isnull = false) {
00086                         bindTpl(pos, val, isnull);
00087                 }
00088                 virtual void bind(const unsigned int pos, const double& val, bool isnull = false) {
00089                         bindTpl(pos, val, isnull);
00090                 }
00091                 virtual void bind(const unsigned int pos, const long double& val, bool isnull = false) {
00092                         bindTpl(pos, val, isnull);
00093                 }
00094                 virtual void bind(const unsigned int pos, const std::string& val, bool isnull = false) {
00095                         bindTpl(pos, val, isnull);
00096                 }
00097     
00098         virtual void clearParameters();
00099 
00100         virtual void bindoutputoperator(std::ostream& str) const;
00101         static void bindoutputoperator(std::ostream& str, const _argst&);
00102 
00103     private:
00104         template<typename T>
00105         inline
00106         void bindTpl(const unsigned int pos, const T& val, bool nul = false) {
00107                 gc_ptr<VBC> ptr(new CT<T>(val, nul)); // gc_ptr must be available during complete bindPtr call (passed by ref)
00108                 bindPtr(pos, ptr);
00109         }
00110         // the bindPtr function performs the real work
00111         // the bind() function above is inlined and just a wrapper
00112         // to this function, which is NOT a function tempalte
00113         // gc_ptr by ref, private and no threading at this point
00114         void bindPtr(const unsigned int pos, gc_ptr<VBC>& ptr);
00115 
00116 };
00117 
00118 } // namespace SQL
00119 } // namespace fatalmind
00120 
00121 #endif

Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3