[857] | 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.hpp,v $
|
---|
| 9 | //
|
---|
| 10 | // Version : $Revision: 1.1 $
|
---|
| 11 | //
|
---|
| 12 | // Description : defines models configuration file, it's parameter and parameter namespaces
|
---|
| 13 | // ***************************************************************************
|
---|
| 14 |
|
---|
| 15 | #ifndef BOOST_RT_FILE_CONFIG_FILE_HPP_010105GER
|
---|
| 16 | #define BOOST_RT_FILE_CONFIG_FILE_HPP_010105GER
|
---|
| 17 |
|
---|
| 18 | // Boost.Runtime.Parameter
|
---|
| 19 | #include <boost/test/utils/runtime/config.hpp>
|
---|
| 20 |
|
---|
| 21 | #include <boost/test/utils/runtime/file/config_file_iterator.hpp>
|
---|
| 22 |
|
---|
| 23 | // Boost.Test
|
---|
| 24 | #include <boost/test/utils/class_properties.hpp>
|
---|
| 25 | #include <boost/test/utils/named_params.hpp>
|
---|
| 26 |
|
---|
| 27 | // Boost
|
---|
| 28 | #include <boost/optional.hpp>
|
---|
| 29 |
|
---|
| 30 | // STL
|
---|
| 31 | #include <list>
|
---|
| 32 |
|
---|
| 33 | namespace boost {
|
---|
| 34 |
|
---|
| 35 | namespace BOOST_RT_PARAM_NAMESPACE {
|
---|
| 36 |
|
---|
| 37 | namespace file {
|
---|
| 38 |
|
---|
| 39 | // ************************************************************************** //
|
---|
| 40 | // ************** runtime::file::parameter ************** //
|
---|
| 41 | // ************************************************************************** //
|
---|
| 42 |
|
---|
| 43 | class param_namespace;
|
---|
| 44 |
|
---|
| 45 | class parameter {
|
---|
| 46 | public:
|
---|
| 47 | // Constructor
|
---|
| 48 | parameter( cstring name, cstring value, param_namespace const& parent );
|
---|
| 49 |
|
---|
| 50 | BOOST_READONLY_PROPERTY( dstring, (parameter)) p_name;
|
---|
| 51 | BOOST_READONLY_PROPERTY( dstring, (parameter)) p_value;
|
---|
| 52 |
|
---|
| 53 | friend std::ostream& operator<<( std::ostream& os, parameter const& );
|
---|
| 54 |
|
---|
| 55 | private:
|
---|
| 56 | // Data members
|
---|
| 57 | param_namespace const& m_parent;
|
---|
| 58 | };
|
---|
| 59 |
|
---|
| 60 | // ************************************************************************** //
|
---|
| 61 | // ************** runtime::file::modifiers ************** //
|
---|
| 62 | // ************************************************************************** //
|
---|
| 63 |
|
---|
| 64 | namespace {
|
---|
| 65 | nfp::typed_keyword<cstring, struct value_marker_t> value_marker;
|
---|
| 66 | nfp::typed_keyword<cstring, struct value_delimeter_t> value_delimeter;
|
---|
| 67 | nfp::typed_keyword<cstring, struct namespace_delimeter_t> namespace_delimeter;
|
---|
| 68 | } // local namespace
|
---|
| 69 |
|
---|
| 70 | // ************************************************************************** //
|
---|
| 71 | // ************** runtime::file::param_namespace ************** //
|
---|
| 72 | // ************************************************************************** //
|
---|
| 73 |
|
---|
| 74 | class param_namespace {
|
---|
| 75 | public:
|
---|
| 76 | typedef std::list<parameter>::iterator iterator;
|
---|
| 77 | typedef std::list<parameter>::const_iterator const_iterator;
|
---|
| 78 | typedef std::list<param_namespace>::iterator sub_ns_iterator;
|
---|
| 79 | typedef std::list<param_namespace>::const_iterator sub_ns_const_iterator;
|
---|
| 80 |
|
---|
| 81 | // Public properties
|
---|
| 82 | BOOST_READONLY_PROPERTY( dstring, (param_namespace)) p_name;
|
---|
| 83 | unit_test::readonly_property<param_namespace const*> p_parent;
|
---|
| 84 |
|
---|
| 85 | void load( config_file_iterator cf_it ) { load( cf_it, nfp::no_params ); }
|
---|
| 86 | template<typename Modifier>
|
---|
| 87 | void load( config_file_iterator cf_it, Modifier const& m )
|
---|
| 88 | {
|
---|
| 89 | cstring vm = m.has( value_marker ) ? m[value_marker] : BOOST_RT_PARAM_CSTRING_LITERAL( "\"" );
|
---|
| 90 | cstring vd = m.has( value_delimeter ) ? m[value_delimeter] : BOOST_RT_PARAM_CSTRING_LITERAL( "= \t\n\r" );
|
---|
| 91 | cstring nd = m.has( namespace_delimeter ) ? m[namespace_delimeter] : BOOST_RT_PARAM_CSTRING_LITERAL( "::" );
|
---|
| 92 |
|
---|
| 93 | load_impl( cf_it, vm, vd, nd );
|
---|
| 94 | }
|
---|
| 95 | void load( cstring file_name )
|
---|
| 96 | {
|
---|
| 97 | load( file_name, nfp::no_params );
|
---|
| 98 | }
|
---|
| 99 | template<typename Modifier>
|
---|
| 100 | void load( cstring file_name, Modifier const& m )
|
---|
| 101 | {
|
---|
| 102 | config_file_iterator cfi( file_name, m );
|
---|
| 103 |
|
---|
| 104 | load( cfi, m );
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | void insert_param( cstring param_name, cstring param_value );
|
---|
| 108 | param_namespace& subnamespace( cstring namespace_name ); // find and insert if not present
|
---|
| 109 | void clear();
|
---|
| 110 |
|
---|
| 111 | iterator begin() { return m_parameters.begin(); }
|
---|
| 112 | const_iterator begin() const { return m_parameters.begin(); }
|
---|
| 113 |
|
---|
| 114 | iterator end() { return m_parameters.end(); }
|
---|
| 115 | const_iterator end() const { return m_parameters.end(); }
|
---|
| 116 |
|
---|
| 117 | sub_ns_iterator sub_ns_begin() { return m_subnamespaces.begin(); }
|
---|
| 118 | sub_ns_const_iterator sub_ns_begin() const { return m_subnamespaces.begin(); }
|
---|
| 119 |
|
---|
| 120 | sub_ns_iterator sub_ns_end() { return m_subnamespaces.end(); }
|
---|
| 121 | sub_ns_const_iterator sub_ns_end() const { return m_subnamespaces.end(); }
|
---|
| 122 |
|
---|
| 123 | void print_full_name( std::ostream& os ) const;
|
---|
| 124 |
|
---|
| 125 | protected:
|
---|
| 126 | explicit param_namespace( cstring name, param_namespace const* parent = 0 );
|
---|
| 127 |
|
---|
| 128 | private:
|
---|
| 129 | void load_impl( config_file_iterator cf_it,
|
---|
| 130 | cstring value_marker_, cstring value_delimeter_, cstring namespace_delimeter_ );
|
---|
| 131 |
|
---|
| 132 | // Data members
|
---|
| 133 | std::list<parameter> m_parameters;
|
---|
| 134 | std::list<param_namespace> m_subnamespaces;
|
---|
| 135 | };
|
---|
| 136 |
|
---|
| 137 | //____________________________________________________________________________//
|
---|
| 138 |
|
---|
| 139 | boost::optional<cstring>
|
---|
| 140 | get_param_value( param_namespace const& where_from,
|
---|
| 141 | cstring name_part1,
|
---|
| 142 | cstring name_part2 = cstring(),
|
---|
| 143 | cstring name_part3 = cstring(),
|
---|
| 144 | cstring name_part4 = cstring(),
|
---|
| 145 | cstring name_part5 = cstring() );
|
---|
| 146 |
|
---|
| 147 | //____________________________________________________________________________//
|
---|
| 148 |
|
---|
| 149 | cstring
|
---|
| 150 | get_requ_param_value( param_namespace const& where_from,
|
---|
| 151 | cstring name_part1,
|
---|
| 152 | cstring name_part2 = cstring(),
|
---|
| 153 | cstring name_part3 = cstring(),
|
---|
| 154 | cstring name_part4 = cstring(),
|
---|
| 155 | cstring name_part5 = cstring() );
|
---|
| 156 |
|
---|
| 157 | //____________________________________________________________________________//
|
---|
| 158 |
|
---|
| 159 | param_namespace const*
|
---|
| 160 | get_param_subns( param_namespace const& where_from,
|
---|
| 161 | cstring namespace_name );
|
---|
| 162 |
|
---|
| 163 | //____________________________________________________________________________//
|
---|
| 164 |
|
---|
| 165 | // ************************************************************************** //
|
---|
| 166 | // ************** runtime::file::config_file ************** //
|
---|
| 167 | // ************************************************************************** //
|
---|
| 168 |
|
---|
| 169 | class config_file : public param_namespace {
|
---|
| 170 | public:
|
---|
| 171 | // Constructor
|
---|
| 172 | config_file();
|
---|
| 173 | config_file( cstring file_name );
|
---|
| 174 | };
|
---|
| 175 |
|
---|
| 176 | } // namespace file
|
---|
| 177 |
|
---|
| 178 | } // namespace BOOST_RT_PARAM_NAMESPACE
|
---|
| 179 |
|
---|
| 180 | } // namespace boost
|
---|
| 181 |
|
---|
| 182 | // ************************************************************************** //
|
---|
| 183 | // Revision History:
|
---|
| 184 | //
|
---|
| 185 | // $Log: config_file.hpp,v $
|
---|
| 186 | // Revision 1.1 2005/04/12 06:42:44 rogeeff
|
---|
| 187 | // Runtime.Param library initial commit
|
---|
| 188 | //
|
---|
| 189 | // ************************************************************************** //
|
---|
| 190 |
|
---|
| 191 | #endif // BOOST_RT_FILE_CONFIG_FILE_HPP_010105GER
|
---|