User Manual, Developers Guide and API Documentation

Converter.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef WNS_PYCONFIG_CONVERTER_HPP
00029 #define WNS_PYCONFIG_CONVERTER_HPP
00030 
00031 #include <WNS/pyconfig/Object.hpp>
00032 
00033 #include <string>
00034 
00035 namespace wns { namespace pyconfig {
00036     template <typename T>
00037     class Converter
00038     {
00039     public:
00040         typedef T TargetType;
00041 
00042         // boolean converter
00043         bool
00044         convert(bool& value, Object o) const
00045         {
00046             switch(o.isTrue())
00047             {
00048                     case 1:
00049                         value = true;
00050                         break;
00051                     case 0:
00052                         value = false;
00053                         break;
00054             }
00055             return false;
00056         } // convert bool
00057 
00058         // std::string converter
00059         bool
00060         convert(std::string& value, Object o) const
00061         {
00062             if(!o.isConvertibleToString())
00063             {
00064                 return false;
00065             }
00066 
00067             value = o.toString();
00068             return true;
00069         } // convert string
00070 
00071 
00072         // default converter
00073         template <typename U>
00074         bool convert(U &value, Object o) const
00075         {
00076             if(!o.isConvertibleToString())
00077             {
00078                 return false;
00079             }
00080 
00081             std::istringstream os(o.toString());
00082             os >> value;
00083 
00084             return true;
00085         } // convert
00086     };
00087 
00088 }}
00089 
00090 #endif // NOT defined WNS_PYCONFIG_CONVERTER_HPP
00091 
00092 

Generated on Tue May 22 03:31:47 2012 for openWNS by  doxygen 1.5.5