1
// (C) Copyright Gennadiy Rozental 2005-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)
6
// See http://www.boost.org/libs/test for the library home page.
10
// Version : $Revision: 57992 $
12
// Description : implements model of program environment
13
// ***************************************************************************
15
#ifndef BOOST_RT_ENV_ENVIRONMENT_IPP_062904GER
16
#define BOOST_RT_ENV_ENVIRONMENT_IPP_062904GER
18
// Boost.Runtime.Parameter
19
#include <boost/test/utils/runtime/config.hpp>
20
#include <boost/test/utils/runtime/validation.hpp>
22
#include <boost/test/utils/runtime/env/variable.hpp>
25
#include <boost/test/utils/basic_cstring/compare.hpp>
26
#include <boost/test/utils/basic_cstring/io.hpp>
34
namespace BOOST_RT_PARAM_NAMESPACE {
36
namespace environment {
38
// ************************************************************************** //
39
// ************** runtime::environment ************** //
40
// ************************************************************************** //
42
namespace rt_env_detail {
44
typedef std::map<cstring,rt_env_detail::variable_data> registry;
45
typedef std::list<dstring> keys;
47
BOOST_RT_PARAM_INLINE registry& s_registry() { static registry instance; return instance; }
48
BOOST_RT_PARAM_INLINE keys& s_keys() { static keys instance; return instance; }
50
BOOST_RT_PARAM_INLINE variable_data&
51
new_var_record( cstring var_name )
53
// save the name in list of keys
54
s_keys().push_back( dstring() );
55
dstring& key = s_keys().back();
56
assign_op( key, var_name, 0 );
58
// create and return new record
59
variable_data& new_var_data = s_registry()[key];
61
new_var_data.m_var_name = key;
66
//____________________________________________________________________________//
68
BOOST_RT_PARAM_INLINE variable_data*
69
find_var_record( cstring var_name )
71
registry::iterator it = s_registry().find( var_name );
73
return it == s_registry().end() ? 0 : &(it->second);
76
//____________________________________________________________________________//
80
#pragma warning(disable:4996) // getenv
83
BOOST_RT_PARAM_INLINE cstring
84
sys_read_var( cstring var_name )
87
return BOOST_RT_PARAM_GETENV( var_name.begin() );
93
//____________________________________________________________________________//
95
BOOST_RT_PARAM_INLINE void
96
sys_write_var( cstring var_name, format_stream& var_value )
98
BOOST_RT_PARAM_PUTENV( var_name, cstring( var_value.str() ) );
101
//____________________________________________________________________________//
103
} // namespace rt_env_detail
105
BOOST_RT_PARAM_INLINE variable_base
106
var( cstring var_name )
108
rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name );
110
BOOST_RT_PARAM_VALIDATE_LOGIC( !!vd,
111
BOOST_RT_PARAM_LITERAL( "First access to the environment variable " )
112
<< var_name << BOOST_RT_PARAM_LITERAL( " should be typed" ) );
114
return variable_base( *vd );
117
//____________________________________________________________________________//
119
} // namespace environment
121
} // namespace BOOST_RT_PARAM_NAMESPACE
125
#endif // BOOST_RT_ENV_ENVIRONMENT_IPP_062904GER