diff --git a/src/signal/signal-cast-helper.cpp b/src/signal/signal-cast-helper.cpp index 73c0e5735fd42f14908a8d6758716965b6f0cdbc..360f4423962c8bce020d43ead047e2789d5d43b9 100644 --- a/src/signal/signal-cast-helper.cpp +++ b/src/signal/signal-cast-helper.cpp @@ -52,6 +52,15 @@ inline boost::any DefaultCastRegisterer<double>::cast(std::istringstream &iss) { } } +// for std::string, do not check failure. If input stream contains an +// empty string, iss.fail() returns true and an exception is thrown +template <> +inline boost::any +DefaultCastRegisterer<std::string>::cast(std::istringstream &iss) { + std::string inst(iss.str()); + return inst; +} + // for std::string, do not add std::endl at the end of the stream. template <> inline void DefaultCastRegisterer<std::string>::disp(const boost::any &object, diff --git a/tests/signal-ptr.cpp b/tests/signal-ptr.cpp index 2646bca5e9c560dd0fdc27a6bb0686ec0f045c05..1bd3578eb084f87494b45b1f3127b83759c175fd 100644 --- a/tests/signal-ptr.cpp +++ b/tests/signal-ptr.cpp @@ -297,3 +297,19 @@ BOOST_AUTO_TEST_CASE(plug_signal_string) { std::cout << "res=" << res << std::endl; BOOST_CHECK(res == str); } + +BOOST_AUTO_TEST_CASE(set_signal_string) { + Signal<std::string, int> s("signal"); + std::string str(""); + std::ostringstream os; + os << str; + std::istringstream value(os.str()); + try { + s.set(value); + } + catch(const std::exception& exc) + { + std::cout << exc.what() << std::endl; + BOOST_CHECK(!"Tentative to set signal to empty string"); + } +}