API Documentation
Loading...
Searching...
No Matches
File.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: File
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/String.h>
35#include <NDEVR/Time.h>
36#include <NDEVR/FileCachedData.h>
37namespace NDEVR
38{
39 class ProgressInfo;
40 class Time;
41 class UUID;
42
43 /**----------------------------------------------------------------------------
44 \brief Logic for reading or writing to a file as well as navigating filesystems
45 or other common file operations.
46 ----------------------------------------------------------------------------*/
47 class File : public String
48 {
49 public:
72 public:
74 NDEVR_BASE_API File(const File& file);
75 NDEVR_BASE_API File(const String& resource_name, const String& path_id);
76 NDEVR_BASE_API File(File&& file) noexcept;
77 NDEVR_BASE_API File(const String& full_path);
79 NDEVR_BASE_API File(const char* full_path);
81
82 NDEVR_BASE_API bool copyTo(const File& cs, bool override_file, ProgressInfo* log = nullptr) const;
83 NDEVR_BASE_API bool moveTo(File& file, bool override_file, ProgressInfo* log = nullptr, bool is_source_temp = false);
85 [[nodiscard]] NDEVR_BASE_API String getPath(uint01 file_parts) const;
86 NDEVR_BASE_API void setPath(const String& path, uint01 part);
88 [[nodiscard]] NDEVR_BASE_API bool exists() const;
89 [[nodiscard]] NDEVR_BASE_API bool cachedExist() const;
90 [[nodiscard]] NDEVR_BASE_API bool parentDirectoryExists() const;
91 [[nodiscard]] NDEVR_BASE_API bool isDirectory() const;
92 [[nodiscard]] NDEVR_BASE_API bool isDrive() const;
93 [[nodiscard]] NDEVR_BASE_API bool isHidden() const;
94 [[nodiscard]] NDEVR_BASE_API bool isOpen() const;
95
97 [[nodiscard]] NDEVR_BASE_API String getFolderName() const;
99
100 [[nodiscard]] NDEVR_BASE_API Time getModifiedTime() const;
101 [[nodiscard]] NDEVR_BASE_API Time getCreationTime() const;
102 [[nodiscard]] NDEVR_BASE_API Time getAccessTime() const;
103 NDEVR_BASE_API void getFileTimes(Time& modified_time, Time& creation_time, Time& access_time) const;
105 NDEVR_BASE_API bool updateAccessedTime(Time access_time) const;
106
108 NDEVR_BASE_API File& append(const char& s);
113 [[nodiscard]] NDEVR_BASE_API Buffer<File, uint04, ObjectAllocator<false>> getChildrenMatching(const Buffer<String>& include_patterns, const Buffer<String>& exclude_patterns, bool recursive = false) const;
114 [[nodiscard]] NDEVR_BASE_API FILE* filePtr();
115 NDEVR_BASE_API FILE* open(OpenMode mode, bool append = false);
116 NDEVR_BASE_API String relativePathTo(const File& reference) const;
120
121
122 NDEVR_BASE_API void create(bool override_file) const;
124
126
127 [[nodiscard]] NDEVR_BASE_API uint08 fileSize() const;
128
129 [[nodiscard]] NDEVR_BASE_API UUID getUUID() const;
130
132
133 NDEVR_BASE_API bool operator<<(const String& value);
135 NDEVR_BASE_API bool operator<<(const fltp04& value);
136 NDEVR_BASE_API bool operator<<(const fltp08& value);
137
139 NDEVR_BASE_API File& operator=(File&& value) noexcept;
140
142 [[nodiscard]] NDEVR_BASE_API static File TempFileFolder();
143 [[nodiscard]] NDEVR_BASE_API File generateTempFile() const;
144
145 const String& pathID() const { return m_id; }
147 NDEVR_BASE_API bool isMTP() const;
155 NDEVR_BASE_API void setFromDisplayString(const String& display_string);
156 public:
159 NDEVR_BASE_API static bool doesFileExist(const String& name);
160 NDEVR_BASE_API static bool typeSort(const File& i, const File& j);
161 NDEVR_BASE_API static bool nameSort(const File& i, const File& j);
162 NDEVR_BASE_API static bool accessSort(const File& i, const File& j);
163 NDEVR_BASE_API static bool createSort(const File& i, const File& j);
164 NDEVR_BASE_API static bool isPathSep(const char& path);
165 NDEVR_BASE_API static bool isIDSep(const char& path);
166 size_t operator()() const
167 {
168 return static_cast<size_t>(hash());
169 }
170 public:
171#ifdef _WIN32
172 static constexpr char PathSep = '\\';
173#else
174 static constexpr char PathSep = '/';
175#endif
176 static constexpr char ExtSep = '.';
177 static constexpr char DriveSep = ':';
178 static constexpr char IDSep = '|';
179
181 private:
182 void checkError(uint04 error) const;
183 protected:
185 mutable String m_id;
191 mutable bool m_id_valid;
192 };
193 /**----------------------------------------------------------------------------
194 \brief Logic for searching for files based on some criteria
195 ----------------------------------------------------------------------------*/
197 {
198 public:
202 uint04 max_recursion_level = Constant<uint04>::Max;
204 protected:
205 void performSearch(const File& current_file, Buffer<File>& files, uint04 recursion_level) const;
206 };
207}
208
209namespace std//Define things to allow use within std libs
210{
211 template <>
212 struct hash<NDEVR::File>
213 {
214 std::size_t operator()(const NDEVR::File& s) const noexcept
215 {
216 return static_cast<size_t>(s.hash());
217 }
218 };
219 NDEVR_BASE_API istream& operator>>(istream& in, NDEVR::String& string);
220};
221
#define NDEVR_BASE_API
Definition DLLInfo.h:78
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:59
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
const String & pathID() const
Definition File.h:145
NDEVR_BASE_API File & append(const char &s)
static NDEVR_BASE_API bool accessSort(const File &i, const File &j)
NDEVR_BASE_API void setInternalVars()
NDEVR_BASE_API uint08 fileSize() const
NDEVR_BASE_API FILE * filePtr()
NDEVR_BASE_API File findNonExistingSuitableName() const
NDEVR_BASE_API bool moveTo(File &file, bool override_file, ProgressInfo *log=nullptr, bool is_source_temp=false)
OpenMode m_open_mode
Definition File.h:187
String pathNameID() const
uint01 m_path_start
Definition File.h:188
NDEVR_BASE_API bool resolveNameFromMTPPath()
NDEVR_BASE_API File & operator=(const File &value)
NDEVR_BASE_API bool updateAccessedTime(Time access_time) const
NDEVR_BASE_API bool hasNullBytes(uint08 max_length=Constant< uint08 >::Max)
String m_id
Definition File.h:185
NDEVR_BASE_API bool parentDirectoryExists() const
static NDEVR_BASE_API File TempFileFolder()
NDEVR_BASE_API bool isDrive() const
NDEVR_BASE_API bool cachedExist() const
NDEVR_BASE_API File(const char *full_path)
NDEVR_BASE_API void deleteFile(ProgressInfo *log=nullptr)
static NDEVR_BASE_API Buffer< File, uint04, ObjectAllocator< false > > MTPDevices()
FileCachedData m_cached_data
Definition File.h:184
NDEVR_BASE_API bool exists() const
NDEVR_BASE_API void throwIfNotExist() const
NDEVR_BASE_API bool resolveMTPPath() const
size_t operator()() const
Definition File.h:166
NDEVR_BASE_API void create(bool override_file) const
NDEVR_BASE_API void getFileTimes(Time &modified_time, Time &creation_time, Time &access_time) const
NDEVR_BASE_API String getPath(uint01 file_parts) const
static NDEVR_BASE_API bool typeSort(const File &i, const File &j)
NDEVR_BASE_API File(File &&file) noexcept
NDEVR_BASE_API void updateCache(const FileCachedData &cache)
NDEVR_BASE_API void invalidateCache()
NDEVR_BASE_API File getParentDirectory() const
FILE * m_file_ptr
Definition File.h:186
static NDEVR_BASE_API bool doesFileExist(const String &name)
NDEVR_BASE_API String relativePathTo(const File &reference) const
NDEVR_BASE_API File & appendPath(const String &cs)
NDEVR_BASE_API void expandEnvironmentalVars()
NDEVR_BASE_API Time getAccessTime() const
uint01 m_file_ext_start
Definition File.h:190
NDEVR_BASE_API File()
static constexpr char PathSep
Definition File.h:172
static NDEVR_BASE_API bool isPathSep(const char &path)
NDEVR_BASE_API void setPath(const String &path, uint01 part)
NDEVR_BASE_API void updateCache() const
static NDEVR_BASE_API Buffer< File, uint04, ObjectAllocator< false > > SystemDrives()
NDEVR_BASE_API void setFromDisplayString(const String &display_string)
NDEVR_BASE_API const FileCachedData & currentCache() const
static constexpr char IDSep
Definition File.h:178
NDEVR_BASE_API File(const File &file)
NDEVR_BASE_API File & operator=(String &value)
FilePart
Definition File.h:64
@ e_drive
Definition File.h:65
@ e_file_name
Definition File.h:67
@ e_full_path
Definition File.h:69
@ e_file_extension
Definition File.h:68
@ e_dir_path
Definition File.h:66
@ e_folder_name
Definition File.h:70
NDEVR_BASE_API Buffer< File, uint04, ObjectAllocator< false > > getChildren() const
NDEVR_BASE_API bool isDirectory() const
static NDEVR_BASE_API bool isIDSep(const char &path)
NDEVR_BASE_API File & operator=(File &&value) noexcept
static constexpr char ExtSep
Definition File.h:176
NDEVR_BASE_API FILE * open(OpenMode mode, bool append=false)
NDEVR_BASE_API bool operator<<(const fltp04 &value)
NDEVR_BASE_API Time getModifiedTime() const
NDEVR_BASE_API bool operator<<(const String &value)
NDEVR_BASE_API File & append(const String &s)
NDEVR_BASE_API File generateTempFile() const
NDEVR_BASE_API bool isOpen() const
NDEVR_BASE_API ~File()
NDEVR_BASE_API Buffer< File, uint04, ObjectAllocator< false > > getChildrenMatching(const Buffer< String > &include_patterns, const Buffer< String > &exclude_patterns, bool recursive=false) const
OpenMode
Definition File.h:51
@ e_ascii_read
Definition File.h:54
@ e_ascii_write_safe
Definition File.h:58
@ e_binary_read_safe
Definition File.h:57
@ e_ascii_write
Definition File.h:55
@ e_binary_read
Definition File.h:52
@ e_ascii_read_shared
Definition File.h:60
@ e_ascii_read_safe
Definition File.h:56
@ e_binary_write
Definition File.h:53
@ e_undefined
Definition File.h:61
@ e_binary_write_safe
Definition File.h:59
NDEVR_BASE_API Buffer< uint01 > getData()
NDEVR_BASE_API void close()
NDEVR_BASE_API bool operator<<(const Buffer< uint01 > &values)
NDEVR_BASE_API String getDriveDescription() const
NDEVR_BASE_API bool isMTP() const
uint01 m_file_name_start
Definition File.h:189
NDEVR_BASE_API File(const String &resource_name, const String &path_id)
static constexpr char DriveSep
Definition File.h:177
NDEVR_BASE_API File(const String &full_path)
NDEVR_BASE_API File(String &&full_path)
NDEVR_BASE_API void removeInvalidChars()
NDEVR_BASE_API bool copyTo(const File &cs, bool override_file, ProgressInfo *log=nullptr) const
NDEVR_BASE_API String toDisplayString()
NDEVR_BASE_API bool isHidden() const
bool m_id_valid
Definition File.h:191
static NDEVR_BASE_API bool nameSort(const File &i, const File &j)
NDEVR_BASE_API UUID getUUID() const
NDEVR_BASE_API Time getCreationTime() const
NDEVR_BASE_API bool operator<<(const fltp08 &value)
NDEVR_BASE_API String getFolderName() const
NDEVR_BASE_API bool updateAccessedTime() const
static NDEVR_BASE_API bool createSort(const File &i, const File &j)
NDEVR_BASE_API void flush()
static NDEVR_BASE_API String PathSepS
Definition File.h:180
Logic for searching for files based on some criteria.
Definition File.h:197
Buffer< String > search_extensions
Definition File.h:200
Buffer< File > performSearch() const
Buffer< File > excluded_list
Definition File.h:201
Buffer< File > files_recursively_to_search
Definition File.h:199
void performSearch(const File &current_file, Buffer< File > &files, uint04 recursion_level) const
A light-weight base class for Log that allows processes to update, without the need for.
Definition ProgressInfo.hpp:48
The core String class for the software.
Definition String.h:47
NDEVR_BASE_API uint08 hash() const
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:62
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:125
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:78
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:104
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:94
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:146
Definition File.h:210
NDEVR_BASE_API istream & operator>>(istream &in, NDEVR::String &string)
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved.
Definition BaseValues.hpp:230
Data that is cached from a file into program memory to limit expensive.
Definition FileCache.h:22