| 1 | // Boost lpath.hpp ---------------------------------------------------------// |
|---|
| 2 | |
|---|
| 3 | // Copyright Beman Dawes 2005 |
|---|
| 4 | |
|---|
| 5 | // Use, modification, and distribution is subject to the Boost Software |
|---|
| 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | |
|---|
| 9 | // See library home page at http://www.boost.org/libs/filesystem |
|---|
| 10 | |
|---|
| 11 | #include <boost/filesystem/path.hpp> |
|---|
| 12 | #include <string> |
|---|
| 13 | |
|---|
| 14 | namespace std |
|---|
| 15 | { |
|---|
| 16 | // Note well: this specialization is meant only to support wide_test.cpp. |
|---|
| 17 | // It is not fully functional, fully correct, or efficient. |
|---|
| 18 | template<> struct char_traits<long> |
|---|
| 19 | { |
|---|
| 20 | typedef long char_type; |
|---|
| 21 | typedef long int_type; |
|---|
| 22 | typedef streamoff off_type; |
|---|
| 23 | typedef streampos pos_type; |
|---|
| 24 | typedef mbstate_t state_type; |
|---|
| 25 | static void assign(char_type& c1, const char_type& c2){c1=c2;} |
|---|
| 26 | static bool eq(const char_type& c1, const char_type& c2){return c1==c2;} |
|---|
| 27 | static bool lt(const char_type& c1, const char_type& c2){return c1<c2;} |
|---|
| 28 | static int compare(const char_type* s1, const char_type* s2, size_t n) |
|---|
| 29 | { |
|---|
| 30 | const char_type* e = s1 + n; |
|---|
| 31 | for ( ;s1 != e && *s1 == *s2; ++s1, ++s2 ) {} |
|---|
| 32 | return s1 == e ? 0 : (*s1<*s2 ? -1 : 1); |
|---|
| 33 | } |
|---|
| 34 | static size_t length(const char_type* s) |
|---|
| 35 | { const char_type* b=s; for(;*s!=0L;++s){} return s-b; } |
|---|
| 36 | |
|---|
| 37 | static const char_type* find(const char_type* s, size_t n, const char_type& a) |
|---|
| 38 | { return 0; } |
|---|
| 39 | |
|---|
| 40 | // copy semantics will do for wide_test |
|---|
| 41 | static char_type* move(char_type* s1, const char_type* s2, size_t n) |
|---|
| 42 | { char_type* b=s1; for(const char_type* e=s1+n;s1!=e;++s1,++s2) *s1=*s2; return b; } |
|---|
| 43 | |
|---|
| 44 | static char_type* copy(char_type* s1, const char_type* s2, size_t n) |
|---|
| 45 | { char_type* b=s1; for(const char_type* e=s1+n;s1!=e;++s1,++s2) *s1=*s2; return b; } |
|---|
| 46 | |
|---|
| 47 | static char_type* assign(char_type* s, size_t n, char_type a) |
|---|
| 48 | { char_type* b=s; for(char_type* e=s+n;s!=e;++s) *s=a; return b; } |
|---|
| 49 | |
|---|
| 50 | static int_type not_eof(const int_type& c); |
|---|
| 51 | static char_type to_char_type(const int_type& c); |
|---|
| 52 | static int_type to_int_type(const char_type& c); |
|---|
| 53 | static bool eq_int_type(const int_type& c1, const int_type& c2); |
|---|
| 54 | static int_type eof(); |
|---|
| 55 | }; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | namespace user |
|---|
| 59 | { |
|---|
| 60 | typedef std::basic_string<long> lstring; |
|---|
| 61 | struct lpath_traits; |
|---|
| 62 | typedef boost::filesystem::basic_path<lstring, lpath_traits> lpath; |
|---|
| 63 | |
|---|
| 64 | struct lpath_traits |
|---|
| 65 | { |
|---|
| 66 | typedef lstring internal_string_type; |
|---|
| 67 | typedef std::string external_string_type; |
|---|
| 68 | |
|---|
| 69 | static external_string_type to_external( const lpath &, |
|---|
| 70 | const internal_string_type & src ) |
|---|
| 71 | { |
|---|
| 72 | external_string_type tmp; |
|---|
| 73 | for ( internal_string_type::const_iterator it( src.begin() ); |
|---|
| 74 | it != src.end(); ++it ) |
|---|
| 75 | { |
|---|
| 76 | tmp += static_cast<external_string_type::value_type>(*it); |
|---|
| 77 | } |
|---|
| 78 | return tmp; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | static internal_string_type to_internal( const external_string_type & src ) |
|---|
| 82 | { |
|---|
| 83 | internal_string_type tmp; |
|---|
| 84 | for ( external_string_type::const_iterator it( src.begin() ); |
|---|
| 85 | it != src.end(); ++it ) tmp += *it; |
|---|
| 86 | return tmp; |
|---|
| 87 | } |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | } // namespace user |
|---|
| 91 | |
|---|
| 92 | namespace boost |
|---|
| 93 | { |
|---|
| 94 | namespace filesystem |
|---|
| 95 | { |
|---|
| 96 | template<> struct is_basic_path<user::lpath> |
|---|
| 97 | { static const bool value = true; }; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|