1 | // (C) Copyright Gennadiy Rozental 2005.
|
---|
2 | // Use, modification, and distribution are subject to the
|
---|
3 | // Boost Software License, Version 1.0. (See accompanying file
|
---|
4 | // LICENSE_1_0.txt or copy at 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: config_file_iterator.hpp,v $
|
---|
9 | //
|
---|
10 | // Version : $Revision: 1.2 $
|
---|
11 | //
|
---|
12 | // Description : flexible configuration file iterator definition
|
---|
13 | // ***************************************************************************
|
---|
14 |
|
---|
15 | #ifndef BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER
|
---|
16 | #define BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER
|
---|
17 |
|
---|
18 | // Boost.Runtime.Parameter
|
---|
19 | #include <boost/test/utils/runtime/config.hpp>
|
---|
20 |
|
---|
21 | #include <boost/test/utils/runtime/fwd.hpp>
|
---|
22 |
|
---|
23 | // Boost.Test
|
---|
24 | #include <boost/test/utils/iterator/input_iterator_facade.hpp>
|
---|
25 | #include <boost/test/utils/callback.hpp>
|
---|
26 | #include <boost/test/utils/named_params.hpp>
|
---|
27 |
|
---|
28 | // Boost
|
---|
29 | #include <boost/shared_ptr.hpp>
|
---|
30 |
|
---|
31 | namespace boost {
|
---|
32 |
|
---|
33 | namespace BOOST_RT_PARAM_NAMESPACE {
|
---|
34 |
|
---|
35 | namespace file {
|
---|
36 |
|
---|
37 | // Public typedef
|
---|
38 | typedef std::pair<dstring,long> location;
|
---|
39 |
|
---|
40 | // ************************************************************************** //
|
---|
41 | // ************** modifiers ************** //
|
---|
42 | // ************************************************************************** //
|
---|
43 |
|
---|
44 | namespace cfg_detail {
|
---|
45 | struct path_separators_t;
|
---|
46 | struct line_delimeter_t;
|
---|
47 | struct sl_comment_delimeter_t;
|
---|
48 | struct command_delimeter_t;
|
---|
49 | struct line_beak_t;
|
---|
50 | struct macro_ref_begin_t;
|
---|
51 | struct macro_ref_end_t;
|
---|
52 | struct include_kw_t;
|
---|
53 | struct define_kw_t;
|
---|
54 | struct undef_kw_t;
|
---|
55 | struct ifdef_kw_t;
|
---|
56 | struct ifndef_kw_t;
|
---|
57 | struct else_kw_t;
|
---|
58 | struct endif_kw_t;
|
---|
59 |
|
---|
60 | struct buffer_size_t;
|
---|
61 |
|
---|
62 | struct trim_leading_spaces_t;
|
---|
63 | struct trim_trailing_spaces_t;
|
---|
64 | struct skip_empty_lines_t;
|
---|
65 | struct detect_missing_macro_t;
|
---|
66 | } // namespace cfg_detail
|
---|
67 |
|
---|
68 | namespace {
|
---|
69 |
|
---|
70 | nfp::typed_keyword<cstring,cfg_detail::path_separators_t> path_separators;
|
---|
71 | nfp::typed_keyword<char_type ,cfg_detail::line_delimeter_t> line_delimeter;
|
---|
72 | nfp::typed_keyword<cstring,cfg_detail::sl_comment_delimeter_t> single_line_comment_delimeter;
|
---|
73 | nfp::typed_keyword<cstring,cfg_detail::command_delimeter_t> command_delimeter;
|
---|
74 | nfp::typed_keyword<cstring,cfg_detail::line_beak_t> line_beak;
|
---|
75 | nfp::typed_keyword<cstring,cfg_detail::macro_ref_begin_t> macro_ref_begin;
|
---|
76 | nfp::typed_keyword<cstring,cfg_detail::macro_ref_end_t> macro_ref_end;
|
---|
77 | nfp::typed_keyword<cstring,cfg_detail::include_kw_t> include_kw;
|
---|
78 | nfp::typed_keyword<cstring,cfg_detail::define_kw_t> define_kw;
|
---|
79 | nfp::typed_keyword<cstring,cfg_detail::undef_kw_t> undef_kw;
|
---|
80 | nfp::typed_keyword<cstring,cfg_detail::ifdef_kw_t> ifdef_kw;
|
---|
81 | nfp::typed_keyword<cstring,cfg_detail::ifndef_kw_t> ifndef_kw;
|
---|
82 | nfp::typed_keyword<cstring,cfg_detail::else_kw_t> else_kw;
|
---|
83 | nfp::typed_keyword<cstring,cfg_detail::endif_kw_t> endif_kw;
|
---|
84 |
|
---|
85 | nfp::typed_keyword<std::size_t,cfg_detail::buffer_size_t> buffer_size;
|
---|
86 |
|
---|
87 | nfp::typed_keyword<bool,cfg_detail::trim_leading_spaces_t> trim_leading_spaces;
|
---|
88 | nfp::typed_keyword<bool,cfg_detail::trim_trailing_spaces_t> trim_trailing_spaces;
|
---|
89 | nfp::typed_keyword<bool,cfg_detail::skip_empty_lines_t> skip_empty_lines;
|
---|
90 | nfp::typed_keyword<bool,cfg_detail::detect_missing_macro_t> detect_missing_macro;
|
---|
91 |
|
---|
92 | } // local namespace
|
---|
93 |
|
---|
94 | // ************************************************************************** //
|
---|
95 | // ************** runtime::file::config_file_iterator ************** //
|
---|
96 | // ************************************************************************** //
|
---|
97 |
|
---|
98 | class config_file_iterator : public unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> {
|
---|
99 | typedef unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> base;
|
---|
100 | public:
|
---|
101 | // Public typedefs
|
---|
102 | typedef unit_test::callback1<cstring> command_handler;
|
---|
103 |
|
---|
104 | // Constructors
|
---|
105 | config_file_iterator() {}
|
---|
106 | explicit config_file_iterator( cstring file_name )
|
---|
107 | {
|
---|
108 | construct();
|
---|
109 | load( file_name );
|
---|
110 | }
|
---|
111 | template<typename Modifiers>
|
---|
112 | config_file_iterator( cstring file_name, Modifiers const& m )
|
---|
113 | {
|
---|
114 | construct();
|
---|
115 | m.apply_to( *this );
|
---|
116 | load( file_name );
|
---|
117 | }
|
---|
118 | config_file_iterator( config_file_iterator const& rhs )
|
---|
119 | : base( rhs )
|
---|
120 | , m_pimpl( rhs.m_pimpl )
|
---|
121 | {
|
---|
122 | rhs.m_valid = false;
|
---|
123 | }
|
---|
124 |
|
---|
125 | void operator=( config_file_iterator const& rhs )
|
---|
126 | {
|
---|
127 | if( this == &rhs )
|
---|
128 | return;
|
---|
129 |
|
---|
130 | (base&)(*this) = rhs;
|
---|
131 | m_pimpl = rhs.m_pimpl;
|
---|
132 | rhs.m_valid = false;
|
---|
133 | } // Assignment
|
---|
134 |
|
---|
135 |
|
---|
136 | // Access methods
|
---|
137 | location const& curr_location();
|
---|
138 | void register_command_handler( cstring command_kw, command_handler const& );
|
---|
139 |
|
---|
140 | // Parameters setters
|
---|
141 | void set_parameter( rtti::id_t, cstring );
|
---|
142 | void set_parameter( rtti::id_t, bool );
|
---|
143 | void set_parameter( rtti::id_t, char_type );
|
---|
144 | void set_parameter( rtti::id_t, std::size_t );
|
---|
145 |
|
---|
146 | private:
|
---|
147 | friend class unit_test::input_iterator_core_access;
|
---|
148 |
|
---|
149 | void construct();
|
---|
150 | void load( cstring file_name );
|
---|
151 |
|
---|
152 | // increment implementation
|
---|
153 | bool get();
|
---|
154 |
|
---|
155 | // Data members
|
---|
156 | struct Impl;
|
---|
157 | shared_ptr<Impl> m_pimpl;
|
---|
158 | };
|
---|
159 |
|
---|
160 | } // namespace file
|
---|
161 |
|
---|
162 | } // namespace BOOST_RT_PARAM_NAMESPACE
|
---|
163 |
|
---|
164 | } // namespace boost
|
---|
165 |
|
---|
166 | // ************************************************************************** //
|
---|
167 | // Revision History:
|
---|
168 | //
|
---|
169 | // $Log: config_file_iterator.hpp,v $
|
---|
170 | // Revision 1.2 2005/04/17 15:50:38 rogeeff
|
---|
171 | // portability fixes
|
---|
172 | //
|
---|
173 | // Revision 1.1 2005/04/12 06:42:44 rogeeff
|
---|
174 | // Runtime.Param library initial commit
|
---|
175 | //
|
---|
176 | // ************************************************************************** //
|
---|
177 |
|
---|
178 | #endif // BOOST_RT_FILE_CONFIG_FILE_ITERATOR_HPP_062604GER
|
---|