4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief String non-inline template implementation */
26 //#include "String.ih"
29 #include <boost/range.hpp>
31 #include <boost/lexical_cast.hpp>
32 #include <boost/shared_ptr.hpp>
35 ///////////////////////////////ct.p////////////////////////////////////////
37 template <class ForwardReadableRange>
38 prefix_ std::string senf::stringJoin(ForwardReadableRange const & range, std::string sep)
40 typename boost::range_const_iterator<ForwardReadableRange>::type i (boost::begin(range));
41 typename boost::range_const_iterator<ForwardReadableRange>::type const i_end (boost::end(range));
47 if ( ++i != i_end ) ss << sep;
55 // Copied from boost/lexical_cast.hpp
58 template<typename Target>
62 typedef char char_type;
67 stream.unsetf(std::ios::skipws);
68 if (std::numeric_limits<Target>::is_specialized)
69 stream.precision(std::numeric_limits<Target>::digits10 + 1);
71 template <class Source>
72 bool operator<<(const Source &input)
74 if (std::numeric_limits<Source>::is_specialized)
75 stream.precision(std::numeric_limits<Source>::digits10 + 1);
76 return !(stream << input).fail();
78 template<typename InputStreamable>
79 bool operator>>(InputStreamable &output)
81 return !boost::is_pointer<InputStreamable>::value &&
83 stream.get() == std::char_traits<char_type>::eof();
85 bool operator>>(std::string &output)
87 output = stream.str();
90 bool operator>>(std::wstring &output)
92 output = stream.str();
96 std::basic_stringstream<char_type> stream;
99 template <class Target>
103 lexical_caster() : interpreter_ (new senf::detail::lexical_stream<Target>()) {}
104 template <class Source>
105 Target operator()(Source const & arg) const
108 if (!((*interpreter_) << arg && (*interpreter_) >> result))
109 boost::throw_exception(boost::bad_lexical_cast(typeid(Source), typeid(Target)));
114 lexical_caster const & operator[](Mod mod) const
116 (*interpreter_) << mod;
121 boost::shared_ptr< senf::detail::lexical_stream<Target> > interpreter_;
125 template <class Target, class Source>
126 prefix_ Target senf::lexical_cast(Source const & arg)
128 senf::detail::lexical_stream<Target> interpreter;
131 if (!(interpreter << arg && interpreter >> result))
132 boost::throw_exception(boost::bad_lexical_cast(typeid(Source), typeid(Target)));
136 template <class Target>
137 prefix_ senf::detail::lexical_caster<Target> senf::lexical_cast()
139 return detail::lexical_caster<Target>();
142 ///////////////////////////////ct.e////////////////////////////////////////
149 // comment-column: 40
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"