本文整理汇总了C++中fs::path::string方法的典型用法代码示例。如果您正苦于以下问题:C++ path::string方法的具体用法?C++ path::string怎么用?C++ path::string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs::path
的用法示例。
在下文中一共展示了path::string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addAttachedFile
bool CrashHandlerImpl::addAttachedFile(const fs::path & file) {
if(file.is_relative()) {
fs::path absolute = fs::current_path() / file;
if(absolute.is_relative()) {
return false;
}
return addAttachedFile(absolute);
}
Autolock autoLock(&m_Lock);
if(m_pCrashInfo->nbFilesAttached == CrashInfo::MaxNbFiles) {
LogError << "Too much files already attached to the crash report (" << m_pCrashInfo->nbFilesAttached << ").";
return false;
}
if(file.string().size() >= CrashInfo::MaxFilenameLen) {
LogError << "File name is too long.";
return false;
}
for(u32 i = 0; i < m_pCrashInfo->nbFilesAttached; i++) {
if(strcmp(m_pCrashInfo->attachedFiles[i], file.string().c_str()) == 0) {
LogWarning << "File \"" << file << "\" is already attached.";
return false;
}
}
util::storeStringTerminated(m_pCrashInfo->attachedFiles[m_pCrashInfo->nbFilesAttached], file.string());
m_pCrashInfo->nbFilesAttached++;
return true;
}
示例2: addAttachedFile
bool CrashHandlerImpl::addAttachedFile(const fs::path& file) {
Autolock autoLock(&m_Lock);
if(m_pCrashInfo->nbFilesAttached == CrashInfo::MaxNbFiles) {
LogError << "Too much files already attached to the crash report (" << m_pCrashInfo->nbFilesAttached << ").";
return false;
}
if(file.string().size() >= CrashInfo::MaxFilenameLen) {
LogError << "File name is too long.";
return false;
}
for(int i = 0; i < m_pCrashInfo->nbFilesAttached; i++) {
if(strcmp(m_pCrashInfo->attachedFiles[i], file.string().c_str()) == 0) {
LogWarning << "File \"" << file << "\" is already attached.";
return false;
}
}
strcpy(m_pCrashInfo->attachedFiles[m_pCrashInfo->nbFilesAttached], file.string().c_str());
m_pCrashInfo->nbFilesAttached++;
return true;
}
示例3: CreateCompatibleBitmap
Cursor::Cursor(fs::path imgPath, float hotSpotX, float hotSpotY) {
sf::Image gif;
if(!gif.loadFromFile(imgPath.string())) {
std::string error = "Error loading cursor from " + imgPath.string();
throw error;
}
// Calculate the AND and XOR masks
HBITMAP cursorAnd = CreateCompatibleBitmap(GetDC(NULL), gif.getSize().x, gif.getSize().y);
HBITMAP cursorXor = CreateCompatibleBitmap(GetDC(NULL), gif.getSize().x, gif.getSize().y);
GetMaskBitmaps(gif, cursorAnd, cursorXor);
ICONINFO iconinfo = {0};
iconinfo.fIcon = FALSE;
iconinfo.xHotspot = hotSpotX;
iconinfo.yHotspot = hotSpotY;
iconinfo.hbmMask = cursorAnd;
iconinfo.hbmColor = cursorXor;
HCURSOR hCursor = CreateIconIndirect(&iconinfo);
if(hCursor == NULL) {
std::string error = "Error creating cursor from " + imgPath.string();
error += " (error code " + std::to_string(GetLastError()) + ")";
throw error;
}
ptr = hCursor;
DeleteObject(cursorAnd);
DeleteObject(cursorXor);
}
示例4: IOException
void
FileSystemTestSetup::setup_clustercache_device(const fs::path& device,
uint64_t size) const
{
int fd = ::open(device.string().c_str(),
O_RDWR| O_CREAT | O_EXCL,
S_IWUSR | S_IRUSR);
if(fd < 0)
{
LOG_ERROR("Couldn't open file " << device << ", " << strerror(errno));
throw fungi::IOException("Couldn't open file", device.string().c_str());
}
BOOST_SCOPE_EXIT((fd))
{
::close(fd);
}
BOOST_SCOPE_EXIT_END;
int ret = ::posix_fallocate(fd, 0, size);
if (ret != 0)
{
LOG_ERROR("Could not allocate file " << device << " with size " << size << ", " << strerror(ret));
throw fungi::IOException("Could not allocate file",
device.string().c_str(),
ret);
}
::fchmod(fd, 00600);
}
示例5: DoCopyFile
bool CMissionManager::DoCopyFile(const fs::path& source, const fs::path& dest, bool overwrite)
{
if (overwrite)
{
try
{
// According to docs, remove() doesn't throw if file doesn't exist
fs::remove(dest);
DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Destination file %s already exists, has been removed before copying.\r", dest.string().c_str());
}
catch (fs::filesystem_error& e)
{
// Don't care about removal error
DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("Caught exception while removing destination file %s: %s\r", dest.string().c_str(), e.what());
}
}
// Copy the source file to the destination
try
{
fs::copy_file(source, dest);
DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("File successfully copied to %s.\r", dest.string().c_str());
return true;
}
catch (fs::filesystem_error& e)
{
DM_LOG(LC_MAINMENU, LT_ERROR)LOGSTRING("Exception while coyping file from %s to %s: %s\r",
source.string().c_str(), dest.string().c_str(), e.what());
return false;
}
}
示例6: Save
/*******************************************************************
* Function Name: Save
* Return Type : int
* Created On : Nov 10, 2013
* Created By : hrushi
* Comments : Save SVM
* Arguments : const fs::path fs
*******************************************************************/
int SVMLearning::Save( const fs::path fs) const
{
cout << "Writing to: " << fs.string() << endl;
m_SVM.save(fs.string().c_str());
return EXIT_SUCCESS;
}
示例7: load
void GstVideoServer::load( const fs::path& path )
{
CI_LOG_I("Load file: " << path.string() );
GstPlayer::load(path.string());
mCurrentFileName = path.filename().string();
///> Now that we have loaded we can grab the pipeline..
mGstPipeline = GstPlayer::getPipeline();
setupNetworkClock();
}
示例8: remove_hjtremove
int remove_hjtremove(fs::path path, void* data)
{
if (strstr(path.string().c_str(),".hjtremove") ||
strstr(path.string().c_str(),".tmp")){
boost::system::error_code ec;
fs::remove(path, ec);
return ec.value();
}
return 0;
}
示例9: RenameOver
bool RenameOver(fs::path src, fs::path dest)
{
#ifdef WIN32
return MoveFileExA(src.string().c_str(), dest.string().c_str(),
MOVEFILE_REPLACE_EXISTING) != 0;
#else
int rc = std::rename(src.string().c_str(), dest.string().c_str());
return (rc == 0);
#endif /* WIN32 */
}
示例10: Next
bool MDeepFileIteratorImp::Next(
fs::path& outFile)
{
bool result = false;
while (not result and not mStack.empty())
{
struct dirent* e = nil;
MInfo& top = mStack.top();
if (top.mDIR != nil)
THROW_IF_POSIX_ERROR(::readdir_r(top.mDIR, &top.mEntry, &e));
if (e == nil)
{
if (top.mDIR != nil)
closedir(top.mDIR);
mStack.pop();
}
else
{
outFile = top.mParent / e->d_name;
struct stat st;
if (stat(outFile.string().c_str(), &st) < 0 or S_ISLNK(st.st_mode))
continue;
if (S_ISDIR(st.st_mode))
{
if (strcmp(e->d_name, ".") and strcmp(e->d_name, ".."))
{
MInfo info;
info.mParent = outFile;
info.mDIR = opendir(outFile.string().c_str());
memset(&info.mEntry, 0, sizeof(info.mEntry));
mStack.push(info);
}
continue;
}
if (mOnlyTEXT and not IsTEXT(outFile))
continue;
if (mFilter.length() and not FileNameMatches(mFilter.c_str(), outFile))
continue;
result = true;
}
}
return result;
}
示例11: content
TEST_F(FileUtilsTest, copy)
{
std::string content("content");
const fs::path a = FileUtils::create_temp_file_in_temp_dir();
{
std::ofstream ofs(a.string().c_str());
ofs << content;
ofs.close();
}
const size_t size = fs::file_size(a);
const fs::path b = FileUtils::create_temp_file_in_temp_dir("b");
ASSERT_NO_THROW(fs::remove(b));
ASSERT_FALSE(fs::exists(b));
EXPECT_NO_THROW(FileUtils::safe_copy(a, b));
EXPECT_TRUE(fs::exists(b));
EXPECT_EQ(size, fs::file_size(b));
std::string read;
{
std::ifstream ifs(b.string().c_str());
ifs >> read;
ifs.close();
}
EXPECT_EQ(content, read);
// copy to a larger, existing file
read = "";
{
std::ofstream ofs(a.string().c_str());
ofs << content << content << content;
ofs.close();
}
EXPECT_LT(size, fs::file_size(a));
EXPECT_NO_THROW(FileUtils::safe_copy(b, a));
EXPECT_EQ(size, fs::file_size(a));
{
std::ifstream ifs(a.string().c_str());
ifs >> read;
ifs.close();
}
EXPECT_EQ(content, read);
}
示例12: setReportLocation
bool CrashHandlerImpl::setReportLocation(const fs::path& location) {
Autolock autoLock(&m_Lock);
if(location.string().size() >= CrashInfo::MaxFilenameLen) {
LogError << "Report location path is too long.";
return false;
}
strcpy(m_pCrashInfo->crashReportFolder, location.string().c_str());
return true;
}
示例13: test_parent
static void test_parent(const fs::path & in, const std::string & out) {
fs::path p = in.parent();
arx_assert_msg(p.string() == out, "\"%s\".parent() -> \"%s\" != \"%s\"",
in.string().c_str(), p.string().c_str(), out.c_str());
fs::path temp = in;
temp.up();
arx_assert_msg(temp.string() == out, "\"%s\".up() ->\"%s\" != \"%s\"",
in.string().c_str(), temp.string().c_str(), out.c_str());
}
示例14: deleteFile
bool FileService::deleteFile(const fs::path& file)
{
try
{
os_chmod(file.string().c_str(), S_IRUSR|S_IWUSR);
return fs::remove(file);
}
catch (const std::exception ex)
{
std::cout << "ERROR: delete file " << file.string() << "; exception: " << ex.what() << std::endl;
return false;
}
}
示例15: loadCanvasFromFile
void ControleaseApp::loadCanvasFromFile(fs::path file)
{
console() << "loading patch from: " << file.string() << endl;
if (!exists(file)) {
console() << "error: cannot find '"<<file.string()<<"'"<<endl;
return;
}
// get size of file
XmlTree xml(loadFile(file));
canvas->initFromXml(xml.getChild("Canvas"));
}