// (C) Copyright Gennadiy Rozental 2005-2008. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/test for the library home page. // // File : $RCSfile$ // // Version : $Revision: 54633 $ // // Description : defines and implements inline model of program environment // *************************************************************************** #ifndef BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER #define BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER #ifdef UNDER_CE #error Windows CE does not support environment variables. #endif // Boost.Runtime.Parameter #include #include #include #include #include #include #include // Boost.Test #include // Boost #include namespace boost { namespace BOOST_RT_PARAM_NAMESPACE { // ************************************************************************** // // ************** runtime::environment implementation ************** // // ************************************************************************** // namespace environment { namespace rt_env_detail { template variable_data& init_new_var( cstring var_name, Modifiers m = nfp::no_params ) { rt_env_detail::variable_data& new_vd = new_var_record( var_name ); cstring str_value = sys_read_var( new_vd.m_var_name ); if( !str_value.is_empty() ) { try { boost::optional value; if( m.has( interpreter ) ) m[interpreter]( str_value, value ); else interpret_argument_value( str_value, value, 0 ); if( !!value ) { new_vd.m_value.reset( new typed_argument( new_vd ) ); arg_value( *new_vd.m_value ) = *value; } } catch( ... ) { // !! could we do that // !! should we report an error? } } if( !new_vd.m_value && m.has( default_value ) ) { new_vd.m_value.reset( new typed_argument( new_vd ) ); nfp::optionally_assign( arg_value( *new_vd.m_value ), m[default_value] ); } nfp::optionally_assign( new_vd.m_global_id, m, global_id ); return new_vd; } //____________________________________________________________________________// } // namespace rt_env_detail } // namespace environment // ************************************************************************** // // ************** runtime::environment ************** // // ************************************************************************** // namespace environment { // variable access variable_base var( cstring var_name ); //________________________________________________________________________// template inline variable var( cstring var_name ) { rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); return environment::variable( !vd ? rt_env_detail::init_new_var( var_name, nfp::no_params ) : *vd ); } //________________________________________________________________________// template inline variable var( cstring var_name, Modifiers const& m ) { rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); return environment::variable( !vd ? rt_env_detail::init_new_var( var_name, m ) : *vd ); } //________________________________________________________________________// // direct variable value access inline cstring get( cstring var_name ) { return environment::var( var_name ).value(); } //________________________________________________________________________// template inline T const& get( cstring var_name ) { return environment::var( var_name ).value(); } //________________________________________________________________________// template inline void get( cstring var_name, boost::optional& res ) { variable const& v = environment::var( var_name ); v.value( res ); } //________________________________________________________________________// } // namespace environment namespace env = environment; } // namespace BOOST_RT_PARAM_NAMESPACE } // namespace boost #ifndef BOOST_RT_PARAM_OFFLINE #define BOOST_RT_PARAM_INLINE inline #include #endif #endif // BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER