[857] | 1 | // (C) Copyright Gennadiy Rozental 2005.
|
---|
| 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: environment.hpp,v $
|
---|
| 9 | //
|
---|
| 10 | // Version : $Revision: 1.3 $
|
---|
| 11 | //
|
---|
| 12 | // Description : defines and implements inline model of program environment
|
---|
| 13 | // ***************************************************************************
|
---|
| 14 |
|
---|
| 15 | #ifndef BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER
|
---|
| 16 | #define BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER
|
---|
| 17 |
|
---|
| 18 | // Boost.Runtime.Parameter
|
---|
| 19 | #include <boost/test/utils/runtime/config.hpp>
|
---|
| 20 | #include <boost/test/utils/runtime/fwd.hpp>
|
---|
| 21 | #include <boost/test/utils/runtime/argument.hpp>
|
---|
| 22 | #include <boost/test/utils/runtime/interpret_argument_value.hpp>
|
---|
| 23 |
|
---|
| 24 | #include <boost/test/utils/runtime/env/fwd.hpp>
|
---|
| 25 | #include <boost/test/utils/runtime/env/modifier.hpp>
|
---|
| 26 | #include <boost/test/utils/runtime/env/variable.hpp>
|
---|
| 27 |
|
---|
| 28 | // Boost.Test
|
---|
| 29 | #include <boost/test/utils/callback.hpp>
|
---|
| 30 |
|
---|
| 31 | // Boost
|
---|
| 32 | #include <boost/optional.hpp>
|
---|
| 33 |
|
---|
| 34 | namespace boost {
|
---|
| 35 |
|
---|
| 36 | namespace BOOST_RT_PARAM_NAMESPACE {
|
---|
| 37 |
|
---|
| 38 | // ************************************************************************** //
|
---|
| 39 | // ************** runtime::environment implementation ************** //
|
---|
| 40 | // ************************************************************************** //
|
---|
| 41 |
|
---|
| 42 | namespace environment {
|
---|
| 43 |
|
---|
| 44 | namespace rt_env_detail {
|
---|
| 45 |
|
---|
| 46 | template<typename T, typename Modifiers>
|
---|
| 47 | variable_data&
|
---|
| 48 | init_new_var( cstring var_name, Modifiers m = nfp::no_params )
|
---|
| 49 | {
|
---|
| 50 | rt_env_detail::variable_data& new_vd = new_var_record( var_name );
|
---|
| 51 |
|
---|
| 52 | cstring str_value = sys_read_var( new_vd.m_var_name );
|
---|
| 53 |
|
---|
| 54 | if( !str_value.is_empty() ) {
|
---|
| 55 | try {
|
---|
| 56 | boost::optional<T> value;
|
---|
| 57 |
|
---|
| 58 | if( m.has( interpreter ) )
|
---|
| 59 | m[interpreter]( str_value, value );
|
---|
| 60 | else
|
---|
| 61 | interpret_argument_value( str_value, value, 0 );
|
---|
| 62 |
|
---|
| 63 | if( !!value ) {
|
---|
| 64 | new_vd.m_value.reset( new typed_argument<T>( new_vd ) );
|
---|
| 65 |
|
---|
| 66 | arg_value<T>( *new_vd.m_value ) = *value;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | catch( ... ) { // !! could we do that
|
---|
| 70 | // !! should we report an error?
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | if( !new_vd.m_value && m.has( default_value ) ) {
|
---|
| 75 | new_vd.m_value.reset( new typed_argument<T>( new_vd ) );
|
---|
| 76 |
|
---|
| 77 | nfp::optionally_assign( arg_value<T>( *new_vd.m_value ), m[default_value] );
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | nfp::optionally_assign( new_vd.m_global_id, m, global_id );
|
---|
| 81 |
|
---|
| 82 | return new_vd;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | //____________________________________________________________________________//
|
---|
| 86 |
|
---|
| 87 | } // namespace rt_env_detail
|
---|
| 88 |
|
---|
| 89 | } // namespace environment
|
---|
| 90 |
|
---|
| 91 | // ************************************************************************** //
|
---|
| 92 | // ************** runtime::environment ************** //
|
---|
| 93 | // ************************************************************************** //
|
---|
| 94 |
|
---|
| 95 | namespace environment {
|
---|
| 96 |
|
---|
| 97 | // variable access
|
---|
| 98 | variable_base
|
---|
| 99 | var( cstring var_name );
|
---|
| 100 |
|
---|
| 101 | //________________________________________________________________________//
|
---|
| 102 |
|
---|
| 103 | template<typename T>
|
---|
| 104 | inline variable<T>
|
---|
| 105 | var( cstring var_name )
|
---|
| 106 | {
|
---|
| 107 | rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name );
|
---|
| 108 |
|
---|
| 109 | return environment::variable<T>( !vd ? rt_env_detail::init_new_var<T>( var_name, nfp::no_params ) : *vd );
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | //________________________________________________________________________//
|
---|
| 113 |
|
---|
| 114 | template<typename T, typename Modifiers>
|
---|
| 115 | inline variable<T>
|
---|
| 116 | var( cstring var_name, Modifiers const& m )
|
---|
| 117 | {
|
---|
| 118 | rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name );
|
---|
| 119 |
|
---|
| 120 | return environment::variable<T>( !vd ? rt_env_detail::init_new_var<T>( var_name, m ) : *vd );
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | //________________________________________________________________________//
|
---|
| 124 |
|
---|
| 125 | // direct variable value access
|
---|
| 126 | inline cstring
|
---|
| 127 | get( cstring var_name )
|
---|
| 128 | {
|
---|
| 129 | return environment::var<cstring>( var_name ).value();
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | //________________________________________________________________________//
|
---|
| 133 |
|
---|
| 134 | template<typename T>
|
---|
| 135 | inline T const&
|
---|
| 136 | get( cstring var_name )
|
---|
| 137 | {
|
---|
| 138 | return environment::var<T>( var_name ).value();
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | //________________________________________________________________________//
|
---|
| 142 |
|
---|
| 143 | template<typename T>
|
---|
| 144 | inline void
|
---|
| 145 | get( cstring var_name, boost::optional<T>& res )
|
---|
| 146 | {
|
---|
| 147 | variable<T> const& v = environment::var<T>( var_name );
|
---|
| 148 | v.value( res );
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | //________________________________________________________________________//
|
---|
| 152 |
|
---|
| 153 | } // namespace environment
|
---|
| 154 |
|
---|
| 155 | namespace env = environment;
|
---|
| 156 |
|
---|
| 157 | } // namespace BOOST_RT_PARAM_NAMESPACE
|
---|
| 158 |
|
---|
| 159 | } // namespace boost
|
---|
| 160 |
|
---|
| 161 | #ifndef BOOST_RT_PARAM_OFFLINE
|
---|
| 162 |
|
---|
| 163 | #define BOOST_RT_PARAM_INLINE inline
|
---|
| 164 | #include <boost/test/utils/runtime/env/environment.ipp>
|
---|
| 165 |
|
---|
| 166 | #endif
|
---|
| 167 |
|
---|
| 168 | // ************************************************************************** //
|
---|
| 169 | // Revision History:
|
---|
| 170 | //
|
---|
| 171 | // $Log: environment.hpp,v $
|
---|
| 172 | // Revision 1.3 2005/05/14 05:41:10 rogeeff
|
---|
| 173 | // *** empty log message ***
|
---|
| 174 | //
|
---|
| 175 | // Revision 1.2 2005/05/14 05:34:57 rogeeff
|
---|
| 176 | // *** empty log message ***
|
---|
| 177 | //
|
---|
| 178 | // Revision 1.1 2005/04/12 06:42:43 rogeeff
|
---|
| 179 | // Runtime.Param library initial commit
|
---|
| 180 | //
|
---|
| 181 | // ************************************************************************** //
|
---|
| 182 |
|
---|
| 183 | #endif // BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER
|
---|