SQLType.hh

00001 //********************************************************************
00002 //*** ResourcePool/mysql/SQLType.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: SQLType.hh,v 1.15 2009-03-14 15:12:25 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 
00025 #ifndef RESOURCEPOOL_MYSQL_SQLTYPE_HH
00026 #define RESOURCEPOOL_MYSQL_SQLTYPE_HH
00027 
00028 #include <iostream>
00029 
00030 #include "mm/gc_ptr.hh"
00031 
00032 namespace fatalmind {
00033 namespace mysql {
00034 
00035 class SQLType: public usg_cnt_t<DefaultThreadedModel> {
00036     public:
00037         SQLType(bool nul = false) 
00038         : _nul(nul)
00039         {
00040         }
00041         virtual ~SQLType() 
00042         {
00043         }
00044     
00045         virtual bool needsquote() const = 0;    
00046         virtual void outputoperator(std::ostream&) const = 0;
00047         void setnull(bool nul = true) {
00048             _nul = nul;
00049         };
00050         bool isnull() const throw() {
00051             return _nul;
00052         }
00053 
00054     private:
00055         bool _nul;
00056 };
00057 
00058 template<typename T>
00059 class SQLTypeImpl: public SQLType
00060 {
00061     public:
00062         SQLTypeImpl<T>(const T& val, const bool nul = true);
00063         virtual ~SQLTypeImpl<T>();
00064 
00065         virtual bool needsquote() const;
00066         virtual void outputoperator(std::ostream&) const;
00067         
00068     private:
00069         T _val;
00070 };
00071 
00072 class SQLRefType: public usg_cnt_t<DefaultThreadedModel> {
00073     public:
00074         virtual ~SQLRefType() {
00075         }
00076 
00077         virtual void assign(const char*, const int len) = 0;
00078     protected:
00079         const void* _valptr;
00080 };
00081 
00082 template<typename T>
00083 class SQLRefTypeImpl: public SQLRefType 
00084 {
00085     public:
00086         SQLRefTypeImpl<T>(T& val, bool& isnull);
00087         virtual ~SQLRefTypeImpl<T>();
00088         virtual void assign(const char*, const int len);
00089     private:
00090         T& val;
00091         bool& isnull;
00092 };
00093 
00094 inline std::ostream& operator<<(std::ostream& os, const SQLType& val)
00095 {
00096     val.outputoperator(os);
00097     return os;
00098 }
00099 
00100 } // namespace mysql
00101 } // namespace fatalmind
00102 #endif

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