cmCMakePath.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <cstddef>
  6. #include <string>
  7. #include <utility>
  8. #include <cm/filesystem>
  9. #include <cm/string_view>
  10. #include <cm/type_traits>
  11. namespace cm {
  12. class static_string_view;
  13. }
  14. namespace detail {
  15. #if defined(__SUNPRO_CC) && defined(__sparc)
  16. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc fails to compile
  17. // the full 'is_pathable' and 'is_move_pathable' checks. We use it only to
  18. // improve error messages via 'enable_if' when calling methods with incorrect
  19. // types. Just pretend all types are allowed so we can at least compile valid
  20. // code.
  21. template <typename T>
  22. struct is_pathable : std::true_type
  23. {
  24. };
  25. template <typename T>
  26. struct is_move_pathable : std::true_type
  27. {
  28. };
  29. #else
  30. template <typename T, typename = void>
  31. struct is_pathable : std::false_type
  32. {
  33. };
  34. template <>
  35. struct is_pathable<cm::filesystem::path> : std::true_type
  36. {
  37. };
  38. template <>
  39. struct is_pathable<std::string> : std::true_type
  40. {
  41. };
  42. template <>
  43. struct is_pathable<cm::string_view> : std::true_type
  44. {
  45. };
  46. template <>
  47. struct is_pathable<cm::static_string_view> : std::true_type
  48. {
  49. };
  50. template <typename T>
  51. struct is_pathable<
  52. T,
  53. cm::enable_if_t<std::is_same<char*, typename std::decay<T>::type>::value,
  54. void>>
  55. : cm::bool_constant<std::is_same<char*, typename std::decay<T>::type>::value>
  56. {
  57. };
  58. template <typename T>
  59. struct is_move_pathable : std::false_type
  60. {
  61. };
  62. template <>
  63. struct is_move_pathable<cm::filesystem::path> : std::true_type
  64. {
  65. };
  66. template <>
  67. struct is_move_pathable<std::string> : std::true_type
  68. {
  69. };
  70. #endif
  71. }
  72. class cmCMakePath
  73. {
  74. private:
  75. template <typename Source>
  76. using enable_if_move_pathable =
  77. cm::enable_if_t<detail::is_move_pathable<Source>::value, cmCMakePath&>;
  78. template <typename Source>
  79. using enable_if_pathable =
  80. cm::enable_if_t<detail::is_pathable<Source>::value, cmCMakePath&>;
  81. public:
  82. using value_type = cm::filesystem::path::value_type;
  83. using string_type = cm::filesystem::path::string_type;
  84. enum format : unsigned char
  85. {
  86. auto_format =
  87. static_cast<unsigned char>(cm::filesystem::path::format::auto_format),
  88. native_format =
  89. static_cast<unsigned char>(cm::filesystem::path::format::native_format),
  90. generic_format =
  91. static_cast<unsigned char>(cm::filesystem::path::format::generic_format)
  92. };
  93. class iterator;
  94. using const_iterator = iterator;
  95. cmCMakePath() noexcept = default;
  96. cmCMakePath(const cmCMakePath&) = default;
  97. cmCMakePath(cmCMakePath&& path) noexcept
  98. : Path(std::forward<cm::filesystem::path>(path.Path))
  99. {
  100. }
  101. cmCMakePath(cm::filesystem::path path) noexcept
  102. : Path(std::move(path))
  103. {
  104. }
  105. cmCMakePath(cm::string_view source, format fmt = generic_format) noexcept
  106. : Path(FormatPath(source, fmt))
  107. {
  108. }
  109. cmCMakePath(const char* source, format fmt = generic_format) noexcept
  110. : Path(FormatPath(cm::string_view{ source }, fmt))
  111. {
  112. }
  113. #if defined(__SUNPRO_CC) && defined(__sparc)
  114. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  115. // standard methods and templates use the same name. The template is selected
  116. // rather than the standard one regardless the arguments of the method.
  117. cmCMakePath(const std::string& source, format fmt = generic_format)
  118. : Path(FormatPath(source, fmt))
  119. {
  120. }
  121. cmCMakePath(std::string&& source, format fmt = generic_format)
  122. : Path(FormatPath(std::move(source), fmt))
  123. {
  124. }
  125. #else
  126. template <typename Source, typename = enable_if_move_pathable<Source>>
  127. cmCMakePath(Source source, format fmt = generic_format)
  128. : Path(FormatPath(std::move(source), fmt))
  129. {
  130. }
  131. #endif
  132. template <typename Source, typename = enable_if_move_pathable<Source>>
  133. cmCMakePath& Assign(Source&& source)
  134. {
  135. this->Path = std::forward<Source>(source);
  136. return *this;
  137. }
  138. template <typename Source, typename = enable_if_pathable<Source>>
  139. cmCMakePath& Assign(const Source& source)
  140. {
  141. this->Path = source;
  142. return *this;
  143. }
  144. cmCMakePath& operator=(const cmCMakePath& path)
  145. {
  146. if (this != &path) {
  147. this->Path = path.Path;
  148. }
  149. return *this;
  150. }
  151. cmCMakePath& operator=(cmCMakePath&& path) noexcept
  152. {
  153. if (this != &path) {
  154. this->Path = std::move(path.Path);
  155. }
  156. return *this;
  157. }
  158. #if defined(__SUNPRO_CC) && defined(__sparc)
  159. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  160. // standard methods and templates use the same name. The template is selected
  161. // rather than the standard one regardless the arguments of the method.
  162. cmCMakePath& operator=(cm::filesystem::path&& source)
  163. {
  164. this->Assign(std::forward<cm::filesystem::path>(source));
  165. return *this;
  166. }
  167. cmCMakePath& operator=(std::string&& source)
  168. {
  169. this->Assign(std::forward<std::string>(source));
  170. return *this;
  171. }
  172. cmCMakePath& operator=(const cm::filesystem::path& source)
  173. {
  174. this->Assign(source);
  175. return *this;
  176. }
  177. cmCMakePath& operator=(const std::string& source)
  178. {
  179. this->Assign(source);
  180. return *this;
  181. }
  182. cmCMakePath& operator=(const cm::string_view source)
  183. {
  184. this->Assign(source);
  185. return *this;
  186. }
  187. cmCMakePath& operator=(const char* source)
  188. {
  189. this->Assign(cm::string_view{ source });
  190. return *this;
  191. }
  192. #else
  193. template <typename Source, typename = enable_if_move_pathable<Source>>
  194. cmCMakePath& operator=(Source&& source)
  195. {
  196. this->Assign(std::forward<Source>(source));
  197. return *this;
  198. }
  199. template <typename Source, typename = enable_if_pathable<Source>>
  200. cmCMakePath& operator=(const Source& source)
  201. {
  202. this->Assign(source);
  203. return *this;
  204. }
  205. #endif
  206. // Concatenation
  207. cmCMakePath& Append(const cmCMakePath& path)
  208. {
  209. return this->Append(path.Path);
  210. }
  211. cmCMakePath& Append(const cm::filesystem::path& path)
  212. {
  213. this->Path /= path;
  214. // filesystem::path::append use preferred_separator ('\' on Windows)
  215. // so convert back to '/'
  216. this->Path = this->Path.generic_string();
  217. return *this;
  218. }
  219. #if defined(__SUNPRO_CC) && defined(__sparc)
  220. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  221. // standard methods and templates use the same name. The template is selected
  222. // rather than the standard one regardless the arguments of the method.
  223. cmCMakePath& Append(const std::string& source)
  224. {
  225. return this->Append(cm::filesystem::path(source));
  226. }
  227. cmCMakePath& Append(cm::string_view source)
  228. {
  229. return this->Append(cm::filesystem::path(source));
  230. }
  231. cmCMakePath& Append(const char* source)
  232. {
  233. return this->Append(cm::filesystem::path(cm::string_view{ source }));
  234. }
  235. #else
  236. template <typename Source, typename = enable_if_pathable<Source>>
  237. cmCMakePath& Append(const Source& source)
  238. {
  239. return this->Append(cm::filesystem::path(source));
  240. }
  241. #endif
  242. cmCMakePath& operator/=(const cmCMakePath& path)
  243. {
  244. return this->Append(path);
  245. }
  246. template <typename Source, typename = enable_if_pathable<Source>>
  247. cmCMakePath& operator/=(const Source& source)
  248. {
  249. return this->Append(source);
  250. }
  251. cmCMakePath& Concat(const cmCMakePath& path)
  252. {
  253. this->Path += path.Path;
  254. return *this;
  255. }
  256. cmCMakePath& Concat(cm::string_view source)
  257. {
  258. this->Path.operator+=(std::string(source));
  259. return *this;
  260. }
  261. #if defined(__SUNPRO_CC) && defined(__sparc)
  262. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  263. // standard methods and templates use the same name. The template is selected
  264. // rather than the standard one regardless the arguments of the method.
  265. cmCMakePath& Concat(const cm::filesystem::path& source)
  266. {
  267. this->Path.operator+=(source);
  268. return *this;
  269. }
  270. cmCMakePath& Concat(const std::string& source)
  271. {
  272. this->Path.operator+=(source);
  273. return *this;
  274. }
  275. cmCMakePath& Concat(const char* source)
  276. {
  277. this->Path.operator+=(source);
  278. return *this;
  279. }
  280. #else
  281. template <typename Source, typename = enable_if_pathable<Source>>
  282. cmCMakePath& Concat(const Source& source)
  283. {
  284. this->Path.operator+=(source);
  285. return *this;
  286. }
  287. #endif
  288. cmCMakePath& operator+=(const cmCMakePath& path)
  289. {
  290. return this->Concat(path);
  291. }
  292. template <typename Source, typename = enable_if_pathable<Source>>
  293. cmCMakePath& operator+=(const Source& source)
  294. {
  295. return this->Concat(source);
  296. }
  297. // Manipulation
  298. void Clear() noexcept { this->Path.clear(); }
  299. cmCMakePath& RemoveFileName()
  300. {
  301. this->Path.remove_filename();
  302. return *this;
  303. }
  304. cmCMakePath& ReplaceFileName(const cmCMakePath& filename)
  305. {
  306. if (this->Path.has_filename()) {
  307. this->Path.replace_filename(filename.Path);
  308. }
  309. return *this;
  310. }
  311. #if defined(__SUNPRO_CC) && defined(__sparc)
  312. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  313. // standard methods and templates use the same name. The template is selected
  314. // rather than the standard one regardless the arguments of the method.
  315. cmCMakePath& ReplaceFileName(const cm::filesystem::path& filename)
  316. {
  317. if (this->Path.has_filename()) {
  318. this->Path.replace_filename(filename);
  319. }
  320. return *this;
  321. }
  322. cmCMakePath& ReplaceFileName(const std::string& filename)
  323. {
  324. if (this->Path.has_filename()) {
  325. this->Path.replace_filename(filename);
  326. }
  327. return *this;
  328. }
  329. cmCMakePath& ReplaceFileName(cm::string_view filename)
  330. {
  331. if (this->Path.has_filename()) {
  332. this->Path.replace_filename(filename);
  333. }
  334. return *this;
  335. }
  336. #else
  337. template <typename Source, typename = enable_if_pathable<Source>>
  338. cmCMakePath& ReplaceFileName(const Source& filename)
  339. {
  340. if (this->Path.has_filename()) {
  341. this->Path.replace_filename(filename);
  342. }
  343. return *this;
  344. }
  345. #endif
  346. cmCMakePath& ReplaceExtension(const cmCMakePath& extension = cmCMakePath())
  347. {
  348. this->Path.replace_extension(extension.Path);
  349. return *this;
  350. }
  351. #if defined(__SUNPRO_CC) && defined(__sparc)
  352. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  353. // standard methods and templates use the same name. The template is selected
  354. // rather than the standard one regardless the arguments of the method.
  355. cmCMakePath& ReplaceExtension(const cm::filesystem::path& extension)
  356. {
  357. this->Path.replace_extension(extension);
  358. return *this;
  359. }
  360. cmCMakePath& ReplaceExtension(const std::string& extension)
  361. {
  362. this->Path.replace_extension(extension);
  363. return *this;
  364. }
  365. cmCMakePath& ReplaceExtension(const cm::string_view extension)
  366. {
  367. this->Path.replace_extension(extension);
  368. return *this;
  369. }
  370. #else
  371. template <typename Source, typename = enable_if_pathable<Source>>
  372. cmCMakePath& ReplaceExtension(const Source& extension)
  373. {
  374. this->Path.replace_extension(extension);
  375. return *this;
  376. }
  377. #endif
  378. cmCMakePath& ReplaceWideExtension(
  379. const cmCMakePath& extension = cmCMakePath())
  380. {
  381. return this->ReplaceWideExtension(
  382. static_cast<cm::string_view>(extension.Path.string()));
  383. }
  384. cmCMakePath& ReplaceWideExtension(const cm::filesystem::path& extension)
  385. {
  386. return this->ReplaceWideExtension(
  387. static_cast<cm::string_view>(extension.string()));
  388. }
  389. #if defined(__SUNPRO_CC) && defined(__sparc)
  390. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  391. // standard methods and templates use the same name. The template is selected
  392. // rather than the standard one regardless the arguments of the method.
  393. cmCMakePath& ReplaceWideExtension(const std::string& extension)
  394. {
  395. return this->ReplaceWideExtension(cm::string_view{ extension });
  396. }
  397. #else
  398. template <typename Source, typename = enable_if_pathable<Source>>
  399. cmCMakePath& ReplaceWideExtension(const Source& extension)
  400. {
  401. return this->ReplaceWideExtension(extension);
  402. }
  403. #endif
  404. cmCMakePath& ReplaceWideExtension(cm::string_view extension);
  405. cmCMakePath& RemoveExtension()
  406. {
  407. if (this->Path.has_extension()) {
  408. this->ReplaceExtension(cm::string_view(""));
  409. }
  410. return *this;
  411. }
  412. cmCMakePath& RemoveWideExtension()
  413. {
  414. if (this->Path.has_extension()) {
  415. this->ReplaceWideExtension(cm::string_view(""));
  416. }
  417. return *this;
  418. }
  419. void swap(cmCMakePath& other) noexcept { this->Path.swap(other.Path); }
  420. // Observers
  421. std::string String() const { return this->Path.string(); }
  422. std::wstring WString() const { return this->Path.wstring(); }
  423. string_type Native() const
  424. {
  425. string_type path;
  426. this->GetNativePath(path);
  427. return path;
  428. }
  429. std::string NativeString() const
  430. {
  431. std::string path;
  432. this->GetNativePath(path);
  433. return path;
  434. }
  435. std::wstring NativeWString() const
  436. {
  437. std::wstring path;
  438. this->GetNativePath(path);
  439. return path;
  440. }
  441. std::string GenericString() const { return this->Path.generic_string(); }
  442. std::wstring GenericWString() const { return this->Path.generic_wstring(); }
  443. // Decomposition
  444. cmCMakePath GetRootName() const { return this->Path.root_name(); }
  445. cmCMakePath GetRootDirectory() const { return this->Path.root_directory(); }
  446. cmCMakePath GetRootPath() const { return this->Path.root_path(); }
  447. cmCMakePath GetFileName() const { return this->Path.filename(); }
  448. cmCMakePath GetExtension() const { return this->Path.extension(); }
  449. cmCMakePath GetWideExtension() const;
  450. cmCMakePath GetStem() const { return this->Path.stem(); }
  451. cmCMakePath GetNarrowStem() const;
  452. cmCMakePath GetRelativePath() const { return this->Path.relative_path(); }
  453. cmCMakePath GetParentPath() const { return this->Path.parent_path(); }
  454. // Generation
  455. cmCMakePath Normal() const
  456. {
  457. auto path = this->Path.lexically_normal();
  458. // filesystem::path:lexically_normal use preferred_separator ('\') on
  459. // Windows) so convert back to '/'
  460. return path.generic_string();
  461. }
  462. cmCMakePath Relative(const cmCMakePath& base) const
  463. {
  464. return this->Relative(base.Path);
  465. }
  466. cmCMakePath Relative(const cm::filesystem::path& base) const
  467. {
  468. auto path = this->Path.lexically_relative(base);
  469. // filesystem::path:lexically_relative use preferred_separator ('\') on
  470. // Windows) so convert back to '/'
  471. return path.generic_string();
  472. }
  473. #if defined(__SUNPRO_CC) && defined(__sparc)
  474. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  475. // standard methods and templates use the same name. The template is selected
  476. // rather than the standard one regardless the arguments of the method.
  477. cmCMakePath Relative(const std::string& base) const
  478. {
  479. return this->Relative(cm::filesystem::path(base));
  480. }
  481. cmCMakePath Relative(cm::string_view base) const
  482. {
  483. return this->Relative(cm::filesystem::path(base));
  484. }
  485. #else
  486. template <typename Source, typename = enable_if_pathable<Source>>
  487. cmCMakePath Relative(const Source& base) const
  488. {
  489. return this->Relative(cm::filesystem::path(base));
  490. }
  491. #endif
  492. cmCMakePath Proximate(const cmCMakePath& base) const
  493. {
  494. return this->Proximate(base.Path);
  495. }
  496. cmCMakePath Proximate(const cm::filesystem::path& base) const
  497. {
  498. auto path = this->Path.lexically_proximate(base);
  499. // filesystem::path::lexically_proximate use preferred_separator ('\') on
  500. // Windows) so convert back to '/'
  501. return path.generic_string();
  502. }
  503. #if defined(__SUNPRO_CC) && defined(__sparc)
  504. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  505. // standard methods and templates use the same name. The template is selected
  506. // rather than the standard one regardless the arguments of the method.
  507. cmCMakePath Proximate(const std::string& base) const
  508. {
  509. return this->Proximate(cm::filesystem::path(base));
  510. }
  511. cmCMakePath Proximate(cm::string_view base) const
  512. {
  513. return this->Proximate(cm::filesystem::path(base));
  514. }
  515. #else
  516. template <typename Source, typename = enable_if_pathable<Source>>
  517. cmCMakePath Proximate(const Source& base) const
  518. {
  519. return this->Proximate(cm::filesystem::path(base));
  520. }
  521. #endif
  522. cmCMakePath Absolute(const cmCMakePath& base) const
  523. {
  524. return this->Absolute(base.Path);
  525. }
  526. #if defined(__SUNPRO_CC) && defined(__sparc)
  527. // Oracle DeveloperStudio C++ compiler on Solaris/Sparc is confused when
  528. // standard methods and templates use the same name. The template is selected
  529. // rather than the standard one regardless the arguments of the method.
  530. cmCMakePath Absolute(const std::string& base) const
  531. {
  532. return this->Absolute(cm::filesystem::path(base));
  533. }
  534. cmCMakePath Absolute(cm::string_view base) const
  535. {
  536. return this->Absolute(cm::filesystem::path(base));
  537. }
  538. #else
  539. template <typename Source, typename = enable_if_pathable<Source>>
  540. cmCMakePath Absolute(const Source& base) const
  541. {
  542. return this->Absolute(cm::filesystem::path(base));
  543. }
  544. #endif
  545. cmCMakePath Absolute(const cm::filesystem::path& base) const;
  546. // Comparison
  547. int Compare(const cmCMakePath& path) const noexcept
  548. {
  549. return this->Path.compare(path.Path);
  550. }
  551. // Query
  552. bool IsEmpty() const noexcept { return this->Path.empty(); }
  553. bool HasRootPath() const { return this->Path.has_root_path(); }
  554. bool HasRootName() const { return this->Path.has_root_name(); }
  555. bool HasRootDirectory() const { return this->Path.has_root_directory(); }
  556. bool HasRelativePath() const { return this->Path.has_relative_path(); }
  557. bool HasParentPath() const { return this->Path.has_parent_path(); }
  558. bool HasFileName() const { return this->Path.has_filename(); }
  559. bool HasStem() const { return this->Path.has_stem(); }
  560. bool HasExtension() const { return this->Path.has_extension(); }
  561. bool IsAbsolute() const { return this->Path.is_absolute(); }
  562. bool IsRelative() const { return this->Path.is_relative(); }
  563. bool IsPrefix(const cmCMakePath& path) const;
  564. // Iterators
  565. // =========
  566. inline iterator begin() const;
  567. inline iterator end() const;
  568. // Non-members
  569. // ===========
  570. friend bool operator==(const cmCMakePath& lhs,
  571. const cmCMakePath& rhs) noexcept
  572. {
  573. return lhs.Compare(rhs) == 0;
  574. }
  575. friend bool operator!=(const cmCMakePath& lhs,
  576. const cmCMakePath& rhs) noexcept
  577. {
  578. return lhs.Compare(rhs) != 0;
  579. }
  580. friend cmCMakePath operator/(const cmCMakePath& lhs, const cmCMakePath& rhs)
  581. {
  582. cmCMakePath result(lhs);
  583. result /= rhs;
  584. return result;
  585. }
  586. private:
  587. friend std::size_t hash_value(const cmCMakePath& path) noexcept;
  588. static std::string FormatPath(std::string path, format fmt = generic_format);
  589. static std::string FormatPath(cm::string_view path,
  590. format fmt = generic_format)
  591. {
  592. return FormatPath(std::string(path), fmt);
  593. }
  594. void GetNativePath(std::string& path) const;
  595. void GetNativePath(std::wstring& path) const;
  596. cm::filesystem::path Path;
  597. };
  598. class cmCMakePath::iterator
  599. {
  600. public:
  601. using iterator_category = cm::filesystem::path::iterator::iterator_category;
  602. using value_type = cmCMakePath;
  603. using difference_type = cm::filesystem::path::iterator::difference_type;
  604. using pointer = const cmCMakePath*;
  605. using reference = const cmCMakePath&;
  606. iterator() = default;
  607. iterator(const iterator& other)
  608. : Iterator(other.Iterator)
  609. , Path(other.Path)
  610. , PathElement(*this->Iterator)
  611. {
  612. }
  613. ~iterator() = default;
  614. iterator& operator=(const iterator& other)
  615. {
  616. if (this != &other) {
  617. this->Iterator = other.Iterator;
  618. this->Path = other.Path;
  619. this->PathElement = *this->Iterator;
  620. }
  621. return *this;
  622. }
  623. reference operator*() const { return this->PathElement; }
  624. pointer operator->() const { return &this->PathElement; }
  625. iterator& operator++()
  626. {
  627. ++this->Iterator;
  628. this->PathElement = *this->Iterator;
  629. return *this;
  630. }
  631. iterator operator++(int)
  632. {
  633. iterator it(*this);
  634. this->operator++();
  635. return it;
  636. }
  637. iterator& operator--()
  638. {
  639. --this->Iterator;
  640. this->PathElement = *this->Iterator;
  641. return *this;
  642. }
  643. iterator operator--(int)
  644. {
  645. iterator it(*this);
  646. this->operator--();
  647. return it;
  648. }
  649. private:
  650. friend class cmCMakePath;
  651. friend bool operator==(const iterator&, const iterator&);
  652. iterator(const cmCMakePath* path, const cm::filesystem::path::iterator& it)
  653. : Iterator(it)
  654. , Path(path)
  655. , PathElement(*this->Iterator)
  656. {
  657. }
  658. cm::filesystem::path::iterator Iterator;
  659. const cmCMakePath* Path = nullptr;
  660. cmCMakePath PathElement;
  661. };
  662. inline cmCMakePath::iterator cmCMakePath::begin() const
  663. {
  664. return iterator(this, this->Path.begin());
  665. }
  666. inline cmCMakePath::iterator cmCMakePath::end() const
  667. {
  668. return iterator(this, this->Path.end());
  669. }
  670. // Non-member functions
  671. // ====================
  672. inline bool operator==(const cmCMakePath::iterator& lhs,
  673. const cmCMakePath::iterator& rhs)
  674. {
  675. return lhs.Path == rhs.Path && lhs.Path && lhs.Iterator == rhs.Iterator;
  676. }
  677. inline bool operator!=(const cmCMakePath::iterator& lhs,
  678. const cmCMakePath::iterator& rhs)
  679. {
  680. return !(lhs == rhs);
  681. }
  682. inline void swap(cmCMakePath& lhs, cmCMakePath& rhs) noexcept
  683. {
  684. lhs.swap(rhs);
  685. }
  686. inline std::size_t hash_value(const cmCMakePath& path) noexcept
  687. {
  688. return cm::filesystem::hash_value(path.Path);
  689. }