diff options
author | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-05 20:32:34 +0000 |
---|---|---|
committer | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-05 20:32:34 +0000 |
commit | 2a9f97555f0f9f770e64b8de1f2143444bdbd4ef (patch) | |
tree | 53f15cb99b1ee0f2e22e1897760430f950d11a97 /tools.h | |
parent | 07aebf937a6a196114e7136f77eb5adefa2eeeb1 (diff) | |
download | vdr-plugin-live-2a9f97555f0f9f770e64b8de1f2143444bdbd4ef.tar.gz vdr-plugin-live-2a9f97555f0f9f770e64b8de1f2143444bdbd4ef.tar.bz2 |
- added lexical_cast tool
Diffstat (limited to 'tools.h')
-rw-r--r-- | tools.h | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -2,6 +2,8 @@ #define VDR_LIVE_TOOLS_H #include <ctime> +#include <sstream> +#include <stdexcept> #include <string> #include <vector> #include <vdr/thread.h> @@ -12,6 +14,23 @@ std::string FormatDateTime( char const* format, time_t time ); std::string StringReplace( std::string const& text, std::string const& substring, std::string const& replacement ); std::vector< std::string > StringSplit( std::string const& text, char delimiter ); +struct bad_lexical_cast: std::runtime_error +{ + bad_lexical_cast(): std::runtime_error( "bad lexical cast" ) {} +}; + +template< typename To, typename From > +To lexical_cast( From const& from ) +{ + std::stringstream parser; + parser << from; + To result; + parser >> result; + if ( !parser ) + throw bad_lexical_cast(); + return result; +} + class ReadLock { public: |