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
00041
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef UNIXSTL_INCL_H_UNIXSTL
00061 # include "unixstl.h"
00062 #endif
00063 #ifndef UNIXSTL_INCL_H_UNIXSTL_FILESYSTEM_TRAITS
00064 # include "unixstl_filesystem_traits.h"
00065 #endif
00066 #ifndef UNIXSTL_INCL_H_UNIXSTL_FILE_PATH_BUFFER
00067 # include "unixstl_file_path_buffer.h"
00068 #endif
00069
00070
00071
00072
00073
00074 #ifndef _UNIXSTL_NO_NAMESPACE
00075 # if defined(_STLSOFT_NO_NAMESPACE) || \
00076 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00077
00078 namespace unixstl
00079 {
00080 # else
00081
00082
00083 namespace stlsoft
00084 {
00085
00086 namespace unixstl_project
00087 {
00088
00089 # endif
00090 #endif
00091
00092
00093
00096
00100
00105
00106
00107
00108
00109
00110
00111
00112
00117 template< ss_typename_param_k C
00118 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00119 , ss_typename_param_k T = filesystem_traits<C>
00120 #else
00121 , ss_typename_param_k T
00122 #endif
00123 >
00124 class basic_current_directory
00125 {
00126 public:
00128 typedef C char_type;
00130 typedef T traits_type;
00132 typedef basic_current_directory<C, T> class_type;
00134 typedef us_size_t size_type;
00135
00136
00137 public:
00139 basic_current_directory();
00140
00141
00142 public:
00144 static size_type get_path(char_type *buffer, size_type cchBuffer);
00145
00146
00147 public:
00149 char_type const *get_path() const;
00151 char_type const *c_str() const;
00153 size_type length() const;
00154
00155
00156 public:
00158 operator char_type const *() const
00159 {
00160 return get_path();
00161 }
00162
00163
00164 private:
00165 basic_file_path_buffer<char_type> m_dir;
00166 size_type const m_len;
00167
00168
00169 private:
00170 basic_current_directory(const class_type &);
00171 basic_current_directory &operator =(const class_type &);
00172 };
00173
00174
00175
00176
00177
00179 typedef basic_current_directory<us_char_a_t, filesystem_traits<us_char_a_t> > current_directory_a;
00181 typedef basic_current_directory<us_char_w_t, filesystem_traits<us_char_w_t> > current_directory_w;
00182
00183
00184
00185
00186
00187 template< ss_typename_param_k C
00188 , ss_typename_param_k T
00189 >
00190 inline C const *c_str_ptr_null(basic_current_directory<C, T> const &b)
00191 {
00192 return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
00193 }
00194
00195 template< ss_typename_param_k C
00196 , ss_typename_param_k T
00197 >
00198 inline C const *c_str_ptr(basic_current_directory<C, T> const &b)
00199 {
00200 return stlsoft_ns_qual(c_str_ptr)(b.c_str());
00201 }
00202
00203 template< ss_typename_param_k C
00204 , ss_typename_param_k T
00205 >
00206 inline us_size_t c_str_len(basic_current_directory<C, T> const &b)
00207 {
00208 return stlsoft_ns_qual(c_str_len)(b.c_str());
00209 }
00210
00211 template< ss_typename_param_k C
00212 , ss_typename_param_k T
00213 >
00214 inline us_size_t c_str_size(basic_current_directory<C, T> const &b)
00215 {
00216 return stlsoft_ns_qual(c_str_size)(b.c_str());
00217 }
00218
00219 template< ss_typename_param_k S
00220 , ss_typename_param_k C
00221 , ss_typename_param_k T
00222 >
00223 inline S &operator <<(S & s, basic_current_directory<C, T> const &b)
00224 {
00225 s << b.c_str();
00226
00227 return s;
00228 }
00229
00230
00231
00232
00233
00234 #ifdef STLSOFT_UNITTEST
00235
00236 namespace unittest
00237 {
00238 ss_bool_t test_unixstl_current_directory(unittest_reporter *r)
00239 {
00240 using stlsoft::unittest::unittest_initialiser;
00241
00242 ss_bool_t bSuccess = true;
00243
00244 unittest_initialiser init(r, "UNIXSTL", "current_directory", __FILE__);
00245
00246 typedef basic_current_directory<char> curr_dir_t;
00247
00248 basic_file_path_buffer<char> sz;
00249 curr_dir_t cd;
00250
00251 getcwd(&sz[0], sz.size());
00252
00253 if(0 != strcmp(sz.c_str(), cd.c_str()))
00254 {
00255 r->report("basic_current_directory<char> failed ", __LINE__);
00256 bSuccess = false;
00257 }
00258
00259 return bSuccess;
00260 }
00261
00262 unittest_registrar unittest_unixstl_current_directory(test_unixstl_current_directory);
00263
00264 }
00265
00266 #endif
00267
00268
00269
00270
00271
00272 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00273
00274 template< ss_typename_param_k C
00275 , ss_typename_param_k T
00276 >
00277 inline basic_current_directory<C, T>::basic_current_directory()
00278 : m_len(get_path(&m_dir[0], m_dir.size()))
00279 {}
00280
00281 template< ss_typename_param_k C
00282 , ss_typename_param_k T
00283 >
00284 inline ss_typename_type_k basic_current_directory<C, T>::size_type basic_current_directory<C, T>::get_path(ss_typename_type_k basic_current_directory<C, T>::char_type *buffer, ss_typename_type_k basic_current_directory<C, T>::size_type cchBuffer)
00285 {
00286 return static_cast<size_type>(traits_type::get_current_directory(cchBuffer, buffer));
00287 }
00288
00289 template< ss_typename_param_k C
00290 , ss_typename_param_k T
00291 >
00292 inline ss_typename_type_k basic_current_directory<C, T>::char_type const *basic_current_directory<C, T>::get_path() const
00293 {
00294 #if defined(__STLSOFT_COMPILER_IS_GCC) && \
00295 __GNUC__ < 3
00296 return m_dir.c_str();
00297 #else
00298 return stlsoft_ns_qual(c_str_ptr)(m_dir);
00299 #endif
00300 }
00301
00302 template< ss_typename_param_k C
00303 , ss_typename_param_k T
00304 >
00305 inline ss_typename_type_k basic_current_directory<C, T>::char_type const *basic_current_directory<C, T>::c_str() const
00306 {
00307 return get_path();
00308 }
00309
00310 template< ss_typename_param_k C
00311 , ss_typename_param_k T
00312 >
00313 inline ss_typename_type_k basic_current_directory<C, T>::size_type basic_current_directory<C, T>::length() const
00314 {
00315 return m_len;
00316 }
00317
00318 #endif
00319
00320
00321
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 #endif
00335
00336
00337
00338
00339
00340