Skip to content

Commit 3aa6df4

Browse files
authored
Merge pull request #60 from florent-lamiraux/signal-empty-string
Fix Signal<std::string>
2 parents f0d43bc + f0ddf27 commit 3aa6df4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/signal/signal-cast-helper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ inline boost::any DefaultCastRegisterer<double>::cast(std::istringstream &iss) {
5252
}
5353
}
5454

55+
// for std::string, do not check failure. If input stream contains an
56+
// empty string, iss.fail() returns true and an exception is thrown
57+
template <>
58+
inline boost::any
59+
DefaultCastRegisterer<std::string>::cast(std::istringstream &iss) {
60+
std::string inst(iss.str());
61+
return inst;
62+
}
63+
5564
// for std::string, do not add std::endl at the end of the stream.
5665
template <>
5766
inline void DefaultCastRegisterer<std::string>::disp(const boost::any &object,

tests/signal-ptr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,19 @@ BOOST_AUTO_TEST_CASE(plug_signal_string) {
297297
std::cout << "res=" << res << std::endl;
298298
BOOST_CHECK(res == str);
299299
}
300+
301+
BOOST_AUTO_TEST_CASE(set_signal_string) {
302+
Signal<std::string, int> s("signal");
303+
std::string str("");
304+
std::ostringstream os;
305+
os << str;
306+
std::istringstream value(os.str());
307+
try {
308+
s.set(value);
309+
}
310+
catch(const std::exception& exc)
311+
{
312+
std::cout << exc.what() << std::endl;
313+
BOOST_CHECK(!"Tentative to set signal to empty string");
314+
}
315+
}

0 commit comments

Comments
 (0)