/** * $Id: utils.h 2 2009-10-31 02:48:23Z l0728348 $ * * Copyright 2009 * * @author Manuel Mausz (0728348) * @brief implements some common utility functions, methods and templates * available in namespace Utils. */ #ifndef UTILS_H #define UTILS_H #include #include namespace Utils { /** * @brief exception thrown by lexical_cast */ class bad_lexical_cast : public std::runtime_error { public: /** * @brief Default exception ctor * @param what message to pass along */ bad_lexical_cast(const std::string& what) : std::runtime_error(what) {} }; /** * @brief simple implementation of boost::lexical_cast * can be used to convert string to number * mainly uses operator<< of stringstream * @param source source value * @return target target value **/ template Target lexical_cast(const Source& source) { Target target; std::stringstream interpreter; if(!(interpreter << source && interpreter >> target && interpreter.get() == std::char_traits::eof())) throw bad_lexical_cast("bad lexical cast"); return target; }; }; #endif /* vim: set et sw=2 ts=2: */