d41b09d8f8a5e15ec2f16074fe3fc0638c9e7350
[platform/upstream/boost.git] / boost / test / utils / iterator / ifstream_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_IFSTREAM_LINE_ITERATOR_HPP_071894GER
16 #define BOOST_IFSTREAM_LINE_ITERATOR_HPP_071894GER
17
18 // Boost
19 #include <boost/test/utils/iterator/istream_line_iterator.hpp>
20
21 // STL
22 #include <fstream>
23
24 #include <boost/test/detail/suppress_warnings.hpp>
25
26 //____________________________________________________________________________//
27
28 namespace boost {
29
30 namespace unit_test {
31
32 namespace ut_detail {
33
34 // ************************************************************************** //
35 // **************                ifstream_holder               ************** //
36 // ************************************************************************** //
37
38 template<typename CharT>
39 class ifstream_holder {
40 public:
41     // Constructor
42     explicit    ifstream_holder( basic_cstring<CharT const> file_name )
43     {
44         if( file_name.is_empty() )
45             return;
46
47         m_stream.open( file_name.begin(), std::ios::in );
48     }
49
50     bool is_valid()
51     {
52         return m_stream.is_open();
53     }
54
55 protected:
56 #ifdef BOOST_CLASSIC_IOSTREAMS
57     typedef std::ifstream                                       stream_t;
58 #else
59     typedef std::basic_ifstream<CharT,std::char_traits<CharT> > stream_t;
60 #endif
61
62     // Data members
63     stream_t    m_stream;
64 };
65
66 } // namespace ut_detail
67
68 // ************************************************************************** //
69 // **************         basic_ifstream_line_iterator         ************** //
70 // ************************************************************************** //
71
72 #ifdef BOOST_MSVC
73 # pragma warning(push)
74 # pragma warning(disable: 4355) // 'this' : used in base member initializer list
75 #endif
76
77 template<typename CharT>
78 class basic_ifstream_line_iterator : ut_detail::ifstream_holder<CharT>, public basic_istream_line_iterator<CharT>
79 {
80 public:
81     basic_ifstream_line_iterator( basic_cstring<CharT const> file_name, CharT delimeter )
82     : ut_detail::ifstream_holder<CharT>( file_name ), basic_istream_line_iterator<CharT>( this->m_stream, delimeter ) {}
83
84     explicit basic_ifstream_line_iterator( basic_cstring<CharT const> file_name = basic_cstring<CharT const>() )
85     : ut_detail::ifstream_holder<CharT>( file_name ), basic_istream_line_iterator<CharT>( this->m_stream ) {}
86 };
87
88 #ifdef BOOST_MSVC
89 # pragma warning(default: 4355)
90 #endif
91
92 typedef basic_ifstream_line_iterator<char>      ifstream_line_iterator;
93 typedef basic_ifstream_line_iterator<wchar_t>   wifstream_line_iterator;
94
95 } // namespace unit_test
96
97 } // namespace boost
98
99 //____________________________________________________________________________//
100
101 #include <boost/test/detail/enable_warnings.hpp>
102
103 #endif // BOOST_IFSTREAM_LINE_ITERATOR_HPP_071894GER
104