本文整理汇总了C++中FilePath类的典型用法代码示例。如果您正苦于以下问题:C++ FilePath类的具体用法?C++ FilePath怎么用?C++ FilePath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilePath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isEquivalentTo
// check for equivalence (point to the same file-system entity)
bool FilePath::isEquivalentTo(const FilePath& filePath) const
{
if (!exists() || !filePath.exists())
return false;
try
{
return boost::filesystem::equivalent(pImpl_->path, filePath.pImpl_->path);
}
catch(const boost::filesystem::filesystem_error& e)
{
Error error(e.code(), ERROR_LOCATION) ;
addErrorProperties(pImpl_->path, &error) ;
error.addProperty("equivilant-to", filePath);
return error ;
}
// keep compiler happy
return false;
}
示例2: FilePath
FilePath FilePath::resolveAliasedPath(const std::string& aliasedPath,
const FilePath& userHomePath)
{
// Special case for empty string or "~"
if (aliasedPath.empty() || (aliasedPath.compare(kHomePathLeafAlias) == 0))
return userHomePath;
// if the path starts with the home alias then substitute the home path
if (aliasedPath.find(kHomePathAlias) == 0)
{
std::string resolvedPath = userHomePath.absolutePath() +
aliasedPath.substr(1);
return FilePath(resolvedPath);
}
else // no aliasing, this is either an absolute path or path
// relative to the current directory
{
return FilePath::safeCurrentPath(userHomePath).complete(aliasedPath);
}
}
示例3: savePlotAsPostscript
Error PlotManager::savePlotAsPostscript(const FilePath& targetPath,
int width,
int height)
{
// calculate size in inches
double widthInches = pixelsToInches(width);
double heightInches = pixelsToInches(height);
// generate code for creating postscript device
boost::format fmt("{ require(grDevices, quietly=TRUE); "
" postscript(file=\"%1%\", width=%2%, height=%3%, "
" onefile = FALSE, "
" paper = \"special\", "
" horizontal = FALSE); }");
std::string deviceCreationCode = boost::str(fmt % string_utils::utf8ToSystem(targetPath.absolutePath()) %
widthInches %
heightInches);
return savePlotAsFile(deviceCreationCode);
}
示例4: createConsoleProc
core::Error createConsoleProc(const ShellArgs& args,
const FilePath& outputFile,
const boost::optional<FilePath>& workingDir,
const std::string& caption,
bool requiresSsh,
bool dialog,
bool enqueueRefreshOnExit,
boost::shared_ptr<ConsoleProcess>* ppCP)
{
core::system::ProcessOptions options = procOptions(requiresSsh);
if (!workingDir)
options.workingDir = s_workingDir;
else if (!workingDir.get().empty())
options.workingDir = workingDir.get();
// NOTE: we use runCommand style process creation on both windows and posix
// so that we can redirect standard output to a file -- this works on
// windows because we are not specifying options.detachProcess (not
// necessary because ConsoleProcess specifies options.createNewConsole
// which overrides options.detachProcess)
// build command
std::string command = svn() << args.args();
// redirect stdout to a file
if (!outputFile.empty())
options.stdOutFile = outputFile;
// create the process
*ppCP = ConsoleProcess::create(command,
options,
caption,
dialog,
console_process::InteractionPossible,
console_process::kDefaultMaxOutputLines);
if (enqueueRefreshOnExit)
(*ppCP)->onExit().connect(boost::bind(&enqueueRefreshEvent));
return Success();
}
示例5: GetModificationDate
String File::GetModificationDate(const FilePath & filePathname)
{
String realPathname = filePathname.GetAbsolutePathname();
struct stat fileInfo = {0};
int32 ret = stat(realPathname.c_str(), &fileInfo);
if(0 == ret)
{
#if defined (__DAVAENGINE_WIN32__)
tm* utcTime = gmtime(&fileInfo.st_mtime);
#elif defined (__DAVAENGINE_ANDROID__)
tm* utcTime = gmtime((const time_t *)&fileInfo.st_mtime);
#elif defined (__DAVAENGINE_MACOS__) || defined (__DAVAENGINE_IPHONE__)
tm* utcTime = gmtime(&fileInfo.st_mtimespec.tv_sec);
#endif
return String(Format("%04d.%02d.%02d %02d:%02d:%02d",
utcTime->tm_year + 1900, utcTime->tm_mon + 1, utcTime->tm_mday,
utcTime->tm_hour, utcTime->tm_min, utcTime->tm_sec));
}
return String("");
}
示例6: parseDcfFile
Error parseDcfFile(const FilePath& dcfFilePath,
bool preserveKeyCase,
DcfFieldRecorder recordField,
std::string* pUserErrMsg)
{
// read the file
std::string dcfFileContents;
Error error = readStringFromFile(dcfFilePath,
&dcfFileContents);
if (error)
{
error.addProperty("dcf-file", dcfFilePath.absolutePath());
*pUserErrMsg = error.summary();
return error;
}
return parseDcfFile(dcfFileContents,
preserveKeyCase,
recordField,
pUserErrMsg);
}
示例7: isReadOnly
bool isReadOnly(const FilePath& filePath)
{
if (::access(filePath.absolutePath().c_str(), W_OK) == -1)
{
if (errno == EACCES)
{
return true;
}
else
{
Error error = systemError(errno, ERROR_LOCATION);
error.addProperty("path", filePath);
LOG_ERROR(error);
return false;
}
}
else
{
return false;
}
}
示例8:
bool VideoWriter::CVideoWriter::open(const FilePath& path, const Size& size, const double fps)
{
if (isOpened())
{
close();
}
if (FileSystem::Exists(path))
{
FileSystem::Remove(path);
}
const bool result = m_writer.open(path.narrow(), cv::VideoWriter::fourcc('H', '2', '6', '4'), fps, cv::Size(size.x, size.y), true);
if (result)
{
m_frameSize = size;
}
return result;
}
示例9: getDefaultWorkingDirectory
FilePath getDefaultWorkingDirectory()
{
// calculate using user settings
FilePath defaultWorkingDir = userSettings().initialWorkingDirectory();
FilePath sessionDefaultWorkingDir = FilePath(session::options().defaultWorkingDir());
// return it if it exists, otherwise use the
// session specified value if it exists
// otherwise, use the default user home path
if (defaultWorkingDir.exists() && defaultWorkingDir.isDirectory())
return defaultWorkingDir;
else if (sessionDefaultWorkingDir.exists() && sessionDefaultWorkingDir.isDirectory())
return sessionDefaultWorkingDir;
else
return session::options().userHomePath();
}
示例10: readStringFromFile
Error readStringFromFile(const FilePath& filePath,
std::string* pStr,
string_utils::LineEnding lineEnding)
{
using namespace boost::system::errc ;
// open file
std::string file = filePath.absolutePath();
std::ifstream ifs(file.c_str(), std::ios_base::in | std::ios_base::binary) ;
if (!ifs)
{
Error error = systemError(no_such_file_or_directory,ERROR_LOCATION);
error.addProperty("path", file);
return error;
}
try
{
// set exception mask (required for proper reporting of errors)
ifs.exceptions(std::istream::failbit | std::istream::badbit);
// copy file to string stream
std::ostringstream ostr;
boost::iostreams::copy(ifs, ostr);
*pStr = ostr.str();
string_utils::convertLineEndings(pStr, lineEnding);
// return success
return Success();
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
error.addProperty("path", file);
return error;
}
}
示例11:
bool Win32FileGroupDirectory::openMappedFile( const FilePath & _fileName, const FileMappedInterfacePtr & _stream )
{
if( _stream == nullptr )
{
LOGGER_ERROR(m_serviceProvider)("Win32FileGroupDirectory::openMappedFile failed _stream == NULL"
);
return false;
}
if( _stream->open( m_path, _fileName ) == false )
{
LOGGER_ERROR(m_serviceProvider)("Win32FileGroupDirectory::openMappedFile failed open file '%s':'%s'"
, m_path.c_str()
, _fileName.c_str()
);
return false;
}
return true;
}
示例12: writeStringToFile
Error writeStringToFile(const FilePath& filePath,
const std::string& str,
string_utils::LineEnding lineEnding)
{
using namespace boost::system::errc ;
// open file
std::string file = filePath.absolutePath();
std::ofstream ofs(file.c_str(), std::ios_base::out | std::ios_base::binary);
if (!ofs)
{
Error error = systemError(no_such_file_or_directory,ERROR_LOCATION);
error.addProperty("path", file);
return error;
}
try
{
// set exception mask (required for proper reporting of errors)
ofs.exceptions(std::istream::failbit | std::istream::badbit);
// copy string to file
std::string normalized = str;
string_utils::convertLineEndings(&normalized, lineEnding);
std::istringstream istr(normalized);
boost::iostreams::copy(istr, ofs);
// return success
return Success();
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
error.addProperty("path", file);
return error;
}
}
示例13: svm_train
bool Problem::CProblem::trainAndSaveModel(const FilePath& path, const Paramter& param) const
{
if (!m_hasData)
{
return false;
}
svm_model* model = svm_train(&m_problem, ¶m);
const FilePath parentFilePath = FileSystem::ParentPath(path);
if (!FileSystem::Exists(parentFilePath) && !FileSystem::CreateDirectories(parentFilePath))
{
return false;
}
const int32 result = svm_save_model(path.narrow().c_str(), model);
svm_free_and_destroy_model(&model);
return (result == 0);
}
示例14: copyFile
// IN: String sourcePath, String targetPath
Error copyFile(const core::json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// read params
std::string sourcePath, targetPath;
Error error = json::readParams(request.params, &sourcePath, &targetPath);
if (error)
return error ;
// make sure the target path doesn't exist
FilePath targetFilePath = module_context::resolveAliasedPath(targetPath);
if (targetFilePath.exists())
return fileExistsError(ERROR_LOCATION);
// compute the source file path
FilePath sourceFilePath = module_context::resolveAliasedPath(sourcePath);
// copy directories recursively
Error copyError ;
if (sourceFilePath.isDirectory())
{
// create the target directory
Error error = targetFilePath.ensureDirectory();
if (error)
return error ;
// iterate over the source
copyError = sourceFilePath.childrenRecursive(
boost::bind(copySourceFile, sourceFilePath, targetFilePath, _1, _2));
}
else
{
copyError = sourceFilePath.copy(targetFilePath);
}
// check quota after copies
quotas::checkQuotaStatus();
// return error status
return copyError;
}
示例15: LoadTextureAction
void LandscapeEditorCustomColors::LoadTextureAction(const FilePath &pathToFile)
{
if(pathToFile.IsEmpty())
return;
Vector<Image*> images = ImageLoader::CreateFromFile(pathToFile);
if(images.empty())
return;
Image* image = images.front();
if(image)
{
Texture* texture = Texture::CreateFromData(image->GetPixelFormat(),
image->GetData(),
image->GetWidth(),
image->GetHeight(),
false);
SafeRelease(colorSprite);
colorSprite = Sprite::CreateAsRenderTarget(texSurf->GetWidth(), texSurf->GetHeight(), FORMAT_RGBA8888);
Sprite* sprite = Sprite::CreateFromTexture(texture, 0, 0, texture->GetWidth(), texture->GetHeight());
StoreOriginalState();
RenderManager::Instance()->SetRenderTarget(colorSprite);
sprite->Draw();
RenderManager::Instance()->RestoreRenderTarget();
PerformLandscapeDraw();
SafeRelease(sprite);
SafeRelease(texture);
for_each(images.begin(), images.end(), SafeRelease<Image>);
StoreSaveFileName(pathToFile);
CreateUndoPoint();
}
}