X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=boost%2Fboost%2Ftoken_functions.hpp;h=867525fb1a0e67cc777753b2c3630104ec7ac729;hb=7677e9487c1669735a2aa9b2356199c2f608fe15;hp=98df81b8b103908429c2881ee6dfdce03d913460;hpb=e1644a68eb123c267a7ef2e651c66b788c38f03a;p=lyx.git diff --git a/boost/boost/token_functions.hpp b/boost/boost/token_functions.hpp index 98df81b8b1..867525fb1a 100644 --- a/boost/boost/token_functions.hpp +++ b/boost/boost/token_functions.hpp @@ -2,16 +2,22 @@ // Copyright John R. Bandela 2001. -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all -// copies. This software is provided "as is" without express or -// implied warranty, and with no claim as to its suitability for any -// purpose. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) -// See http://www.boost.org/libs/tokenizer for documentation. +// See http://www.boost.org/libs/tokenizer/ for documentation. // Revision History: - +// 01 Oct 2004 Joaquín M López Muñoz +// Workaround for a problem with string::assign in msvc-stlport +// 06 Apr 2004 John Bandela +// Fixed a bug involving using char_delimiter with a true input iterator +// 28 Nov 2003 Robert Zeh and John Bandela +// Converted into "fast" functions that avoid using += when +// the supplied iterator isn't an input_iterator; based on +// some work done at Archelon and a version that was checked into +// the boost CVS for a short period of time. // 20 Feb 2002 John Maddock // Removed using namespace std declarations and added // workaround for BOOST_NO_STDC_NAMESPACE (the library @@ -22,14 +28,18 @@ // Removed tabs and a little cleanup. -#ifndef BOOST_TOKEN_FUNCTIONS_JRB051801_HPP_ -#define BOOST_TOKEN_FUNCTIONS_JRB051801_HPP_ +#ifndef BOOST_TOKEN_FUNCTIONS_JRB120303_HPP_ +#define BOOST_TOKEN_FUNCTIONS_JRB120303_HPP_ #include #include -#include #include #include +#include // for find_if +#include +#include +#include +#include // // the following must not be macros if we are to prefix them @@ -64,7 +74,7 @@ namespace boost{ // character (backslash \), can be assigned to other characters. struct escaped_list_error : public std::runtime_error{ - escaped_list_error(const std::string& what):std::runtime_error(what) { } + escaped_list_error(const std::string& what_arg):std::runtime_error(what_arg) { } }; @@ -180,6 +190,103 @@ namespace boost{ } }; + //=========================================================================== + // The classes here are used by offset_separator and char_separator to implement + // faster assigning of tokens using assign instead of += + + namespace tokenizer_detail { + + // The assign_or_plus_equal struct contains functions that implement + // assign, +=, and clearing based on the iterator type. The + // generic case does nothing for plus_equal and clearing, while + // passing through the call for assign. + // + // When an input iterator is being used, the situation is reversed. + // The assign method does nothing, plus_equal invokes operator +=, + // and the clearing method sets the supplied token to the default + // token constructor's result. + // + + template + struct assign_or_plus_equal { + template + static void assign(Iterator b, Iterator e, Token &t) { + +#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) &&\ + BOOST_WORKAROUND(__SGI_STL_PORT, < 0x500) &&\ + defined(_STLP_DEBUG) &&\ + (defined(_STLP_USE_DYNAMIC_LIB) || defined(_DLL)) + // Problem with string::assign for msvc-stlport in debug mode: the + // linker tries to import the templatized version of this memfun, + // which is obviously not exported. + // See http://www.stlport.com/dcforum/DCForumID6/1763.html for details. + + t = Token(); + while(b != e) t += *b++; +#else + t.assign(b, e); +#endif + + } + + template + static void plus_equal(Token &, const Value &) { + + } + + // If we are doing an assign, there is no need for the + // the clear. + // + template + static void clear(Token &) { + + } + }; + + template <> + struct assign_or_plus_equal { + template + static void assign(Iterator b, Iterator e, Token &t) { + + } + template + static void plus_equal(Token &t, const Value &v) { + t += v; + } + template + static void clear(Token &t) { + t = Token(); + } + }; + + + template + struct pointer_iterator_category{ + typedef std::random_access_iterator_tag type; + }; + + + template + struct class_iterator_category{ + typedef typename Iterator::iterator_category type; + }; + + + + // This portably gets the iterator_tag without partial template specialization + template + struct get_iterator_category{ + typedef typename mpl::if_, + pointer_iterator_category, + class_iterator_category + >::type cat; + + typedef typename cat::type iterator_category; + }; + + +} + //=========================================================================== // The offset_separator class, which is a model of TokenizerFunction. @@ -212,25 +319,36 @@ namespace boost{ template bool operator()(InputIterator& next, InputIterator end, Token& tok) { - assert(!offsets_.empty()); + typedef tokenizer_detail::assign_or_plus_equal< +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + typename +#endif + tokenizer_detail::get_iterator_category< + InputIterator>::iterator_category> assigner; + + + BOOST_ASSERT(!offsets_.empty()); - tok = Token(); + assigner::clear(tok); + InputIterator start(next); if (next == end) return false; - if (current_offset_ == offsets_.size()) + if (current_offset_ == offsets_.size()) { if (wrap_offsets_) current_offset_=0; else return false; - + } + int c = offsets_[current_offset_]; int i = 0; for (; i < c; ++i) { if (next == end)break; - tok+=*next++; + assigner::plus_equal(tok,*next++); } + assigner::assign(start,next,tok); if (!return_partial_last_) if (i < (c-1) ) @@ -297,42 +415,54 @@ namespace boost{ template bool operator()(InputIterator& next, InputIterator end, Token& tok) { - tok = Token(); + typedef tokenizer_detail::assign_or_plus_equal< +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + typename +#endif + tokenizer_detail::get_iterator_category< + InputIterator>::iterator_category> assigner; + + assigner::clear(tok); // skip past all dropped_delims if (m_empty_tokens == drop_empty_tokens) for (; next != end && is_dropped(*next); ++next) { } + InputIterator start(next); + if (m_empty_tokens == drop_empty_tokens) { if (next == end) return false; + // if we are on a kept_delims move past it and stop if (is_kept(*next)) { - tok += *next; + assigner::plus_equal(tok,*next); ++next; } else // append all the non delim characters for (; next != end && !is_dropped(*next) && !is_kept(*next); ++next) - tok += *next; + assigner::plus_equal(tok,*next); } else { // m_empty_tokens == keep_empty_tokens // Handle empty token at the end - if (next == end) + if (next == end) { if (m_output_done == false) { m_output_done = true; + assigner::assign(start,next,tok); return true; } else return false; + } if (is_kept(*next)) { if (m_output_done == false) m_output_done = true; else { - tok += *next; + assigner::plus_equal(tok,*next); ++next; m_output_done = false; } @@ -342,12 +472,13 @@ namespace boost{ } else { if (is_dropped(*next)) - ++next; + start=++next; for (; next != end && !is_dropped(*next) && !is_kept(*next); ++next) - tok += *next; + assigner::plus_equal(tok,*next); m_output_done = true; } } + assigner::assign(start,next,tok); return true; }