MySQLaux 0.6 is free software from Langensoft written by Thomas Langen.

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

MySQLaux/TypedField.h

Go to the documentation of this file.
00001 /* 
00002  * MySQLaux - auxiliary classes for communication with MySQL databases
00003  * Copyright © 2001  Thomas Langen (mailto:langen@langensoft.com)
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  * 
00019  * $Source: TypedField.h $
00020  * $Id: TypedField.h 1.5 Fri, 06 Apr 2001 10:30:48 +0200 langen $
00021  * $ProjectHeader: MySQLaux 0.6 Fri, 06 Apr 2001 10:30:48 +0200 langen $
00022  */
00023 
00024 #ifndef __MySQLaux_TypedField_h__
00025 #define __MySQLaux_TypedField_h__
00026 
00027 #include "Exception.h"
00028 #include "Field.h"
00029 #include <sstream>
00030 
00031 namespace MySQLaux
00032 {
00038   template<class T>
00039   class TypedField
00040     : public Field
00041   {
00042   private:
00043     T _value;
00044   public:
00045 #if 0
00046 
00052     TypedField (std::string const & name,
00053                 T const & value)
00054         : Field (name),
00055           _value (value)
00056     {
00057     }
00058 #endif
00059     
00065     TypedField (std::string const & name,
00066                 std::string const & data)
00067         : Field (name)
00068     {
00069       std::istringstream is (data);
00070       is >> _value;
00071     }
00072     
00077     TypedField (string const & name)
00078         : Field (name, true)
00079     {
00080     }
00081     
00085     T const & value() const
00086       throw (NullFieldIndicator)
00087     {
00088       if (_is_null)
00089         throw NullFieldIndicator ();
00090       return _value;
00091     }
00092     
00096     std::string to_string () const
00097       throw (NullFieldIndicator)
00098     {
00099       if (_is_null)
00100         throw NullFieldIndicator ();
00101       
00102       std::ostringstream os;
00103       os << _value;
00104       return os.str();
00105     }
00106 
00110     std::size_t size () const { return sizeof(_value); }
00111   };
00112 }
00113 
00114 #endif // __MySQLaux_TypedField_h__ 
00115 
00116 /*
00117  * Local Variables:
00118  * mode: C++
00119  * fill-column: 80
00120  * c-comment-continuation-stars: " * "
00121  * End:
00122  */
00123 

Generated at Fri Apr 6 11:20:03 2001 for MySQLaux by doxygen1.2.5 written by Dimitri van Heesch, © 1997-2001