Doxygen
Loading...
Searching...
No Matches
Dir Class Referencefinal

Class representing a directory in the file system. More...

#include <src/dir.h>

Classes

struct  Private
 

Public Member Functions

 Dir ()
 
 Dir (const std::string &path)
 
 Dir (const Dir &d)
 
Diroperator= (const Dir &d)
 
 Dir (Dir &&d)
 
Diroperator= (Dir &&d)
 
 ~Dir ()
 
void setPath (const std::string &path)
 
std::string path () const
 
DirIterator iterator () const
 
bool isEmpty (const std::string subdir) const
 
bool exists () const
 
std::string filePath (const std::string &path, bool acceptsAbsPath=true) const
 
bool exists (const std::string &path, bool acceptsAbsPath=true) const
 
bool mkdir (const std::string &path, bool acceptsAbsPath=true) const
 
bool rmdir (const std::string &path, bool acceptsAbsPath=true) const
 
bool remove (const std::string &path, bool acceptsAbsPath=true) const
 
bool rename (const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
 
bool copy (const std::string &src, const std::string &dest, bool acceptsAbsPath=true) const
 
std::string absPath () const
 
bool isRelative () const
 

Static Public Member Functions

static bool isRelativePath (const std::string &path)
 
static std::string currentDirPath ()
 
static bool setCurrent (const std::string &path)
 
static std::string cleanDirPath (const std::string &path)
 

Private Attributes

std::unique_ptr< Privatep
 

Detailed Description

Class representing a directory in the file system.

Definition at line 74 of file dir.h.

Constructor & Destructor Documentation

◆ Dir() [1/4]

Dir::Dir ( )

Definition at line 189 of file dir.cpp.

189 : p(std::make_unique<Private>())
190{
191 std::error_code ec;
192 p->path = fs::current_path(ec);
193}
std::unique_ptr< Private > p
Definition dir.h:110

References p.

Referenced by Dir(), Dir(), operator=(), and operator=().

◆ Dir() [2/4]

Dir::Dir ( const std::string & path)

Definition at line 220 of file dir.cpp.

220 : p(std::make_unique<Private>())
221{
222 setPath(path);
223}
void setPath(const std::string &path)
Definition dir.cpp:229
std::string path() const
Definition dir.cpp:234

References p, path(), and setPath().

◆ Dir() [3/4]

Dir::Dir ( const Dir & d)

Definition at line 195 of file dir.cpp.

195 : p(std::make_unique<Private>())
196{
197 p->path = d.p->path;
198}

References Dir(), and p.

◆ Dir() [4/4]

Dir::Dir ( Dir && d)

Definition at line 209 of file dir.cpp.

209 : p(std::make_unique<Private>())
210{
211 std::exchange(p->path,d.p->path);
212}

References Dir(), and p.

◆ ~Dir()

Dir::~Dir ( )

Definition at line 225 of file dir.cpp.

226{
227}

Member Function Documentation

◆ absPath()

std::string Dir::absPath ( ) const

Definition at line 363 of file dir.cpp.

364{
365 std::error_code ec;
366 std::string result = fs::absolute(p->path,ec).string();
367 correctPath(result);
368 return result;
369}
static void correctPath(std::string &s)
Definition dir.cpp:244

References correctPath(), and p.

Referenced by Htags::execute(), PerlModGenerator::generate(), FormulaManager::generateImages(), parseInput(), Htags::path2URL(), RTFGenerator::preProcessFileInplace(), writeDotGraphFromFile(), and writeDotImageMapFromFile().

◆ cleanDirPath()

std::string Dir::cleanDirPath ( const std::string & path)
static

Definition at line 355 of file dir.cpp.

356{
357 std::error_code ec;
358 std::string result = fs::path(path).lexically_normal().string();
359 correctPath(result);
360 return result;
361}

References correctPath(), and path().

Referenced by findFileDef(), and resolveSymlink().

◆ copy()

bool Dir::copy ( const std::string & src,
const std::string & dest,
bool acceptsAbsPath = true ) const

Definition at line 330 of file dir.cpp.

331{
332 const auto copyOptions = fs::copy_options::overwrite_existing;
333 std::error_code ec;
334 std::string sn = filePath(srcName,acceptsAbsPath);
335 std::string dn = filePath(dstName,acceptsAbsPath);
336 fs::copy(sn,dn,copyOptions,ec);
337 return !ec;
338}
std::string filePath(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:280

References filePath().

◆ currentDirPath()

std::string Dir::currentDirPath ( )
static

Definition at line 340 of file dir.cpp.

341{
342 std::error_code ec;
343 std::string result = fs::current_path(ec).string();
344 correctPath(result);
345 return result;
346}

References correctPath().

Referenced by Config::checkAndCorrect(), Htags::execute(), FormulaManager::generateImages(), generateOutput(), CitationManager::generatePage(), parseInput(), RTFGenerator::preProcessFileInplace(), runHtmlHelpCompiler(), runQHelpGenerator(), setPerlModDoxyfile(), Portable::setShortDir(), and writeDiaGraphFromFile().

◆ exists() [1/2]

◆ exists() [2/2]

bool Dir::exists ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 249 of file dir.cpp.

250{
251 std::string result = filePath(path,acceptsAbsPath);
252 std::error_code ec;
253 bool exist = fs::exists(fs::path(result),ec);
254 return !ec && exist;
255}

References filePath(), and path().

◆ filePath()

std::string Dir::filePath ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 280 of file dir.cpp.

281{
282 std::string result;
283 if (acceptsAbsPath && !isRelativePath(path))
284 {
285 result = path;
286 }
287 else
288 {
289 result = (p->path / path).string();
290 }
291 correctPath(result);
292 return result;
293}
static bool isRelativePath(const std::string &path)
Definition dir.cpp:275

References correctPath(), isRelativePath(), p, and path().

Referenced by copy(), exists(), mkdir(), preProcessFile(), RTFGenerator::preProcessFileInplace(), remove(), and rename().

◆ isEmpty()

bool Dir::isEmpty ( const std::string subdir) const

Definition at line 263 of file dir.cpp.

264{
265 fs::path pth = path();
266 pth /= subdir;
267 return fs::is_empty(pth);
268}

References path().

Referenced by clearSubDirs().

◆ isRelative()

bool Dir::isRelative ( ) const

Definition at line 270 of file dir.cpp.

271{
272 return isRelativePath(p->path.string());
273}

References isRelativePath(), and p.

◆ isRelativePath()

bool Dir::isRelativePath ( const std::string & path)
static

Definition at line 275 of file dir.cpp.

276{
277 return fs::path(path).is_relative();
278}

References path().

Referenced by filePath(), and isRelative().

◆ iterator()

DirIterator Dir::iterator ( ) const

Definition at line 239 of file dir.cpp.

240{
241 return DirIterator(p->path.string());
242}

References p.

Referenced by readDir().

◆ mkdir()

bool Dir::mkdir ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 295 of file dir.cpp.

296{
297 std::error_code ec;
298 std::string result = filePath(path,acceptsAbsPath);
299 if (exists(path,acceptsAbsPath))
300 {
301 return true;
302 }
303 else
304 {
305 return fs::create_directory(result,ec);
306 }
307}
bool exists() const
Definition dir.cpp:257

References exists(), filePath(), and path().

Referenced by PerlModGenerator::createOutputDir(), createOutputDirectory(), createSubDirs(), generateDEF(), generateOutput(), CitationManager::generatePage(), DocbookGenerator::init(), HtmlGenerator::init(), LatexGenerator::init(), ManGenerator::init(), RTFGenerator::init(), initWarningFormat(), and parseInput().

◆ operator=() [1/2]

Dir & Dir::operator= ( const Dir & d)

Definition at line 200 of file dir.cpp.

201{
202 if (&d!=this)
203 {
204 p->path = d.p->path;
205 }
206 return *this;
207}

References Dir(), and p.

◆ operator=() [2/2]

Dir & Dir::operator= ( Dir && d)

Definition at line 214 of file dir.cpp.

215{
216 std::exchange(p->path,d.p->path);
217 return *this;
218}

References Dir(), and p.

◆ path()

std::string Dir::path ( ) const

Definition at line 234 of file dir.cpp.

235{
236 return p->path.string();
237}

References p.

Referenced by cleanDirPath(), Dir(), exists(), filePath(), isEmpty(), isRelativePath(), mkdir(), remove(), rmdir(), setCurrent(), and setPath().

◆ remove()

bool Dir::remove ( const std::string & path,
bool acceptsAbsPath = true ) const

◆ rename()

bool Dir::rename ( const std::string & orgName,
const std::string & newName,
bool acceptsAbsPath = true ) const

Definition at line 321 of file dir.cpp.

322{
323 std::error_code ec;
324 std::string fn1 = filePath(orgName,acceptsAbsPath);
325 std::string fn2 = filePath(newName,acceptsAbsPath);
326 fs::rename(fn1,fn2,ec);
327 return !ec;
328}

References filePath().

Referenced by openOutputFile(), RTFGenerator::preProcessFileInplace(), resetPDFSize(), and DotFilePatcher::run().

◆ rmdir()

bool Dir::rmdir ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 309 of file dir.cpp.

310{
311 return remove(path,acceptsAbsPath);
312}
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:314

References path(), and remove().

Referenced by clearSubDirs(), and CitationManager::generatePage().

◆ setCurrent()

bool Dir::setCurrent ( const std::string & path)
static

Definition at line 348 of file dir.cpp.

349{
350 std::error_code ec;
351 fs::current_path(path,ec);
352 return !ec;
353}

References path().

Referenced by Htags::execute(), FormulaManager::generateImages(), CitationManager::generatePage(), RTFGenerator::preProcessFileInplace(), runHtmlHelpCompiler(), runQHelpGenerator(), Portable::setShortDir(), and writeDiaGraphFromFile().

◆ setPath()

void Dir::setPath ( const std::string & path)

Definition at line 229 of file dir.cpp.

230{
231 p->path = path;
232}

References p, and path().

Referenced by PerlModGenerator::createOutputDir(), Dir(), Htags::execute(), and parseInput().

Member Data Documentation

◆ p

std::unique_ptr<Private> Dir::p
private

The documentation for this class was generated from the following files: