Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / test / utils / iterator / istream_line_iterator.hpp
1 //  (C) Copyright Gennadiy Rozental 2004-2008.
2 //  Distributed under the Boost Software License, Version 1.0.
3 //  (See accompanying file LICENSE_1_0.txt or copy at 
4 //  http://www.boost.org/LICENSE_1_0.txt)
5
6 //  See http://www.boost.org/libs/test for the library home page.
7 //
8 //  File        : $RCSfile$
9 //
10 //  Version     : $Revision$
11 //
12 //  Description : 
13 // ***************************************************************************
14
15 #ifndef BOOST_ISTREAM_LINE_ITERATOR_HPP_071894GER
16 #define BOOST_ISTREAM_LINE_ITERATOR_HPP_071894GER
17
18 // Boost
19 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
20 #include <boost/test/utils/iterator/input_iterator_facade.hpp>
21
22 // STL
23 #include <iosfwd>
24
25 #include <boost/test/detail/suppress_warnings.hpp>
26
27 //____________________________________________________________________________//
28
29 namespace boost {
30
31 namespace unit_test {
32
33 // ************************************************************************** //
34 // **************         basic_istream_line_iterator          ************** //
35 // ************************************************************************** //
36
37 // !! Should we support policy based delimitation
38
39 template<typename CharT>
40 class basic_istream_line_iterator
41 : public input_iterator_facade<basic_istream_line_iterator<CharT>,
42                                std::basic_string<CharT>,
43                                basic_cstring<CharT const> > {
44     typedef input_iterator_facade<basic_istream_line_iterator<CharT>,
45                                   std::basic_string<CharT>,
46                                   basic_cstring<CharT const> > base;
47 #ifdef BOOST_CLASSIC_IOSTREAMS
48     typedef std::istream              istream_type;
49 #else
50     typedef std::basic_istream<CharT> istream_type;
51 #endif
52 public:
53     // Constructors
54     basic_istream_line_iterator() {}
55     basic_istream_line_iterator( istream_type& input, CharT delimeter )
56     : m_input_stream( &input ), m_delimeter( delimeter )
57     {
58         this->init();
59     }
60     explicit basic_istream_line_iterator( istream_type& input )
61     : m_input_stream( &input ) 
62     , m_delimeter( input.widen( '\n' ) )
63     {
64         this->init();
65     }
66
67 private:
68     friend class input_iterator_core_access;
69
70     // increment implementation
71     bool                     get()
72     {
73         return !!std::getline( *m_input_stream, this->m_value, m_delimeter );
74     }
75
76     // Data members
77     istream_type* m_input_stream;
78     CharT         m_delimeter;
79 };
80
81 typedef basic_istream_line_iterator<char>       istream_line_iterator;
82 typedef basic_istream_line_iterator<wchar_t>    wistream_line_iterator;
83
84 } // namespace unit_test
85
86 } // namespace boost
87
88 //____________________________________________________________________________//
89
90 #include <boost/test/detail/enable_warnings.hpp>
91
92 #endif // BOOST_ISTREAM_LINE_ITERATOR_HPP_071894GER
93