CppCommon  1.0.4.1
C++ Common Library
symlink.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_FILESYSTEM_SYMLINK_H
10 #define CPPCOMMON_FILESYSTEM_SYMLINK_H
11 
12 #include "filesystem/path.h"
13 
14 namespace CppCommon {
15 
17 
23 class Symlink : public Path
24 {
25 public:
27  Symlink() : Path() {}
29 
32  Symlink(const Path& path) : Path(path) {}
33  Symlink(const Symlink&) = default;
34  Symlink(Symlink&&) = default;
35  ~Symlink() = default;
36 
37  Symlink& operator=(const Path& path)
38  { Assign(path); return *this; }
39  Symlink& operator=(const Symlink&) = default;
40  Symlink& operator=(Symlink&&) = default;
41 
43  explicit operator bool() const noexcept { return IsSymlinkExists() && IsTargetExists(); }
44 
46  Path target() const;
47 
49  bool IsSymlinkExists() const;
51  bool IsTargetExists() const
52  { return !target().empty(); }
53 
55 
60  static Symlink CreateSymlink(const Path& src, const Path& dst);
62 
67  static Path CreateHardlink(const Path& src, const Path& dst);
68 
70 
79  static Symlink CopySymlink(const Path& src, const Path& dst)
80  { return CreateSymlink((src.IsSymlink() ? Symlink(src).target() : src), dst); }
81 
83  void swap(Symlink& symlink) noexcept;
84  friend void swap(Symlink& symlink1, Symlink& symlink2) noexcept;
85 };
86 
89 } // namespace CppCommon
90 
91 #include "symlink.inl"
92 
93 #endif // CPPCOMMON_FILESYSTEM_SYMLINK_H
Filesystem path.
Definition: path.h:90
bool IsSymlink() const
Is the path points to symbolic link?
Definition: path.h:219
Path & Assign(const Path &path)
Assign the given path to the current one.
Definition: path.inl:20
bool empty() const noexcept
Is the path empty?
Definition: path.h:191
C++ Common project definitions.
Definition: token_bucket.h:15
Filesystem path definition.