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
00049 #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FUNCTIONALS
00050 #define WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FUNCTIONALS
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FUNCTIONALS_MAJOR 4
00054 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FUNCTIONALS_MINOR 1
00055 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FUNCTIONALS_REVISION 3
00056 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_FUNCTIONALS_EDIT 81
00057 #endif
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00074 # include <winstl/winstl.h>
00075 #endif
00076 #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
00077 # include <winstl/filesystem/filesystem_traits.hpp>
00078 #endif
00079 #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER
00080 # include <winstl/filesystem/file_path_buffer.hpp>
00081 #endif
00082 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00083 # include <stlsoft/shims/access/string.hpp>
00084 #endif
00085 #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
00086 # include <winstl/shims/access/string.hpp>
00087 #endif
00088 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00089 # include <stlsoft/memory/auto_buffer.hpp>
00090 #endif
00091 #ifndef _WINSTL_FUNCTIONALS_NO_STD
00092 # include <functional>
00093 #else
00094 # error Now need to write that std_binary_function stuff!!
00095 #endif
00096
00097
00098
00099
00100
00101 #ifndef _WINSTL_NO_NAMESPACE
00102 # if defined(_STLSOFT_NO_NAMESPACE) || \
00103 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00104
00105 namespace winstl
00106 {
00107 # else
00108
00109
00110 namespace stlsoft
00111 {
00112
00113 namespace winstl_project
00114 {
00115
00116 # endif
00117 #endif
00118
00119
00120
00121
00122
00123 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00124
00125 template <ss_typename_param_k C>
00126 inline bool file_exists_envx_(C const* s, ws_bool_t bExpandEnvironmentStrings)
00127 {
00128 typedef filesystem_traits<C> traits_t;
00129 typedef basic_file_path_buffer<C> buffer_t;
00130
00131 buffer_t nvx;
00132 buffer_t full;
00133
00134 if( bExpandEnvironmentStrings &&
00135 NULL == traits_t::str_chr(s, '%'))
00136 {
00137 bExpandEnvironmentStrings = false;
00138 }
00139
00140 if(bExpandEnvironmentStrings)
00141 {
00142 if(!traits_t::expand_environment_strings(s, &nvx[0], nvx.size()))
00143 {
00144 return false;
00145 }
00146 else
00147 {
00148 s = nvx.c_str();
00149 }
00150 }
00151
00152 if(!traits_t::get_full_path_name(s, full.size(), &full[0]))
00153 {
00154 return false;
00155 }
00156 else
00157 {
00158 return traits_t::file_exists(&full[0]);
00159 }
00160 }
00161
00162 template <ss_typename_param_k C>
00163 inline bool are_paths_equal_envx_(C const* s1, C const* s2, ws_bool_t bExpandEnvironmentStrings)
00164 {
00165 typedef filesystem_traits<C> traits_t;
00166 typedef basic_file_path_buffer<C> buffer_t;
00167
00168 buffer_t full1;
00169 buffer_t full2;
00170 buffer_t nvx1;
00171 buffer_t nvx2;
00172 C *dummy;
00173
00174 if( bExpandEnvironmentStrings &&
00175 NULL == traits_t::str_chr(s1, '%') &&
00176 NULL == traits_t::str_chr(s2, '%'))
00177 {
00178 bExpandEnvironmentStrings = false;
00179 }
00180
00181 if(bExpandEnvironmentStrings)
00182 {
00183 if( !traits_t::expand_environment_strings(s1, &nvx1[0], nvx1.size()) ||
00184 !traits_t::expand_environment_strings(s2, &nvx2[0], nvx2.size()))
00185 {
00186 return false;
00187 }
00188 else
00189 {
00190 s1 = nvx1.c_str();
00191 s2 = nvx2.c_str();
00192 }
00193 }
00194
00195 if( !traits_t::get_full_path_name(s1, full1.size(), &full1[0], &dummy) ||
00196 !traits_t::get_full_path_name(s2, full2.size(), &full2[0], &dummy))
00197 {
00198 return false;
00199 }
00200 else
00201 {
00202 traits_t::remove_dir_end(&full1[0]);
00203 traits_t::remove_dir_end(&full2[0]);
00204
00205 s1 = full1.c_str();
00206 s2 = full2.c_str();
00207 }
00208
00209 return 0 == traits_t::str_compare_no_case(s1, s2);
00210 }
00211
00212 #endif
00213
00214
00215
00216
00217
00229 template< ss_typename_param_k C
00230 , ss_typename_param_k A1 = C const*
00231 , ss_typename_param_k A2 = C const*
00232 >
00233
00234 struct path_compare
00235 : public winstl_ns_qual_std(binary_function)<A1, A2, ws_bool_t>
00236 {
00239 private:
00240 typedef winstl_ns_qual_std(binary_function)<A1, A2, ws_bool_t> parent_class_type;
00241 public:
00243 typedef C char_type;
00245 typedef ss_typename_type_k parent_class_type::first_argument_type first_argument_type;
00247 typedef ss_typename_type_k parent_class_type::second_argument_type second_argument_type;
00249 typedef ss_typename_type_k parent_class_type::result_type result_type;
00251 typedef path_compare<C, A1, A2> class_type;
00253
00256 public:
00260 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00261 template<ss_typename_param_k T1, ss_typename_param_k T2>
00262 result_type operator ()(T1 const& s1, T2 const& s2) const
00263 #else
00264 result_type operator ()(first_argument_type s1, second_argument_type s2) const
00265 #endif
00266 {
00267 return are_paths_equal_envx_(stlsoft_ns_qual(c_str_ptr)(s1), stlsoft_ns_qual(c_str_ptr)(s2), false);
00268 }
00270 };
00271
00284 template< ss_typename_param_k C
00285 , ss_typename_param_k A1 = C const*
00286 , ss_typename_param_k A2 = C const*
00287 >
00288
00289 struct path_compare_env
00290 : public winstl_ns_qual_std(binary_function)<A1, A2, ws_bool_t>
00291 {
00294 private:
00295 typedef winstl_ns_qual_std(binary_function)<A1, A2, ws_bool_t> parent_class_type;
00296 public:
00298 typedef C char_type;
00300 typedef ss_typename_type_k parent_class_type::first_argument_type first_argument_type;
00302 typedef ss_typename_type_k parent_class_type::second_argument_type second_argument_type;
00304 typedef ss_typename_type_k parent_class_type::result_type result_type;
00306 typedef path_compare_env<C, A1, A2> class_type;
00308
00311 public:
00315 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00316 template<ss_typename_param_k T1, ss_typename_param_k T2>
00317 result_type operator ()(T1 const& s1, T2 const& s2) const
00318 #else
00319 result_type operator ()(first_argument_type s1, second_argument_type s2) const
00320 #endif
00321 {
00322 return are_paths_equal_envx_(stlsoft_ns_qual(c_str_ptr)(s1), stlsoft_ns_qual(c_str_ptr)(s2), true);
00323 }
00325 };
00326
00337 template< ss_typename_param_k C
00338 , ss_typename_param_k A = C const*
00339 >
00340
00341 struct path_exists
00342 : public winstl_ns_qual_std(unary_function)<A, ws_bool_t>
00343 {
00346 private:
00347 typedef winstl_ns_qual_std(unary_function)<A, ws_bool_t> parent_class_type;
00348 public:
00350 typedef C char_type;
00352 typedef A argument_type;
00354 typedef path_exists<C, A> class_type;
00356
00359 public:
00360 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00361 template <ss_typename_param_k S>
00362 ws_bool_t operator ()(S const& s) const
00363 #else
00364 ws_bool_t operator ()(argument_type s) const
00365 #endif
00366 {
00367 return file_exists_envx_(stlsoft_ns_qual(c_str_ptr)(s), false);
00368 }
00370 };
00371
00383 template< ss_typename_param_k C
00384 , ss_typename_param_k A = C const*
00385 >
00386
00387 struct path_exists_env
00388 : public winstl_ns_qual_std(unary_function)<A, ws_bool_t>
00389 {
00392 private:
00393 typedef winstl_ns_qual_std(unary_function)<A, ws_bool_t> parent_class_type;
00394 public:
00396 typedef C char_type;
00398 typedef A argument_type;
00400 typedef path_exists_env<C, A> class_type;
00402
00405 public:
00406 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00407 template <ss_typename_param_k S>
00408 ws_bool_t operator ()(S const& s) const
00409 #else
00410 ws_bool_t operator ()(argument_type s) const
00411 #endif
00412 {
00413 return file_exists_envx_(stlsoft_ns_qual(c_str_ptr)(s), true);
00414 }
00416 };
00417
00418
00435 template< ss_typename_param_k C
00436 , ss_typename_param_k A = C const*
00437 >
00438
00439 struct path_contains_file
00440 : public winstl_ns_qual_std(unary_function)<A, ws_bool_t>
00441 {
00444 private:
00445 typedef winstl_ns_qual_std(unary_function)<A, ws_bool_t> parent_class_type;
00446 public:
00448 typedef C char_type;
00450 typedef A argument_type;
00452 typedef path_contains_file<C, A> class_type;
00454
00457 public:
00458 path_contains_file(char_type const* file)
00459 : m_file(file)
00460 {}
00462
00465 public:
00466 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00467 template <ss_typename_param_k S>
00468 ws_bool_t operator ()(S const& s) const
00469 #else
00470 ws_bool_t operator ()(argument_type s) const
00471 #endif
00472 {
00473 return path_contains_file_(stlsoft_ns_qual(c_str_ptr)(s), m_file);
00474 }
00476
00479 private:
00480 static ws_bool_t path_contains_file_(char_type const* directory, char_type const* file)
00481 {
00482 typedef filesystem_traits<char_type> traits_t;
00483 typedef stlsoft_ns_qual(auto_buffer)<char_type> buffer_t;
00484
00485 const ws_size_t cchDirectory = traits_t::str_len(directory);
00486 const ws_size_t cchFile = traits_t::str_len(file);
00487 buffer_t path(1 + cchDirectory + 1 + cchFile + 1);
00488
00489 traits_t::str_copy(&path[0], directory);
00490 traits_t::ensure_dir_end(&path[0]);
00491 traits_t::str_cat(&path[0], file);
00492
00493 return traits_t::file_exists(path.data());
00494 }
00496
00499 private:
00500 char_type const* m_file;
00502 };
00503
00505
00506
00507 #ifdef STLSOFT_UNITTEST
00508 # include "./unittest/functionals_unittest_.h"
00509 #endif
00510
00511
00512
00513 #ifndef _WINSTL_NO_NAMESPACE
00514 # if defined(_STLSOFT_NO_NAMESPACE) || \
00515 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00516 }
00517 # else
00518 }
00519 }
00520 # endif
00521 #endif
00522
00523
00524
00525 #endif
00526
00527