Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
FileFinder.hpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#ifndef FILEFINDER_HPP_
37#define FILEFINDER_HPP_
38
39#include <string>
40#include <vector>
41#include <filesystem>
42namespace fs = std::filesystem;
43
64
71{
72public:
80 FileFinder();
81
88 FileFinder(const std::string& rPath, RelativeTo::Value relativeTo);
89
99 FileFinder(const std::string& rLeafName, const FileFinder& rParentOrSibling);
100
110 FileFinder(const fs::path& rPath);
111
115 virtual ~FileFinder();
116
123 virtual void SetPath(const std::string& rPath, RelativeTo::Value relativeTo);
124
131 virtual void SetPath(const std::string& rLeafName, const FileFinder& rParentOrSibling);
132
136 bool IsPathSet() const;
137
141 bool Exists() const;
142
146 bool IsFile() const;
147
151 bool IsDir() const;
152
158 bool IsEmpty() const;
159
166 std::string GetAbsolutePath() const;
167
174 bool IsNewerThan(const FileFinder& rOtherEntity) const;
175
181 std::string GetLeafName() const;
182
188 std::string GetLeafNameNoExtension() const;
189
194 std::string GetExtension() const;
195
199 FileFinder GetParent() const;
200
206 std::string GetRelativePath(const FileFinder& rBasePath) const;
207
220 FileFinder CopyTo(const FileFinder& rDest) const;
221
234 void Remove() const;
235
247 void DangerousRemove() const;
248
260 std::vector<FileFinder> FindMatches(const std::string& rPattern) const;
261
267 static bool IsAbsolutePath(const std::string& rPath);
268
274 static void ReplaceSpacesWithUnderscores(std::string& rPath);
275
281 static void ReplaceUnderscoresWithSpaces(std::string& rPath);
282
289 static void FakePath(RelativeTo::Value fakeWhat, const std::string& rFakePath);
290
294 static void StopFaking();
295
302 bool operator<(const FileFinder& otherFinder) const;
303
304private:
306 std::string mAbsPath;
307
309 static bool msFaking;
310
313
315 static std::string msFakePath;
316
325 void PrivateRemove(bool dangerous = false) const;
326};
327
328#endif /*FILEFINDER_HPP_*/
void Remove() const
std::string GetLeafNameNoExtension() const
std::string mAbsPath
std::string GetRelativePath(const FileFinder &rBasePath) const
bool IsEmpty() const
bool IsNewerThan(const FileFinder &rOtherEntity) const
static void ReplaceSpacesWithUnderscores(std::string &rPath)
std::string GetAbsolutePath() const
static bool IsAbsolutePath(const std::string &rPath)
static bool msFaking
void PrivateRemove(bool dangerous=false) const
void DangerousRemove() const
std::string GetExtension() const
std::vector< FileFinder > FindMatches(const std::string &rPattern) const
FileFinder GetParent() const
static void FakePath(RelativeTo::Value fakeWhat, const std::string &rFakePath)
static RelativeTo::Value msFakeWhat
bool IsFile() const
static void ReplaceUnderscoresWithSpaces(std::string &rPath)
bool IsDir() const
bool operator<(const FileFinder &otherFinder) const
std::string GetLeafName() const
virtual void SetPath(const std::string &rPath, RelativeTo::Value relativeTo)
bool Exists() const
static std::string msFakePath
virtual ~FileFinder()
FileFinder CopyTo(const FileFinder &rDest) const
bool IsPathSet() const
static void StopFaking()