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.ipp,v $
|
---|
9 | //
|
---|
10 | // Version : $Revision: 1.5 $
|
---|
11 | //
|
---|
12 | // Description : implements model of program environment
|
---|
13 | // ***************************************************************************
|
---|
14 |
|
---|
15 | #ifndef BOOST_RT_ENV_ENVIRONMENT_IPP_062904GER
|
---|
16 | #define BOOST_RT_ENV_ENVIRONMENT_IPP_062904GER
|
---|
17 |
|
---|
18 | // Boost.Runtime.Parameter
|
---|
19 | #include <boost/test/utils/runtime/config.hpp>
|
---|
20 | #include <boost/test/utils/runtime/validation.hpp>
|
---|
21 |
|
---|
22 | #include <boost/test/utils/runtime/env/variable.hpp>
|
---|
23 |
|
---|
24 | // Boost.Test
|
---|
25 | #include <boost/test/utils/basic_cstring/compare.hpp>
|
---|
26 | #include <boost/test/utils/basic_cstring/io.hpp>
|
---|
27 |
|
---|
28 | // STL
|
---|
29 | #include <map>
|
---|
30 | #include <list>
|
---|
31 |
|
---|
32 | namespace boost {
|
---|
33 |
|
---|
34 | namespace BOOST_RT_PARAM_NAMESPACE {
|
---|
35 |
|
---|
36 | namespace environment {
|
---|
37 |
|
---|
38 | // ************************************************************************** //
|
---|
39 | // ************** runtime::environment ************** //
|
---|
40 | // ************************************************************************** //
|
---|
41 |
|
---|
42 | namespace rt_env_detail {
|
---|
43 |
|
---|
44 | typedef std::map<cstring,rt_env_detail::variable_data> registry;
|
---|
45 | typedef std::list<dstring> keys;
|
---|
46 |
|
---|
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; }
|
---|
49 |
|
---|
50 | BOOST_RT_PARAM_INLINE variable_data&
|
---|
51 | new_var_record( cstring var_name )
|
---|
52 | {
|
---|
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 );
|
---|
57 |
|
---|
58 | // create and return new record
|
---|
59 | variable_data& new_var_data = s_registry()[key];
|
---|
60 |
|
---|
61 | new_var_data.m_var_name = key;
|
---|
62 |
|
---|
63 | return new_var_data;
|
---|
64 | }
|
---|
65 |
|
---|
66 | //____________________________________________________________________________//
|
---|
67 |
|
---|
68 | BOOST_RT_PARAM_INLINE variable_data*
|
---|
69 | find_var_record( cstring var_name )
|
---|
70 | {
|
---|
71 | registry::iterator it = s_registry().find( var_name );
|
---|
72 |
|
---|
73 | return it == s_registry().end() ? 0 : &(it->second);
|
---|
74 | }
|
---|
75 |
|
---|
76 | //____________________________________________________________________________//
|
---|
77 |
|
---|
78 | BOOST_RT_PARAM_INLINE cstring
|
---|
79 | sys_read_var( cstring var_name )
|
---|
80 | {
|
---|
81 | using namespace std;
|
---|
82 | return BOOST_RT_PARAM_GETENV( var_name.begin() );
|
---|
83 | }
|
---|
84 |
|
---|
85 | //____________________________________________________________________________//
|
---|
86 |
|
---|
87 | BOOST_RT_PARAM_INLINE void
|
---|
88 | sys_write_var( cstring var_name, format_stream& var_value )
|
---|
89 | {
|
---|
90 | BOOST_RT_PARAM_PUTENV( var_name, cstring( var_value.str() ) );
|
---|
91 | }
|
---|
92 |
|
---|
93 | //____________________________________________________________________________//
|
---|
94 |
|
---|
95 | } // namespace rt_env_detail
|
---|
96 |
|
---|
97 | BOOST_RT_PARAM_INLINE variable_base
|
---|
98 | var( cstring var_name )
|
---|
99 | {
|
---|
100 | rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name );
|
---|
101 |
|
---|
102 | BOOST_RT_PARAM_VALIDATE_LOGIC( !!vd,
|
---|
103 | BOOST_RT_PARAM_LITERAL( "First access to the environment variable " )
|
---|
104 | << var_name << BOOST_RT_PARAM_LITERAL( " should be typed" ) );
|
---|
105 |
|
---|
106 | return variable_base( *vd );
|
---|
107 | }
|
---|
108 |
|
---|
109 | //____________________________________________________________________________//
|
---|
110 |
|
---|
111 | } // namespace environment
|
---|
112 |
|
---|
113 | } // namespace BOOST_RT_PARAM_NAMESPACE
|
---|
114 |
|
---|
115 | } // namespace boost
|
---|
116 |
|
---|
117 | // ************************************************************************** //
|
---|
118 | // Revision History:
|
---|
119 | //
|
---|
120 | // $Log: environment.ipp,v $
|
---|
121 | // Revision 1.5 2005/05/14 05:41:10 rogeeff
|
---|
122 | // *** empty log message ***
|
---|
123 | //
|
---|
124 | // Revision 1.4 2005/05/05 05:55:45 rogeeff
|
---|
125 | // portability fixes
|
---|
126 | //
|
---|
127 | // Revision 1.3 2005/05/03 05:02:50 rogeeff
|
---|
128 | // como fixes
|
---|
129 | //
|
---|
130 | // Revision 1.2 2005/04/27 03:29:52 rogeeff
|
---|
131 | // portability fix
|
---|
132 | //
|
---|
133 | // Revision 1.1 2005/04/12 06:42:43 rogeeff
|
---|
134 | // Runtime.Param library initial commit
|
---|
135 | //
|
---|
136 | // ************************************************************************** //
|
---|
137 |
|
---|
138 | #endif // BOOST_RT_ENV_ENVIRONMENT_IPP_062904GER
|
---|