Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

# convert.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007 /***********************************************************************
    00008  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
    00009  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
    00010  Others may also hold copyrights on code in this file.  See the CREDITS
    00011  file in the top directory of the distribution for details.
    00012
    00013  This file is part of MySQL++.
    00014
    00015  MySQL++ is free software; you can redistribute it and/or modify it
    00016  under the terms of the GNU Lesser General Public License as published
    00017  by the Free Software Foundation; either version 2.1 of the License, or
    00018  (at your option) any later version.
    00019
    00020  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00021  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00022  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00023  License for more details.
    00024
    00025  You should have received a copy of the GNU Lesser General Public
    00026  License along with MySQL++; if not, write to the Free Software
    00027  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00028  USA
    00029 ***********************************************************************/
    00030
    00031 #ifndef MYSQLPP_CONVERT_H
    00032 #define MYSQLPP_CONVERT_H
    00033
    00034 #include "common.h"
    00035
    00036 #include <stdlib.h>
    00037
    00038 namespace mysqlpp {
    00039
    00040 #if !defined(DOXYGEN_IGNORE)
    00041 // Doxygen will not generate documentation for this section.
    00042
    00043 template <class Type> class mysql_convert;
    00044
    00045 #define mysql__convert(TYPE, FUNC) \
    00046   template <> \
    00047   class mysql_convert<TYPE> {\
    00048   public:\
    00049     mysql_convert(const char* str, const char *& end) { \
    00050       num_ = FUNC(str, const_cast<char **>(&end));}\
    00051     operator TYPE () {return num_;}\
    00052   private:\
    00053     TYPE num_;\
    00054   };\
    00055
    00056 #if defined(_MSC_VER)
    00057 #       pragma warning(disable: 4244)
    00058 #endif
    00059
    00060         mysql__convert(float, strtod)
    00061         mysql__convert(double, strtod)
    00062
    00063 #if defined(_MSC_VER)
    00064 #       pragma warning(default: 4244)
    00065 #endif
    00066
    00067 #undef mysql__convert
    00068 #define mysql__convert(TYPE, FUNC) \
    00069   template <> \
    00070   class mysql_convert<TYPE> {\
    00071   public:\
    00072     mysql_convert(const char* str, const char *& end) { \
    00073       num_ = FUNC(str, const_cast<char **>(&end),10);}\
    00074     operator TYPE () {return num_;}\
    00075   private:\
    00076     TYPE num_;\
    00077   };\
    00078
    00079 #if defined(_MSC_VER)
    00080 #       pragma warning(disable: 4244)
    00081 #endif
    00082
    00083         mysql__convert(char, strtol)
    00084         mysql__convert(signed char, strtol)
    00085         mysql__convert(int, strtol)
    00086         mysql__convert(short int, strtol)
    00087         mysql__convert(long int, strtol)
    00088
    00089         mysql__convert(unsigned char, strtoul)
    00090         mysql__convert(unsigned int, strtoul)
    00091         mysql__convert(unsigned short int, strtoul)
    00092         mysql__convert(unsigned long int, strtoul)
    00093
    00094 #if defined(_MSC_VER)
    00095 #       pragma warning(default: 4244)
    00096 #endif
    00097
    00098 #if !defined(NO_LONG_LONGS)
    00099 #if defined(_MSC_VER)
    00100 // Handle 64-bit ints the VC++ way
    00101 mysql__convert(longlong, _strtoi64)
    00102 mysql__convert(ulonglong, _strtoui64)
    00103 #else
    00104 // No better idea, so assume the C99 way.  If your compiler doesn't
    00105 // support this, please provide a patch to extend this ifdef, or define
    00106 // NO_LONG_LONGS.
    00107 mysql__convert(longlong, strtoll)
    00108 mysql__convert(ulonglong, strtoull)
    00109 #endif
    00110 #endif // !defined(NO_LONG_LONGS)
    00111
    00112 #endif // !defined(DOXYGEN_IGNORE)
    00113
    00114 } // end namespace mysqlpp
    00115
    00116 #endif
    00117