find_format_store.hpp 3.1 KB

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