1/*
2 * Copyright (c) 2012-2014, TU Delft
3 * Copyright (c) 2012-2014, TU Eindhoven
4 * Copyright (c) 2012-2014, TU Kaiserslautern
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
--- 32 unchanged lines hidden (view full) ---
41#include <string>
42#include <sstream>
43#include <stdexcept>
44
45
46template<typename T>
47T fromString(const std::string& s,
48 std::ios_base& (*f)(std::ios_base &) = std::dec)
49throw(std::runtime_error)
50{
51 std::istringstream is(s);
52 T t;
53
54 if (!(is >> f >> t)) {
55 throw std::runtime_error("Cannot convert string");
56 }
57
58 return t;
59}
60
61#endif /* UTILS_H */
2 * Copyright (c) 2012-2014, TU Delft
3 * Copyright (c) 2012-2014, TU Eindhoven
4 * Copyright (c) 2012-2014, TU Kaiserslautern
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
--- 32 unchanged lines hidden (view full) ---
41#include <string>
42#include <sstream>
43#include <stdexcept>
44
45
46template<typename T>
47T fromString(const std::string& s,
48 std::ios_base& (*f)(std::ios_base &) = std::dec)
49throw(std::runtime_error)
50{
51 std::istringstream is(s);
52 T t;
53
54 if (!(is >> f >> t)) {
55 throw std::runtime_error("Cannot convert string");
56 }
57
58 return t;
59}
60
61#endif /* UTILS_H */