Doxygen
Loading...
Searching...
No Matches
FileInfo Class Reference

Minimal replacement for QFileInfo. More...

#include <src/fileinfo.h>

Public Member Functions

 FileInfo (const std::string &name)
 
bool exists () const
 
size_t size () const
 
bool isWritable () const
 
bool isReadable () const
 
bool isExecutable () const
 
bool isRelative () const
 
bool isFile () const
 
bool isDir () const
 
bool isSymLink () const
 
std::string readLink () const
 
std::string filePath () const
 
std::string absFilePath () const
 
std::string fileName () const
 
std::string baseName () const
 
std::string extension (bool complete) const
 
std::string dirPath (bool absPath=true) const
 

Static Private Member Functions

static void correctPath (std::string &s)
 

Private Attributes

std::string m_name
 

Detailed Description

Minimal replacement for QFileInfo.

Definition at line 22 of file fileinfo.h.

Constructor & Destructor Documentation

◆ FileInfo()

FileInfo::FileInfo ( const std::string & name)
inlineexplicit

Definition at line 25 of file fileinfo.h.

25: m_name(name) {}
std::string m_name
Definition fileinfo.h:44

References m_name.

Member Function Documentation

◆ absFilePath()

std::string FileInfo::absFilePath ( ) const

Definition at line 101 of file fileinfo.cpp.

102{
103 std::string result;
104 std::error_code ec;
105 fs::path path(m_name);
106 if (!path.is_relative())
107 {
108 result = path.lexically_normal().string();
109 }
110 else
111 {
112 result = (fs::current_path(ec) / m_name).lexically_normal().string();
113 }
114 correctPath(result);
115 return result;
116}
static void correctPath(std::string &s)
Definition fileinfo.cpp:96

References correctPath(), and m_name.

Referenced by Preprocessor::addSearchDir(), checkAndOpenFile(), checkMarkdownMainfile(), cleanUpPaths(), determineAbsoluteIncludeName(), dirPath(), findFilePath(), FormulaManager::generateImages(), genericPatternMatch(), getConvertLatexMacro(), markdownFileNameToId(), openDbConnection(), parseFile(), MarkdownOutlineParser::parseInput(), preProcessFile(), RTFGenerator::preProcessFileInplace(), Markdown::Private::processLink(), readConfiguration(), readDir(), readFileOrDirectory(), readTagFile(), resolveLink(), setFileName(), substituteLatexKeywords(), and ClassDefImpl::writeIncludeFilesForSlice().

◆ baseName()

std::string FileInfo::baseName ( ) const

Definition at line 123 of file fileinfo.cpp.

124{
125 std::string s = fileName();
126 size_t pos = s.find('.');
127 return pos!=std::string::npos ? s.substr(0,pos) : s;
128}
std::string fileName() const
Definition fileinfo.cpp:118

References fileName().

Referenced by parseMain().

◆ correctPath()

void FileInfo::correctPath ( std::string & s)
staticprivate

Definition at line 96 of file fileinfo.cpp.

97{
98 std::replace( s.begin(), s.end(), '\\', '/' );
99}

Referenced by absFilePath(), and dirPath().

◆ dirPath()

std::string FileInfo::dirPath ( bool absPath = true) const

Definition at line 137 of file fileinfo.cpp.

138{
139 std::string result;
140 if (absPath)
141 {
142 result = absFilePath();
143 }
144 else
145 {
146 result = m_name;
147 correctPath(result);
148 }
149 size_t pos = result.rfind('/');
150 if (pos==std::string::npos)
151 {
152 return ".";
153 }
154 else if (pos==0)
155 {
156 return "/";
157 }
158 else
159 {
160 return result.substr(0,pos);
161 }
162}
std::string absFilePath() const
Definition fileinfo.cpp:101

References absFilePath(), correctPath(), and m_name.

Referenced by Config::checkAndCorrect(), determineAbsoluteIncludeName(), findFile(), findPackageScope(), initWarningFormat(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), ManDocVisitor::operator()(), ManDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), CodeFragmentManager::parseCodeFragment(), readDir(), and readFileOrDirectory().

◆ exists()

◆ extension()

std::string FileInfo::extension ( bool complete) const

Definition at line 130 of file fileinfo.cpp.

131{
132 std::string fn = fileName();
133 size_t pos = complete ? fn.find('.') : fn.rfind('.');
134 return pos!=std::string::npos ? fn.substr(pos+1) : std::string();
135}

References fileName().

Referenced by getLanguageFromFileName().

◆ fileName()

◆ filePath()

std::string FileInfo::filePath ( ) const

Definition at line 91 of file fileinfo.cpp.

92{
93 return m_name;
94}

References m_name.

Referenced by genericPatternMatch(), and openOutputFile().

◆ isDir()

bool FileInfo::isDir ( ) const

Definition at line 70 of file fileinfo.cpp.

71{
72 std::error_code ec;
73 fs::file_status status = fs::status(m_name,ec);
74 return !ec && fs::is_directory(std::move(status));
75}

References m_name.

Referenced by Preprocessor::addSearchDir(), Config::checkAndCorrect(), cleanUpPaths(), copyExtraFiles(), copyIcon(), copyLatexStyleSheet(), copyLogo(), copyStyleSheet(), determineAbsoluteIncludeName(), Dir::exists(), readDir(), readFileOrDirectory(), and resolveSymlink().

◆ isExecutable()

bool FileInfo::isExecutable ( ) const

Definition at line 51 of file fileinfo.cpp.

52{
53 std::error_code ec;
54 fs::file_status status = fs::status(m_name,ec);
55 return !ec && (status.permissions() & fs::perms::owner_exec)!=fs::perms::none;
56}

References m_name.

◆ isFile()

bool FileInfo::isFile ( ) const

Definition at line 63 of file fileinfo.cpp.

64{
65 std::error_code ec;
66 fs::file_status status = fs::status(m_name,ec);
67 return !ec && fs::is_regular_file(std::move(status));
68}

References m_name.

Referenced by Config::checkAndCorrect(), checkAndOpenFile(), computeVerifiedDotPath(), fileToString(), parseInput(), readDir(), readFileOrDirectory(), readIncludeFile(), readTagFile(), runPlantumlContent(), tryPath(), and HtmlGenerator::writeStyleInfo().

◆ isReadable()

bool FileInfo::isReadable ( ) const

Definition at line 44 of file fileinfo.cpp.

45{
46 std::error_code ec;
47 fs::file_status status = fs::status(m_name,ec);
48 return !ec && (status.permissions() & fs::perms::owner_read)!=fs::perms::none;
49}

References m_name.

Referenced by Htags::loadFilemap(), Markdown::Private::processLink(), readDir(), readFileOrDirectory(), and HtmlGenerator::writeStyleInfo().

◆ isRelative()

bool FileInfo::isRelative ( ) const

Definition at line 58 of file fileinfo.cpp.

59{
60 return fs::path(m_name).is_relative();
61}

References m_name.

Referenced by resolveSymlink().

◆ isSymLink()

bool FileInfo::isSymLink ( ) const

Definition at line 77 of file fileinfo.cpp.

78{
79 std::error_code ec;
80 fs::file_status status = fs::symlink_status(m_name,ec);
81 return !ec && fs::is_symlink(std::move(status));
82}

References m_name.

Referenced by DocParser::findAndCopyImage(), readDir(), readFileOrDirectory(), and resolveSymlink().

◆ isWritable()

bool FileInfo::isWritable ( ) const

Definition at line 37 of file fileinfo.cpp.

38{
39 std::error_code ec;
40 fs::file_status status = fs::status(m_name,ec);
41 return !ec && (status.permissions() & fs::perms::owner_write)!=fs::perms::none;
42}

References m_name.

◆ readLink()

std::string FileInfo::readLink ( ) const

Definition at line 84 of file fileinfo.cpp.

85{
86 std::error_code ec;
87 fs::path targetPath = fs::read_symlink(fs::path(m_name));
88 return !ec ? targetPath.string() : std::string();
89}

References m_name.

Referenced by resolveSymlink().

◆ size()

size_t FileInfo::size ( ) const

Definition at line 23 of file fileinfo.cpp.

24{
25 std::error_code ec;
26 size_t result = static_cast<size_t>(fs::file_size(fs::path(m_name),ec));
27 return ec ? 0 : result;
28}

References m_name.

Referenced by deliverablesPresent(), insertMapFile(), and readInputFile().

Member Data Documentation

◆ m_name

std::string FileInfo::m_name
private

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