• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_conversion.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 
00003 /* AbiSource Program Utilities
00004  * Copyright (C) 2010 AbiSource, Inc.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301 USA.
00020  */
00021 
00022 #ifndef UT_CONVERSION_H
00023 #define UT_CONVERSION_H
00024 
00025 #include "pp_AttrProp.h"
00026 class PP_Revision;
00027 
00028 #include <string>
00029 #include <sstream>
00030 
00031 template < typename ClassName >
00032 static ClassName toType( const char* s )
00033 {
00034     ClassName ret = 0;
00035     std::stringstream ss;
00036     ss << s;
00037     ss >> ret;
00038     return ret;
00039 }
00040 template < typename ClassName >
00041 static ClassName toType( std::string s )
00042 {
00043     ClassName ret = 0;
00044     std::stringstream ss;
00045     ss << s;
00046     ss >> ret;
00047     return ret;
00048 }
00049 
00050 template < typename T >
00051 static std::string tostr( T v )
00052 {
00053     std::stringstream ss;
00054     ss << v;
00055     return ss.str();
00056 }
00057 
00058 
00059 template < typename T >
00060 T UT_getAttributeTyped( const PP_AttrProp *pAP,
00061                         const gchar* name,
00062                         T def )
00063 {
00064     const gchar * pAttrValue = NULL;
00065     if( pAP->getAttribute( name, pAttrValue ))
00066     {
00067         return toType<T>( pAttrValue );
00068     }
00069     return def;
00070 }
00071 template < typename T >
00072 T UT_getAttributeTyped( const PP_Revision* pAP,
00073                         const gchar* name,
00074                         T def )
00075 {
00076     return UT_getAttributeTyped( (const PP_AttrProp*)pAP, name, def );
00077 }
00078 
00079 
00080 
00081 
00082 #endif // reinclude protection

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1