OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // FilePath is a container for pathnames stored in a platform's native string | 5 // FilePath is a container for pathnames stored in a platform's native string |
6 // type, providing containers for manipulation in according with the | 6 // type, providing containers for manipulation in according with the |
7 // platform's conventions for pathnames. It supports the following path | 7 // platform's conventions for pathnames. It supports the following path |
8 // types: | 8 // types: |
9 // | 9 // |
10 // POSIX Windows | 10 // POSIX Windows |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // here so that the same setting can be used in both the implementation and | 118 // here so that the same setting can be used in both the implementation and |
119 // in the unit test. | 119 // in the unit test. |
120 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
121 #define FILE_PATH_USES_DRIVE_LETTERS | 121 #define FILE_PATH_USES_DRIVE_LETTERS |
122 #define FILE_PATH_USES_WIN_SEPARATORS | 122 #define FILE_PATH_USES_WIN_SEPARATORS |
123 #endif // OS_WIN | 123 #endif // OS_WIN |
124 | 124 |
125 class Pickle; | 125 class Pickle; |
126 class PickleIterator; | 126 class PickleIterator; |
127 | 127 |
| 128 namespace base { |
| 129 |
128 // An abstraction to isolate users from the differences between native | 130 // An abstraction to isolate users from the differences between native |
129 // pathnames on different platforms. | 131 // pathnames on different platforms. |
130 class BASE_EXPORT FilePath { | 132 class BASE_EXPORT FilePath { |
131 public: | 133 public: |
132 #if defined(OS_POSIX) | 134 #if defined(OS_POSIX) |
133 // On most platforms, native pathnames are char arrays, and the encoding | 135 // On most platforms, native pathnames are char arrays, and the encoding |
134 // may or may not be specified. On Mac OS X, native pathnames are encoded | 136 // may or may not be specified. On Mac OS X, native pathnames are encoded |
135 // in UTF-8. | 137 // in UTF-8. |
136 typedef std::string StringType; | 138 typedef std::string StringType; |
137 #elif defined(OS_WIN) | 139 #elif defined(OS_WIN) |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // Remove trailing separators from this object. If the path is absolute, it | 393 // Remove trailing separators from this object. If the path is absolute, it |
392 // will never be stripped any more than to refer to the absolute root | 394 // will never be stripped any more than to refer to the absolute root |
393 // directory, so "////" will become "/", not "". A leading pair of | 395 // directory, so "////" will become "/", not "". A leading pair of |
394 // separators is never stripped, to support alternate roots. This is used to | 396 // separators is never stripped, to support alternate roots. This is used to |
395 // support UNC paths on Windows. | 397 // support UNC paths on Windows. |
396 void StripTrailingSeparatorsInternal(); | 398 void StripTrailingSeparatorsInternal(); |
397 | 399 |
398 StringType path_; | 400 StringType path_; |
399 }; | 401 }; |
400 | 402 |
| 403 } // namespace base |
| 404 |
| 405 // TODO(brettw) remove this once callers properly use the base namespace. |
| 406 using base::FilePath; |
| 407 |
401 // This is required by googletest to print a readable output on test failures. | 408 // This is required by googletest to print a readable output on test failures. |
402 BASE_EXPORT extern void PrintTo(const FilePath& path, std::ostream* out); | 409 BASE_EXPORT extern void PrintTo(const base::FilePath& path, std::ostream* out); |
403 | 410 |
404 // Macros for string literal initialization of FilePath::CharType[], and for | 411 // Macros for string literal initialization of FilePath::CharType[], and for |
405 // using a FilePath::CharType[] in a printf-style format string. | 412 // using a FilePath::CharType[] in a printf-style format string. |
406 #if defined(OS_POSIX) | 413 #if defined(OS_POSIX) |
407 #define FILE_PATH_LITERAL(x) x | 414 #define FILE_PATH_LITERAL(x) x |
408 #define PRFilePath "s" | 415 #define PRFilePath "s" |
409 #define PRFilePathLiteral "%s" | 416 #define PRFilePathLiteral "%s" |
410 #elif defined(OS_WIN) | 417 #elif defined(OS_WIN) |
411 #define FILE_PATH_LITERAL(x) L ## x | 418 #define FILE_PATH_LITERAL(x) L ## x |
412 #define PRFilePath "ls" | 419 #define PRFilePath "ls" |
413 #define PRFilePathLiteral L"%ls" | 420 #define PRFilePathLiteral L"%ls" |
414 #endif // OS_WIN | 421 #endif // OS_WIN |
415 | 422 |
416 // Provide a hash function so that hash_sets and maps can contain FilePath | 423 // Provide a hash function so that hash_sets and maps can contain FilePath |
417 // objects. | 424 // objects. |
418 namespace BASE_HASH_NAMESPACE { | 425 namespace BASE_HASH_NAMESPACE { |
419 #if defined(COMPILER_GCC) | 426 #if defined(COMPILER_GCC) |
420 | 427 |
421 template<> | 428 template<> |
422 struct hash<FilePath> { | 429 struct hash<base::FilePath> { |
423 size_t operator()(const FilePath& f) const { | 430 size_t operator()(const base::FilePath& f) const { |
424 return hash<FilePath::StringType>()(f.value()); | 431 return hash<base::FilePath::StringType>()(f.value()); |
425 } | 432 } |
426 }; | 433 }; |
427 | 434 |
428 #elif defined(COMPILER_MSVC) | 435 #elif defined(COMPILER_MSVC) |
429 | 436 |
430 inline size_t hash_value(const FilePath& f) { | 437 inline size_t hash_value(const base::FilePath& f) { |
431 return hash_value(f.value()); | 438 return hash_value(f.value()); |
432 } | 439 } |
433 | 440 |
434 #endif // COMPILER | 441 #endif // COMPILER |
435 | 442 |
436 } // namespace BASE_HASH_NAMESPACE | 443 } // namespace BASE_HASH_NAMESPACE |
437 | 444 |
438 #endif // BASE_FILE_PATH_H_ | 445 #endif // BASE_FILE_PATH_H_ |
OLD | NEW |