00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef WINSTL_INCL_H_WINSTL
00070 # include "winstl.h"
00071 #endif
00072
00073 #if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00074 _MSC_VER < 1200
00075 # error winstl_environment_variable.h is not compatible with Visual C++ 5.0 or earlier
00076 #endif
00077
00078 #ifndef WINSTL_INCL_H_WINSTL_SYSTEM_VERSION
00079 # include "winstl_filesystem_traits.h"
00080 #endif
00081 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00082 # include "stlsoft_string_access.h"
00083 #endif
00084 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00085 # include "winstl_string_access.h"
00086 #endif
00087 #ifndef STLSOFT_INCL_H_STLSOFT_AUTO_BUFFER
00088 # include "stlsoft_auto_buffer.h"
00089 #endif
00090 #ifndef WINSTL_INCL_H_WINSTL_PROCESSHEAP_ALLOCATOR
00091 # include "winstl_processheap_allocator.h"
00092 #endif
00093
00094
00095
00096
00097
00098 #ifndef _WINSTL_NO_NAMESPACE
00099 # if defined(_STLSOFT_NO_NAMESPACE) || \
00100 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00101
00102 namespace winstl
00103 {
00104 # else
00105
00106
00107 namespace stlsoft
00108 {
00109
00110 namespace winstl_project
00111 {
00112
00113 # endif
00114 #endif
00115
00116 #if !defined(__STLSOFT_COMPILER_IS_MWERKS)
00117 stlsoft_ns_using(c_str_ptr)
00118 #endif
00119
00120
00121
00124
00128
00133
00134
00135
00136
00137
00138
00139
00140
00145 template< ss_typename_param_k C
00146 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00147 , ss_typename_param_k T = filesystem_traits<C>
00148 #else
00149 , ss_typename_param_k T
00150 #endif
00151 >
00152 class basic_environment_variable
00153 {
00154 public:
00156 typedef C char_type;
00158 typedef T traits_type;
00160 typedef basic_environment_variable<C, T> class_type;
00162 typedef ss_size_t size_type;
00163
00164
00165 public:
00167 ss_explicit_k basic_environment_variable(char_type const *name)
00168 : m_buffer(1 + traits_type::get_environment_variable(name, 0, 0))
00169 {
00170 if( 0 == traits_type::get_environment_variable(name, m_buffer, m_buffer.size()) &&
00171 0 != m_buffer.size())
00172 {
00173 m_buffer[0] = 0;
00174 }
00175 }
00176 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00177
00178 template<ss_typename_param_k S>
00179 ss_explicit_k basic_environment_variable(S const &name)
00180 : m_buffer(1 + traits_type::get_environment_variable(c_str_ptr(name), 0, 0))
00181 {
00182 if( 0 == traits_type::get_environment_variable(c_str_ptr(name), m_buffer, m_buffer.size()) &&
00183 0 != m_buffer.size())
00184 {
00185 m_buffer[0] = 0;
00186 }
00187 }
00188 #endif
00189
00190
00191 public:
00193 operator char_type const *() const
00194 {
00195 return m_buffer.data();
00196 }
00197
00198
00199 public:
00201 size_type length() const
00202 {
00203 return m_buffer.size() - 1;
00204 }
00205
00206
00207 private:
00208 typedef stlsoft_ns_qual(auto_buffer)<char_type, processheap_allocator<char_type> > buffer_t;
00209
00210 buffer_t m_buffer;
00211
00212
00213 private:
00214 basic_environment_variable(basic_environment_variable const &);
00215 basic_environment_variable &operator =(basic_environment_variable const &);
00216 };
00217
00218
00219
00220
00221
00223 typedef basic_environment_variable<ws_char_a_t, filesystem_traits<ws_char_a_t> > environment_variable_a;
00225 typedef basic_environment_variable<ws_char_w_t, filesystem_traits<ws_char_w_t> > environment_variable_w;
00227 typedef basic_environment_variable<TCHAR, filesystem_traits<TCHAR> > environment_variable;
00228
00230
00231
00232 #ifdef STLSOFT_UNITTEST
00233
00234 namespace unittest
00235 {
00236 ss_bool_t test_winstl_environment_variable(unittest_reporter *r)
00237 {
00238 using stlsoft::unittest::unittest_initialiser;
00239
00240 ss_bool_t bSuccess = true;
00241
00242 unittest_initialiser init(r, "WinSTL", "environment_variable", __FILE__);
00243
00244 typedef environment_variable_a env_var_t;
00245
00246 env_var_t path("PATH");
00247
00248 if(0 != strcmp(getenv("PATH"), path))
00249 {
00250 r->report("basic_environment_variable<char> failed ", __LINE__);
00251 bSuccess = false;
00252 }
00253
00254 return bSuccess;
00255 }
00256
00257 unittest_registrar unittest_winstl_environment_variable(test_winstl_environment_variable);
00258
00259 }
00260
00261 #endif
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 #endif
00274
00275
00276
00277
00278
00279