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 #ifndef UNIXSTL_INCL_H_UNIXSTL
00060 # include "unixstl.h"
00061 #endif
00062 #ifndef UNIXSTL_INCL_H_UNIXSTL_SYSTEM_VERSION
00063 # include "unixstl_filesystem_traits.h"
00064 #endif
00065 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00066 # include "stlsoft_string_access.h"
00067 #endif
00068 #ifndef UNIXSTL_INCL_H_UNIXSTL_STRING_ACCESS
00069 # include "unixstl_string_access.h"
00070 #endif
00071 #ifndef STLSOFT_INCL_H_STLSOFT_AUTO_BUFFER
00072 # include "stlsoft_auto_buffer.h"
00073 #endif
00074 #ifndef STLSOFT_INCL_H_STLSOFT_MALLOC_ALLOCATOR
00075 # include "stlsoft_malloc_allocator.h"
00076 #endif
00077
00078
00079
00080
00081
00082 #ifndef _UNIXSTL_NO_NAMESPACE
00083 # if defined(_STLSOFT_NO_NAMESPACE) || \
00084 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00085
00086 namespace unixstl
00087 {
00088 # else
00089
00090
00091 namespace stlsoft
00092 {
00093
00094 namespace unixstl_project
00095 {
00096
00097 # endif
00098 #endif
00099
00100 #if !defined(__STLSOFT_COMPILER_IS_GCC) && \
00101 __GNUC__ < 3
00102 stlsoft_ns_using(c_str_ptr)
00103 #endif
00104
00105
00106
00109
00113
00118
00119
00120
00121
00122
00123
00124
00125
00130 template< ss_typename_param_k C
00131 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00132 , ss_typename_param_k T = filesystem_traits<C>
00133 #else
00134 , ss_typename_param_k T
00135 #endif
00136 >
00137 class basic_environment_variable
00138 {
00139 public:
00141 typedef C char_type;
00143 typedef T traits_type;
00145 typedef basic_environment_variable<C, T> class_type;
00147 typedef us_size_t size_type;
00148
00149
00150 public:
00152 ss_explicit_k basic_environment_variable(char_type const *name)
00153 : m_buffer(1 + traits_type::get_environment_variable(name, 0, 0))
00154 {
00155 if( 0 == traits_type::get_environment_variable(name, m_buffer, m_buffer.size()) &&
00156 0 != m_buffer.size())
00157 {
00158 m_buffer[0] = 0;
00159 }
00160 }
00161 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00162
00163 template<ss_typename_param_k S>
00164 ss_explicit_k basic_environment_variable(S const &name)
00165 : m_buffer(1 + traits_type::get_environment_variable(c_str_ptr(name), 0, 0))
00166 {
00167 if( 0 == traits_type::get_environment_variable(c_str_ptr(name), m_buffer, m_buffer.size()) &&
00168 0 != m_buffer.size())
00169 {
00170 m_buffer[0] = 0;
00171 }
00172 }
00173 #endif
00174
00175
00176 public:
00178 operator char_type const *() const
00179 {
00180 return m_buffer.data();
00181 }
00182
00183
00184 public:
00186 size_type length() const
00187 {
00188 return m_buffer.size() - 1;
00189 }
00190
00191
00192 private:
00193 typedef stlsoft_ns_qual(auto_buffer)<char_type, malloc_allocator<char_type> > buffer_t;
00194
00195 buffer_t m_buffer;
00196
00197
00198 private:
00199 basic_environment_variable(basic_environment_variable const &);
00200 basic_environment_variable &operator =(basic_environment_variable const &);
00201 };
00202
00203
00204
00205
00206
00208 typedef basic_environment_variable<us_char_a_t, filesystem_traits<us_char_a_t> > environment_variable_a;
00210 typedef basic_environment_variable<us_char_w_t, filesystem_traits<us_char_w_t> > environment_variable_w;
00211
00212
00213
00214
00215
00216 #if !defined(__STLSOFT_COMPILER_IS_MSVC) || \
00217 _MSC_VER >= 1100
00218
00221 template<ss_typename_param_k C>
00222 inline basic_environment_variable<C> make_environment_variable(C const *path)
00223 {
00224 return basic_environment_variable<C>(path);
00225 }
00226
00227 #endif
00228
00230
00231
00232 #ifdef STLSOFT_UNITTEST
00233
00234 namespace unittest
00235 {
00236 ss_bool_t test_unixstl_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, "UNIXSTL", "environment_variable", __FILE__);
00243
00244 typedef basic_environment_variable<char> 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_unixstl_environment_variable(test_unixstl_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