lfilesystem  0.0.1
C++ filesystem library
lfilesystem_Volume.h
Go to the documentation of this file.
1 /*
2  * ======================================================================================
3  * __ ____ __ __ ____ ___
4  * ( ) (_ _)( \/ )( ___)/ __)
5  * )(__ _)(_ ) ( )__) \__ \
6  * (____)(____)(_/\/\_)(____)(___/
7  *
8  * This file is part of the Limes open source library and is licensed under the terms of the GNU Public License.
9  *
10  * Commercial licenses are available; contact the maintainers at ben.the.vining@gmail.com to inquire for details.
11  *
12  * ======================================================================================
13  */
14 
15 #pragma once
16 
17 #include <string>
18 #include <cstdint>
19 #include <filesystem>
20 #include <vector>
21 #include <optional>
22 #include <ostream>
23 #include "lfilesystem/lfilesystem_Export.h"
25 
32 namespace limes::files
33 {
34 
35 using Path = std::filesystem::path;
36 
37 class FilesystemEntry;
38 
58 class LFILE_EXPORT Volume final
59 {
60 public:
68  explicit Volume (const Path& path = dirs::cwd().getAbsolutePath());
69 
73  [[nodiscard]] static std::optional<Volume> tryCreate (const Path& path = dirs::cwd().getAbsolutePath()) noexcept;
74 
79  bool operator== (const Volume& other) const noexcept;
80 
82  bool operator!= (const Volume& other) const noexcept;
84 
89  [[nodiscard]] bool contains (const FilesystemEntry& file) const noexcept;
90 
98  [[nodiscard]] std::string getLabel() const;
99 
110  [[nodiscard]] int getSerialNumber() const;
111 
116  [[nodiscard]] std::uintmax_t bytesFree() const;
117 
122  [[nodiscard]] std::uintmax_t totalBytes() const;
123 
128  [[nodiscard]] Path getPath() const noexcept;
129 
131  enum class Type
132  {
133  CDRom,
134  HardDisk,
135  Removable,
136  Network,
137  RAM,
138  Unknown
139  };
140 
149  [[nodiscard]] Type getType() const;
150 
155  [[nodiscard]] bool isReadOnly() const;
156 
161  [[nodiscard]] bool isCaseSensitive() const;
162 
166  [[nodiscard]] static std::vector<Volume> getAll() noexcept;
167 
168 private:
169  Path rootPath;
170 };
171 
177 std::ostream& operator<< (std::ostream& os, const Volume& value);
178 
187 namespace volume
188 {
189 
194 [[nodiscard]] LFILE_EXPORT std::string label();
195 
200 [[nodiscard]] LFILE_EXPORT int serialNumber();
201 
206 [[nodiscard]] LFILE_EXPORT std::uintmax_t bytesFree();
207 
212 [[nodiscard]] LFILE_EXPORT std::uintmax_t totalBytes();
213 
218 [[nodiscard]] LFILE_EXPORT Volume::Type type();
219 
224 [[nodiscard]] LFILE_EXPORT bool readOnly();
225 
230 [[nodiscard]] LFILE_EXPORT bool caseSensitive();
231 
232 } // namespace volume
233 
234 } // namespace files
The base class for any kind of object on the filesystem.
This class represents a logical filesystem volume.
Type
Represents the type of a filesystem volume.
static std::vector< Volume > getAll() noexcept
Returns all currently mounted volumes.
Volume(const Path &path=dirs::cwd().getAbsolutePath())
Creates a Volume object representing the volume that the passed path exists on.
Type getType() const
Returns the type of this volume.
bool isReadOnly() const
Returns true if this volume is read-only.
static std::optional< Volume > tryCreate(const Path &path=dirs::cwd().getAbsolutePath()) noexcept
A noexcept method for creating a volume object.
bool isCaseSensitive() const
Returns true if paths on this volume are case-sensitive.
std::filesystem::path Path
Convenience typedef for filesystem paths.
This file contains utility functions for finding some common directories.
LFILE_EXPORT bool caseSensitive()
Returns true if the current volume is case-sensitive.
LFILE_EXPORT Volume::Type type()
Returns the type of the current volume.
LFILE_EXPORT int serialNumber()
Returns the current volume's serial number.
LFILE_EXPORT std::uintmax_t totalBytes()
Returns the total number of bytes on the current volume.
LFILE_EXPORT bool readOnly()
Returns true if the current volume is mounted as read-only.
LFILE_EXPORT std::uintmax_t bytesFree()
Returns the number of bytes free on the current volume.
LFILE_EXPORT std::string label()
Returns the current volume's label.
Filesystem utilities.