Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // Boost string_algo library find_format_store.hpp header file ---------------------------// |
| 2 | |
| 3 | // Copyright Pavol Droba 2002-2003. |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | // See http://www.boost.org/ for updates, documentation, and revision history. |
| 10 | |
| 11 | #ifndef BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP |
| 12 | #define BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP |
| 13 | |
| 14 | #include <ndnboost/algorithm/string/config.hpp> |
| 15 | #include <ndnboost/range/iterator_range.hpp> |
| 16 | |
| 17 | namespace ndnboost { |
| 18 | namespace algorithm { |
| 19 | namespace detail { |
| 20 | |
| 21 | // temporary format and find result storage --------------------------------// |
| 22 | |
| 23 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) |
| 24 | #pragma warning(push) |
| 25 | #pragma warning(disable:4512) //assignment operator could not be generated |
| 26 | #endif |
| 27 | template< |
| 28 | typename ForwardIteratorT, |
| 29 | typename FormatterT, |
| 30 | typename FormatResultT > |
| 31 | class find_format_store : |
| 32 | public iterator_range<ForwardIteratorT> |
| 33 | { |
| 34 | public: |
| 35 | // typedefs |
| 36 | typedef iterator_range<ForwardIteratorT> base_type; |
| 37 | typedef FormatterT formatter_type; |
| 38 | typedef FormatResultT format_result_type; |
| 39 | |
| 40 | public: |
| 41 | // Construction |
| 42 | find_format_store( |
| 43 | const base_type& FindResult, |
| 44 | const format_result_type& FormatResult, |
| 45 | const formatter_type& Formatter ) : |
| 46 | base_type(FindResult), |
| 47 | m_FormatResult(FormatResult), |
| 48 | m_Formatter(Formatter) {} |
| 49 | |
| 50 | // Assignment |
| 51 | template< typename FindResultT > |
| 52 | find_format_store& operator=( FindResultT FindResult ) |
| 53 | { |
| 54 | iterator_range<ForwardIteratorT>::operator=(FindResult); |
| 55 | if( !this->empty() ) { |
| 56 | m_FormatResult=m_Formatter(FindResult); |
| 57 | } |
| 58 | |
| 59 | return *this; |
| 60 | } |
| 61 | |
| 62 | // Retrieve format result |
| 63 | const format_result_type& format_result() |
| 64 | { |
| 65 | return m_FormatResult; |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | format_result_type m_FormatResult; |
| 70 | const formatter_type& m_Formatter; |
| 71 | }; |
| 72 | |
| 73 | template<typename InputT, typename FindResultT> |
| 74 | bool check_find_result(InputT&, FindResultT& FindResult) |
| 75 | { |
| 76 | typedef BOOST_STRING_TYPENAME |
| 77 | range_const_iterator<InputT>::type input_iterator_type; |
| 78 | iterator_range<input_iterator_type> ResultRange(FindResult); |
| 79 | return !ResultRange.empty(); |
| 80 | } |
| 81 | |
| 82 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) |
| 83 | #pragma warning(pop) |
| 84 | #endif |
| 85 | } // namespace detail |
| 86 | } // namespace algorithm |
| 87 | } // namespace ndnboost |
| 88 | |
| 89 | #endif // BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP |