summaryrefslogtreecommitdiff
path: root/tools.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools.h')
-rw-r--r--tools.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools.h b/tools.h
index 3b195dd..0c98fed 100644
--- a/tools.h
+++ b/tools.h
@@ -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: