// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \file \brief String non-inline template implementation */ //#include "String.ih" // Custom includes #include #include #include #include #define prefix_ //-///////////////////////////////////////////////////////////////////////////////////////////////// template prefix_ std::string senf::stringJoin(ForwardReadableRange const & range, std::string sep) { typename boost::range_const_iterator::type i (boost::begin(range)); typename boost::range_const_iterator::type const i_end (boost::end(range)); std::stringstream ss; if (i != i_end) { for (;;) { ss << *i; if ( ++i != i_end ) ss << sep; else break; } } return ss.str(); } // Copied from boost/lexical_cast.hpp namespace senf { namespace detail { template class lexical_stream { private: typedef char char_type; public: lexical_stream() { stream.unsetf(std::ios::skipws); if (std::numeric_limits::is_specialized) stream.precision(std::numeric_limits::digits10 + 1); } template bool operator<<(const Source &input) { if (std::numeric_limits::is_specialized) stream.precision(std::numeric_limits::digits10 + 1); return !(stream << input).fail(); } template bool operator>>(InputStreamable &output) { return !boost::is_pointer::value && stream >> output && stream.get() == std::char_traits::eof(); } bool operator>>(std::string &output) { output = stream.str(); return true; } bool operator>>(std::wstring &output) { output = stream.str(); return true; } private: std::basic_stringstream stream; }; template class lexical_caster { public: lexical_caster() : interpreter_ (new senf::detail::lexical_stream()) {} template Target operator()(Source const & arg) const { Target result; if (!((*interpreter_) << arg && (*interpreter_) >> result)) boost::throw_exception(boost::bad_lexical_cast(typeid(Source), typeid(Target))); return result; } template lexical_caster const & operator[](Mod mod) const { (*interpreter_) << mod; return *this; } private: boost::shared_ptr< senf::detail::lexical_stream > interpreter_; }; }} template prefix_ Target senf::lexical_cast(Source const & arg) { senf::detail::lexical_stream interpreter; Target result; if (!(interpreter << arg && interpreter >> result)) boost::throw_exception(boost::bad_lexical_cast(typeid(Source), typeid(Target))); return result; } template prefix_ senf::detail::lexical_caster senf::lexical_cast() { return detail::lexical_caster(); } //-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: