Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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