]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (C) Copyright Gennadiy Rozental 2001. |
2 | // Distributed under the Boost Software License, Version 1.0. | |
3 | // (See accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | // See http://www.boost.org/libs/test for the library home page. | |
7 | // | |
8 | // File : $RCSfile$ | |
9 | // | |
10 | // Version : $Revision$ | |
11 | // | |
12 | // Description : trivial utility to cast to/from strings | |
13 | // *************************************************************************** | |
14 | ||
15 | #ifndef BOOST_TEST_UTILS_STRING_CAST_HPP | |
16 | #define BOOST_TEST_UTILS_STRING_CAST_HPP | |
17 | ||
18 | // Boost.Test | |
19 | #include <boost/test/utils/basic_cstring/basic_cstring.hpp> | |
20 | ||
21 | // STL | |
22 | #include <sstream> | |
23 | ||
24 | #include <boost/test/detail/suppress_warnings.hpp> | |
25 | ||
26 | //____________________________________________________________________________// | |
27 | ||
28 | namespace boost { | |
29 | namespace unit_test { | |
30 | namespace utils { | |
31 | ||
32 | // ************************************************************************** // | |
33 | // ************** string_cast ************** // | |
34 | // ************************************************************************** // | |
35 | ||
36 | template<typename T> | |
37 | inline std::string | |
38 | string_cast( T const& t ) | |
39 | { | |
40 | std::ostringstream buff; | |
41 | buff << t; | |
42 | return buff.str(); | |
43 | } | |
44 | ||
45 | //____________________________________________________________________________// | |
46 | ||
47 | // ************************************************************************** // | |
48 | // ************** string_as ************** // | |
49 | // ************************************************************************** // | |
50 | ||
51 | template<typename T> | |
52 | inline bool | |
53 | string_as( const_string str, T& res ) | |
54 | { | |
55 | std::istringstream buff( std::string( str.begin(), str.end() ) ); | |
56 | buff >> res; | |
57 | ||
58 | return !buff.fail() && buff.eof(); | |
59 | } | |
60 | ||
61 | //____________________________________________________________________________// | |
62 | ||
63 | } // namespace utils | |
64 | } // namespace unit_test | |
65 | } // namespace boost | |
66 | ||
67 | #include <boost/test/detail/enable_warnings.hpp> | |
68 | ||
69 | #endif // BOOST_TEST_UTILS_STRING_CAST_HPP |