logic: reduce access to filesystem while indexing
* use canonical filepath cache in cxx indexer * made constructors of FilePath explicit * use FilePath at more places instead of string * forward declares FilePath wherever possible
This commit is contained in:
@@ -14,11 +14,16 @@ public:
|
||||
private:
|
||||
std::function<ValType(KeyType)> m_calculator;
|
||||
std::unordered_map<KeyType, ValType, Hasher> m_map;
|
||||
|
||||
size_t m_hitCount;
|
||||
size_t m_missCount;
|
||||
};
|
||||
|
||||
template <typename KeyType, typename ValType, typename Hasher>
|
||||
Cache<KeyType, ValType, Hasher>::Cache(std::function<ValType(KeyType)> calculator)
|
||||
: m_calculator(calculator)
|
||||
, m_hitCount(0)
|
||||
, m_missCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -28,8 +33,10 @@ ValType Cache<KeyType, ValType, Hasher>::getValue(KeyType key)
|
||||
typename std::unordered_map<KeyType, ValType>::const_iterator it = m_map.find(key);
|
||||
if (it != m_map.end())
|
||||
{
|
||||
++m_hitCount;
|
||||
return it->second;
|
||||
}
|
||||
++m_missCount;
|
||||
ValType val = m_calculator(key);
|
||||
m_map[key] = val;
|
||||
return val;
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
|
||||
#include "AppPath.h"
|
||||
|
||||
std::string ResourcePaths::getColorSchemesPath()
|
||||
FilePath ResourcePaths::getColorSchemesPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/color_schemes/";
|
||||
return FilePath(AppPath::getAppPath() + "data/color_schemes/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getFallbackPath()
|
||||
FilePath ResourcePaths::getFallbackPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/fallback/";
|
||||
return FilePath(AppPath::getAppPath() + "data/fallback/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getFontsPath()
|
||||
FilePath ResourcePaths::getFontsPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/fonts/";
|
||||
return FilePath(AppPath::getAppPath() + "data/fonts/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getGuiPath()
|
||||
FilePath ResourcePaths::getGuiPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/gui/";
|
||||
return FilePath(AppPath::getAppPath() + "data/gui/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getJavaPath()
|
||||
FilePath ResourcePaths::getJavaPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/java/";
|
||||
return FilePath(AppPath::getAppPath() + "data/java/");
|
||||
}
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class ResourcePaths
|
||||
{
|
||||
public:
|
||||
static std::string getColorSchemesPath();
|
||||
static std::string getFallbackPath();
|
||||
static std::string getFontsPath();
|
||||
static std::string getGuiPath();
|
||||
static std::string getJavaPath();
|
||||
static FilePath getColorSchemesPath();
|
||||
static FilePath getFallbackPath();
|
||||
static FilePath getFontsPath();
|
||||
static FilePath getGuiPath();
|
||||
static FilePath getJavaPath();
|
||||
};
|
||||
|
||||
#endif // RESOURCE_PATHS_H
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "utility/UserPaths.h"
|
||||
|
||||
std::string UserPaths::s_userDataPath = "";
|
||||
std::string UserPaths::s_sampleProjectsPath = "";
|
||||
FilePath UserPaths::s_userDataPath;
|
||||
FilePath UserPaths::s_sampleProjectsPath;
|
||||
|
||||
std::string UserPaths::getUserDataPath()
|
||||
FilePath UserPaths::getUserDataPath()
|
||||
{
|
||||
return s_userDataPath;
|
||||
}
|
||||
|
||||
void UserPaths::setUserDataPath(const std::string& path)
|
||||
void UserPaths::setUserDataPath(const FilePath& path)
|
||||
{
|
||||
s_userDataPath = path;
|
||||
}
|
||||
|
||||
std::string UserPaths::getSampleProjectsPath()
|
||||
FilePath UserPaths::getSampleProjectsPath()
|
||||
{
|
||||
if (s_sampleProjectsPath.size())
|
||||
if (s_sampleProjectsPath.str().size())
|
||||
{
|
||||
return s_sampleProjectsPath;
|
||||
}
|
||||
@@ -23,22 +23,22 @@ std::string UserPaths::getSampleProjectsPath()
|
||||
return s_userDataPath;
|
||||
}
|
||||
|
||||
void UserPaths::setSampleProjectsPath(const std::string& path)
|
||||
void UserPaths::setSampleProjectsPath(const FilePath& path)
|
||||
{
|
||||
s_sampleProjectsPath = path;
|
||||
}
|
||||
|
||||
std::string UserPaths::getAppSettingsPath()
|
||||
FilePath UserPaths::getAppSettingsPath()
|
||||
{
|
||||
return getUserDataPath() + "ApplicationSettings.xml";
|
||||
return getUserDataPath().concat(FilePath("ApplicationSettings.xml"));
|
||||
}
|
||||
|
||||
std::string UserPaths::getWindowSettingsPath()
|
||||
FilePath UserPaths::getWindowSettingsPath()
|
||||
{
|
||||
return getUserDataPath() + "window_settings.ini";
|
||||
return getUserDataPath().concat(FilePath("window_settings.ini"));
|
||||
}
|
||||
|
||||
std::string UserPaths::getLogPath()
|
||||
FilePath UserPaths::getLogPath()
|
||||
{
|
||||
return getUserDataPath() + "log/";
|
||||
return getUserDataPath().concat(FilePath("log/"));
|
||||
}
|
||||
|
||||
@@ -3,22 +3,24 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class UserPaths
|
||||
{
|
||||
public:
|
||||
static std::string getUserDataPath();
|
||||
static void setUserDataPath(const std::string& path);
|
||||
static FilePath getUserDataPath();
|
||||
static void setUserDataPath(const FilePath& path);
|
||||
|
||||
static std::string getSampleProjectsPath();
|
||||
static void setSampleProjectsPath(const std::string& path);
|
||||
static FilePath getSampleProjectsPath();
|
||||
static void setSampleProjectsPath(const FilePath& path);
|
||||
|
||||
static std::string getAppSettingsPath();
|
||||
static std::string getWindowSettingsPath();
|
||||
static std::string getLogPath();
|
||||
static FilePath getAppSettingsPath();
|
||||
static FilePath getWindowSettingsPath();
|
||||
static FilePath getLogPath();
|
||||
|
||||
private:
|
||||
static std::string s_userDataPath;
|
||||
static std::string s_sampleProjectsPath;
|
||||
static FilePath s_userDataPath;
|
||||
static FilePath s_sampleProjectsPath;
|
||||
};
|
||||
|
||||
#endif // USER_PATHS_H
|
||||
|
||||
@@ -74,7 +74,7 @@ CommandLineParser::CommandLineParser(int argc, char** argv, const std::string& v
|
||||
if (vm.count("licenseFile"))
|
||||
{
|
||||
std::cout << "licensefile flag" << std::endl;
|
||||
if (FileSystem::exists(licensefile))
|
||||
if (FilePath(licensefile).exists())
|
||||
{
|
||||
std::cout << "licensefile exists" << std::endl;
|
||||
processLicense(m_license.loadFromFile(licensefile));
|
||||
@@ -166,7 +166,7 @@ void CommandLineParser::processProjectfile(const std::string& file)
|
||||
}
|
||||
|
||||
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
|
||||
if (!configManager->load(TextAccess::createFromFile(projectfile.str())))
|
||||
if (!configManager->load(TextAccess::createFromFile(projectfile)))
|
||||
{
|
||||
m_errorString = errorstring + " could not be loaded(invalid)";
|
||||
return;
|
||||
@@ -180,7 +180,7 @@ void CommandLineParser::projectLoad()
|
||||
if (m_projectFile.exists() &&
|
||||
(m_projectFile.extension() == ".srctrlprj" || m_projectFile.extension() == ".coatiproject"))
|
||||
{
|
||||
MessageLoadProject(m_projectFile.str(), m_force).dispatch();
|
||||
MessageLoadProject(m_projectFile, m_force).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
FilePath::FilePath()
|
||||
: m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -15,6 +18,9 @@ FilePath::FilePath(const char* filePath)
|
||||
: m_path(filePath)
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,6 +28,9 @@ FilePath::FilePath(const std::string& filePath)
|
||||
: m_path(filePath)
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,6 +38,9 @@ FilePath::FilePath(const boost::filesystem::path& filePath)
|
||||
: m_path(filePath)
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,6 +48,9 @@ FilePath::FilePath(const std::string& filePath, const std::string& base)
|
||||
: m_path(boost::filesystem::absolute(filePath, base))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,9 +75,21 @@ bool FilePath::exists() const
|
||||
return m_exists;
|
||||
}
|
||||
|
||||
bool FilePath::recheckExists() const
|
||||
{
|
||||
m_checkedExists = false;
|
||||
return exists();
|
||||
}
|
||||
|
||||
bool FilePath::isDirectory() const
|
||||
{
|
||||
return boost::filesystem::is_directory(m_path);
|
||||
if (!m_checkedIsDirectory)
|
||||
{
|
||||
m_isDirectory = boost::filesystem::is_directory(m_path);
|
||||
m_checkedIsDirectory = true;
|
||||
}
|
||||
|
||||
return m_isDirectory;
|
||||
}
|
||||
|
||||
bool FilePath::isAbsolute() const
|
||||
@@ -72,37 +99,50 @@ bool FilePath::isAbsolute() const
|
||||
|
||||
FilePath FilePath::parentDirectory() const
|
||||
{
|
||||
return m_path.parent_path();
|
||||
FilePath parentDirectory(m_path.parent_path());
|
||||
parentDirectory.m_checkedIsDirectory = true;
|
||||
parentDirectory.m_isDirectory = true;
|
||||
|
||||
if (m_checkedExists && m_exists)
|
||||
{
|
||||
parentDirectory.m_checkedExists = true;
|
||||
parentDirectory.m_exists = true;
|
||||
}
|
||||
return parentDirectory;
|
||||
}
|
||||
|
||||
FilePath FilePath::absolute() const
|
||||
{
|
||||
return boost::filesystem::absolute(m_path);
|
||||
return FilePath(boost::filesystem::absolute(m_path));
|
||||
}
|
||||
|
||||
FilePath FilePath::canonical() const
|
||||
{
|
||||
if (m_canonicalized)
|
||||
{
|
||||
return FilePath(*this);
|
||||
}
|
||||
if (!exists())
|
||||
{
|
||||
return FilePath(m_path);
|
||||
return FilePath(*this);
|
||||
}
|
||||
|
||||
boost::filesystem::path abs_p = boost::filesystem::absolute(m_path);
|
||||
boost::filesystem::path result;
|
||||
boost::filesystem::path canonicalPath;
|
||||
for (boost::filesystem::path::iterator it = abs_p.begin(); it != abs_p.end(); ++it)
|
||||
{
|
||||
if (*it == "..")
|
||||
{
|
||||
// /a/b/.. is not necessarily /a if b is a symbolic link
|
||||
if (boost::filesystem::is_symlink(result))
|
||||
result /= *it;
|
||||
if (boost::filesystem::is_symlink(canonicalPath))
|
||||
canonicalPath /= *it;
|
||||
// /a/b/../.. is not /a/b/.. under most circumstances
|
||||
// We can end up with ..s in our result because of symbolic links
|
||||
else if (result.filename() == "..")
|
||||
result /= *it;
|
||||
else if (canonicalPath.filename() == "..")
|
||||
canonicalPath /= *it;
|
||||
// Otherwise it should be safe to resolve the parent
|
||||
else
|
||||
result = result.parent_path();
|
||||
canonicalPath = canonicalPath.parent_path();
|
||||
}
|
||||
else if (*it == ".")
|
||||
{
|
||||
@@ -111,10 +151,12 @@ FilePath FilePath::canonical() const
|
||||
else
|
||||
{
|
||||
// Just cat other path entries
|
||||
result /= *it;
|
||||
canonicalPath /= *it;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
FilePath ret(canonicalPath);
|
||||
ret.m_canonicalized = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
@@ -132,7 +174,7 @@ std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
LOG_ERROR(match[1].str() + " is not an environment variable");
|
||||
return paths;
|
||||
}
|
||||
text.replace( match.position(0), match.length(0), s);
|
||||
text.replace(match.position(0), match.length(0), s);
|
||||
}
|
||||
|
||||
char environmentVariablePathSeparator = ':';
|
||||
@@ -145,7 +187,7 @@ std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
{
|
||||
if (str.size())
|
||||
{
|
||||
paths.push_back(str);
|
||||
paths.push_back(FilePath(str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +201,7 @@ FilePath FilePath::relativeTo(const FilePath& other) const
|
||||
|
||||
if (a.root_path() != b.root_path())
|
||||
{
|
||||
return str();
|
||||
return *this;
|
||||
}
|
||||
|
||||
boost::filesystem::path::const_iterator itA = a.begin();
|
||||
@@ -196,12 +238,12 @@ FilePath FilePath::relativeTo(const FilePath& other) const
|
||||
r = "./";
|
||||
}
|
||||
|
||||
return r;
|
||||
return FilePath(r);
|
||||
}
|
||||
|
||||
FilePath FilePath::concat(const FilePath& other) const
|
||||
{
|
||||
return boost::filesystem::path(m_path) / other.m_path;
|
||||
return FilePath(boost::filesystem::path(m_path) / other.m_path);
|
||||
}
|
||||
|
||||
bool FilePath::contains(const FilePath& other) const
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define FILE_PATH_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
@@ -9,15 +10,16 @@ class FilePath
|
||||
{
|
||||
public:
|
||||
FilePath();
|
||||
FilePath(const char* filePath);
|
||||
FilePath(const std::string& filePath);
|
||||
FilePath(const boost::filesystem::path& filePath);
|
||||
explicit FilePath(const char* filePath);
|
||||
explicit FilePath(const std::string& filePath);
|
||||
explicit FilePath(const boost::filesystem::path& filePath);
|
||||
FilePath(const std::string& filePath, const std::string& base);
|
||||
|
||||
boost::filesystem::path path() const;
|
||||
|
||||
bool empty() const;
|
||||
bool exists() const;
|
||||
bool recheckExists() const;
|
||||
bool isDirectory() const;
|
||||
bool isAbsolute() const;
|
||||
|
||||
@@ -49,6 +51,9 @@ private:
|
||||
|
||||
mutable bool m_exists;
|
||||
mutable bool m_checkedExists;
|
||||
mutable bool m_isDirectory;
|
||||
mutable bool m_checkedIsDirectory;
|
||||
mutable bool m_canonicalized;
|
||||
};
|
||||
|
||||
#endif // FILE_PATH_H
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
FileRegister::FileRegister(const FileRegisterStateData& stateData, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths)
|
||||
: m_stateData(stateData)
|
||||
, m_indexedPaths(indexedPaths)
|
||||
, m_excludedPaths(excludedPaths)
|
||||
, m_hasFilePathCache(
|
||||
[&](std::string filePath){
|
||||
[&](std::string f){
|
||||
const FilePath filePath(f);
|
||||
bool ret = false;
|
||||
for (const FilePath& indexedPath: m_indexedPaths)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "utility/file/FileRegisterStateData.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
FileRegisterStateData::FileRegisterStateData()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
std::vector<std::string> FileSystem::getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions
|
||||
const FilePath& path, const std::vector<std::string>& extensions
|
||||
){
|
||||
std::set<std::string> ext(extensions.begin(), extensions.end());
|
||||
std::vector<std::string> files;
|
||||
|
||||
if (boost::filesystem::is_directory(path))
|
||||
if (boost::filesystem::is_directory(path.path()))
|
||||
{
|
||||
boost::filesystem::recursive_directory_iterator it(path);
|
||||
boost::filesystem::recursive_directory_iterator it(path.path());
|
||||
boost::filesystem::recursive_directory_iterator endit;
|
||||
while (it != endit)
|
||||
{
|
||||
@@ -38,7 +38,7 @@ std::vector<std::string> FileSystem::getFileNamesFromDirectory(
|
||||
return files;
|
||||
}
|
||||
|
||||
FileInfo FileSystem::getFileInfoForPath(FilePath filePath)
|
||||
FileInfo FileSystem::getFileInfoForPath(const FilePath& filePath)
|
||||
{
|
||||
if (filePath.exists())
|
||||
{
|
||||
@@ -110,7 +110,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
|
||||
std::time_t t = boost::filesystem::last_write_time(*it);
|
||||
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
files.push_back(FileInfo(it->path(), lastWriteTime));
|
||||
files.push_back(FileInfo(FilePath(it->path()), lastWriteTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
|
||||
{
|
||||
boost::posix_time::ptime lastWriteTime;
|
||||
if (FileSystem::exists(filePath.str()))
|
||||
if (filePath.exists())
|
||||
{
|
||||
std::time_t t = boost::filesystem::last_write_time(filePath.path());
|
||||
lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
@@ -235,13 +235,3 @@ std::string FileSystem::filePathWithoutExtension(const std::string& path)
|
||||
{
|
||||
return boost::filesystem::path(path).replace_extension().generic_string();
|
||||
}
|
||||
|
||||
bool FileSystem::equivalent(const std::string& pathA, const std::string& pathB)
|
||||
{
|
||||
if (exists(pathA) && exists(pathB))
|
||||
{
|
||||
return boost::filesystem::equivalent(boost::filesystem::path(pathA), boost::filesystem::path(pathB));
|
||||
}
|
||||
|
||||
return boost::filesystem::path(pathA).compare(boost::filesystem::path(pathB)) == 0;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ class FileSystem
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions);
|
||||
const FilePath& path, const std::vector<std::string>& extensions);
|
||||
|
||||
static FileInfo getFileInfoForPath(FilePath filePath);
|
||||
static FileInfo getFileInfoForPath(const FilePath& filePath);
|
||||
|
||||
static std::vector<FileInfo> getFileInfosFromPaths(
|
||||
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions, bool followSymLinks = true);
|
||||
@@ -36,8 +36,6 @@ public:
|
||||
|
||||
static std::string extension(const std::string& path);
|
||||
static std::string filePathWithoutExtension(const std::string& path);
|
||||
|
||||
static bool equivalent(const std::string& pathA, const std::string& pathB);
|
||||
};
|
||||
|
||||
#endif // FILE_SYSTEM_H
|
||||
|
||||
@@ -19,7 +19,7 @@ std::shared_ptr<SharedUUIDManager> SharedUUIDManager::getInstance()
|
||||
// m_instance = std::make_shared<SharedUUIDManager>();
|
||||
SharedUUIDManager* sharedUUIDManager = new SharedUUIDManager();
|
||||
m_instance = std::shared_ptr<SharedUUIDManager>(sharedUUIDManager);
|
||||
m_instance->setFilePath(UserPaths::getUserDataPath());
|
||||
m_instance->setFilePath(UserPaths::getUserDataPath().str());
|
||||
m_instance->saveInstanceUUID();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ SharedUUIDManager::~SharedUUIDManager()
|
||||
void SharedUUIDManager::setFilePath(const std::string& filePath)
|
||||
{
|
||||
m_filePath = filePath;
|
||||
FileSystem::createDirectory(m_filePath);
|
||||
FileSystem::createDirectory(FilePath(m_filePath));
|
||||
|
||||
refreshUUIDs();
|
||||
}
|
||||
@@ -121,6 +121,6 @@ void SharedUUIDManager::refreshUUIDs()
|
||||
{
|
||||
if (FilePath(m_filePath + m_fileName).exists())
|
||||
{
|
||||
m_uuids = ConfigManager::createAndLoad(TextAccess::createFromFile(m_filePath + m_fileName));
|
||||
m_uuids = ConfigManager::createAndLoad(TextAccess::createFromFile(FilePath(m_filePath + m_fileName)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ FileLogger::~FileLogger()
|
||||
{
|
||||
}
|
||||
|
||||
void FileLogger::setLogDirectory(const std::string& filePath)
|
||||
void FileLogger::setLogDirectory(const FilePath& filePath)
|
||||
{
|
||||
m_logDirectory = filePath;
|
||||
FileSystem::createDirectory(m_logDirectory);
|
||||
@@ -90,14 +90,14 @@ void FileLogger::updateLogFileName()
|
||||
|
||||
if (fileChanged)
|
||||
{
|
||||
FileSystem::remove(m_logDirectory + m_currentLogFileName);
|
||||
FileSystem::remove(m_logDirectory.concat(FilePath(m_currentLogFileName)));
|
||||
}
|
||||
}
|
||||
|
||||
void FileLogger::logMessage(const std::string& type, const LogMessage& message)
|
||||
{
|
||||
std::ofstream fileStream;
|
||||
fileStream.open(m_logDirectory + m_currentLogFileName, std::ios::app);
|
||||
fileStream.open(m_logDirectory.concat(FilePath(m_currentLogFileName)).str(), std::ios::app);
|
||||
fileStream << message.getTimeString("%H:%M:%S") << " | ";
|
||||
fileStream << message.threadId << " | ";
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/logging/Logger.h"
|
||||
#include "utility/logging/LogMessage.h"
|
||||
|
||||
@@ -12,7 +13,7 @@ public:
|
||||
FileLogger();
|
||||
virtual ~FileLogger();
|
||||
|
||||
void setLogDirectory(const std::string& filePath);
|
||||
void setLogDirectory(const FilePath& filePath);
|
||||
void setFileName(const std::string& fileName);
|
||||
void setMaxLogLineCount(unsigned int logCount);
|
||||
|
||||
@@ -28,7 +29,7 @@ private:
|
||||
void updateLogFileName();
|
||||
|
||||
std::string m_logFileName;
|
||||
std::string m_logDirectory;
|
||||
FilePath m_logDirectory;
|
||||
unsigned int m_maxLogLineCount;
|
||||
unsigned int m_maxLogFileCount;
|
||||
unsigned int m_currentLogLineCount;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
std::shared_ptr<TextAccess> TextAccess::createFromFile(const std::string& filePath)
|
||||
std::shared_ptr<TextAccess> TextAccess::createFromFile(const FilePath& filePath)
|
||||
{
|
||||
std::shared_ptr<TextAccess> result(new TextAccess());
|
||||
|
||||
@@ -32,7 +32,7 @@ unsigned int TextAccess::getLineCount() const
|
||||
return m_lines.size();
|
||||
}
|
||||
|
||||
std::string TextAccess::getFilePath() const
|
||||
FilePath TextAccess::getFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
@@ -76,16 +76,16 @@ std::string TextAccess::getText() const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> TextAccess::readFile(const std::string& filePath)
|
||||
std::vector<std::string> TextAccess::readFile(const FilePath& filePath)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
std::ifstream srcFile;
|
||||
srcFile.open(filePath);
|
||||
srcFile.open(filePath.str());
|
||||
|
||||
if (srcFile.fail())
|
||||
{
|
||||
LOG_ERROR("Could not open file " + filePath);
|
||||
LOG_ERROR("Could not open file " + filePath.str());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,19 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class TextAccess
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<TextAccess> createFromFile(const std::string& filePath);
|
||||
static std::shared_ptr<TextAccess> createFromFile(const FilePath& filePath);
|
||||
static std::shared_ptr<TextAccess> createFromString(const std::string& text);
|
||||
|
||||
virtual ~TextAccess();
|
||||
|
||||
unsigned int getLineCount() const;
|
||||
|
||||
std::string getFilePath() const;
|
||||
FilePath getFilePath() const;
|
||||
|
||||
/**
|
||||
* @param lineNumber: starts with 1
|
||||
@@ -30,7 +32,7 @@ public:
|
||||
std::string getText() const;
|
||||
|
||||
private:
|
||||
static std::vector<std::string> readFile(const std::string& filePath);
|
||||
static std::vector<std::string> readFile(const FilePath& filePath);
|
||||
static std::vector<std::string> splitStringByLines(const std::string& text);
|
||||
|
||||
TextAccess();
|
||||
@@ -40,7 +42,7 @@ private:
|
||||
bool checkIndexInRange(const unsigned int index) const;
|
||||
bool checkIndexIntervalInRange(const unsigned int firstIndex, const unsigned int lastIndex) const;
|
||||
|
||||
std::string m_filePath;
|
||||
FilePath m_filePath;
|
||||
std::vector<std::string> m_lines;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
|
||||
namespace utility
|
||||
{
|
||||
template <typename Ret, typename... Args>
|
||||
|
||||
Reference in New Issue
Block a user