WORM 0.2
A C++ DAL/ORM code generation framework

src/sql/wsqldatum.h

Go to the documentation of this file.
00001 /*
00002     WORM - a DAL/ORM code generation framework
00003     Copyright (C) 2011  Erik Winn <erikwinnmail@yahoo.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 3 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, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 #ifndef WSQLDATUM_H
00020 #define WSQLDATUM_H
00021 
00022 #include <string>
00023 #include <boost/lexical_cast.hpp>
00024 
00025 namespace WSql
00026 {
00027 
00028 class WSqlDatum
00029 {
00030 
00031     public:
00032         WSqlDatum();
00033         WSqlDatum( const WSqlDatum& other );
00034         virtual ~WSqlDatum();
00035         virtual WSqlDatum& operator=( const WSqlDatum& other );
00036         virtual bool operator==( const WSqlDatum& other ) const;
00037         inline bool operator!=( const WSqlDatum &other ) const {
00038             return !operator==( other );
00039         }
00040         template <typename T> void setData( const T t ) {
00041             try {
00042                 _data = boost::lexical_cast<std::string>( t );
00043             }
00044             catch ( boost::bad_lexical_cast &e ) {
00046             }
00047         };
00048 
00049         template <typename T> T data()const {
00050             try {
00051                 return boost::lexical_cast<T>( _data );
00052             }
00053             catch ( boost::bad_lexical_cast &e ) {
00055                 //well, gotta do _something ..
00056                 return T();
00057             }
00058         };
00059 
00060         short toShort()const {return data<short>(); }
00061         int toInt()const {return data<int>(); }
00062         long toLong()const {return data<long>(); }
00063         float toFloat()const {return data<float>(); }
00064         double toDouble()const {return data<double>(); }
00065 
00066         unsigned short toUShort()const {return data<unsigned short>(); }
00067         unsigned int toUInt()const {return data<unsigned int>(); }
00068         unsigned long toULong()const {return data<unsigned long>(); }
00069 
00070         std::string toString()const {return data<std::string>(); }
00071 
00072         void clear();
00073     private:
00074         std::string _data;
00075 
00076 };
00077 
00078 }//namespace WSql
00079 #endif // WSQLDATUM_H
00080 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines