本文整理汇总了C++中core::FilePath类的典型用法代码示例。如果您正苦于以下问题:C++ FilePath类的具体用法?C++ FilePath怎么用?C++ FilePath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilePath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: appendToFile
Error appendToFile(const core::FilePath& filePath,
const ContentType& content)
{
using namespace boost::system::errc ;
// open the file stream
boost::shared_ptr<std::ostream> pOfs;
Error error = filePath.open_w(&pOfs, false);
if (error)
return error;
try
{
pOfs->seekp(0, std::ios_base::end);
// append the content
*pOfs << content ;
if (pOfs->fail())
return systemError(io_error, ERROR_LOCATION);
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
error.addProperty("path", filePath.absolutePath());
return error;
}
return Success() ;
}
示例2: buildRCmd
shell_utils::ShellCommand buildRCmd(const core::FilePath& rBinDir)
{
#if defined(_WIN32)
shell_utils::ShellCommand rCmd(rBinDir.childPath("Rcmd.exe"));
#else
shell_utils::ShellCommand rCmd(rBinDir.childPath("R"));
rCmd << "CMD";
#endif
return rCmd;
}
示例3: connectHtmlCapture
core::Error HtmlCapture::connectHtmlCapture(
const core::FilePath& outputFolder,
const core::FilePath& libraryFolder,
const json::Object& chunkOptions)
{
return r::exec::RFunction(".rs.initHtmlCapture",
string_utils::utf8ToSystem(outputFolder.absolutePath()),
string_utils::utf8ToSystem(outputFolder.complete(kChunkLibDir).absolutePath()),
chunkOptions).call();
}
示例4: runProgram
Error runProgram(const core::FilePath& programFilePath,
const std::vector<std::string>& args,
const core::system::Options& extraEnvVars,
const core::FilePath& workingDir,
const boost::function<void(const std::string&)>& onOutput,
const boost::function<void(int,const std::string&)>& onExited)
{
// get system program file path
std::string programPath = string_utils::utf8ToSystem(
programFilePath.absolutePath());
// setup options
core::system::ProcessOptions options;
options.terminateChildren = true;
options.redirectStdErrToStdOut = true;
core::system::Options env;
core::system::getModifiedEnv(extraEnvVars, &env);
options.environment = env;
options.workingDir = workingDir;
// setup callbacks
boost::shared_ptr<CB> pCB(new CB(onOutput, onExited));
core::system::ProcessCallbacks cb;
cb.onStdout = cb.onStderr = boost::bind(&CB::onOutput, pCB, _2);
cb.onExit = boost::bind(&CB::onExit, pCB, _1);
// run process using supervisor
return s_processSupervisor.runProgram(programPath, args, options, cb);
}
示例5: initLocalStreamAcceptor
inline Error initLocalStreamAcceptor(
SocketAcceptorService<boost::asio::local::stream_protocol>& acceptorService,
const core::FilePath& localStreamPath)
{
// initialize endpoint
using boost::asio::local::stream_protocol;
stream_protocol::endpoint endpoint(localStreamPath.absolutePath());
// get acceptor
stream_protocol::acceptor& acceptor = acceptorService.acceptor();
// open
boost::system::error_code ec;
acceptor.open(endpoint.protocol(), ec) ;
if (ec)
return Error(ec, ERROR_LOCATION) ;
// bind
acceptor.bind(endpoint, ec) ;
if (ec)
return Error(ec, ERROR_LOCATION) ;
// chmod on the stream file
Error error = changeFileMode(localStreamPath,
system::EveryoneReadWriteMode);
if (error)
return error;
// listen
acceptor.listen(boost::asio::socket_base::max_connections, ec) ;
if (ec)
return Error(ec, ERROR_LOCATION) ;
return Success() ;
}
示例6: connectDataCapture
core::Error DataCapture::connectDataCapture(
const core::FilePath& outputFolder,
const json::Object& chunkOptions)
{
return r::exec::RFunction(".rs.initDataCapture",
string_utils::utf8ToSystem(outputFolder.absolutePath()),
chunkOptions).call();
}
示例7: shellCommandForEngine
core::shell_utils::ShellCommand shellCommandForEngine(
const std::string& engine,
const core::FilePath& scriptPath)
{
core::shell_utils::ShellCommand command(engine);
command << core::string_utils::utf8ToSystem(scriptPath.absolutePathNative());
return command;
}
示例8: readStringFromFile
Error readStringFromFile(
const core::FilePath& filePath,
const Filter& filter,
std::string* pContents,
string_utils::LineEnding lineEnding=string_utils::LineEndingPassthrough)
{
try
{
// open the file stream (report errors with exceptions)
boost::shared_ptr<std::istream> pIfs;
Error error = filePath.open_r(&pIfs);
if (error)
return error;
pIfs->exceptions(std::istream::failbit | std::istream::badbit);
// output string stream (report errors with exceptions)
std::stringstream ostr;
ostr.exceptions(std::ostream::failbit | std::ostream::badbit);
// do the copy
boost::iostreams::filtering_ostream filteringOStream ;
filteringOStream.push(filter);
filteringOStream.push(ostr);
boost::iostreams::copy(*pIfs, filteringOStream, 128);
// return contents with requested line endings
*pContents = ostr.str();
string_utils::convertLineEndings(pContents, lineEnding);
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", filePath.absolutePath());
return error;
}
return Success();
}
示例9: writeCollectionToFile
Error writeCollectionToFile(
const core::FilePath& filePath,
const CollectionType& collection,
boost::function<std::string(
const typename CollectionType::value_type&)>
stringifyFunction)
{
using namespace boost::system::errc ;
// open the file stream
boost::shared_ptr<std::ostream> pOfs;
Error error = filePath.open_w(&pOfs, true);
if (error)
return error;
try
{
// write each line
for (typename CollectionType::const_iterator
it = collection.begin();
it != collection.end();
++it)
{
*pOfs << stringifyFunction(*it) << std::endl ;
if (pOfs->fail())
return systemError(io_error, ERROR_LOCATION);
}
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
error.addProperty("path", filePath.absolutePath());
return error;
}
return Success() ;
}
示例10: runTexCompile
core::Error runTexCompile(
const core::FilePath& texProgramPath,
const core::system::Options& envVars,
const core::shell_utils::ShellArgs& args,
const core::FilePath& texFilePath,
const boost::function<void(int,const std::string&)>& onExited)
{
return compile_pdf_supervisor::runProgram(
texProgramPath,
buildArgs(args, texFilePath),
envVars,
texFilePath.parent(),
ignoreOutput,
onExited);
}
示例11: connectDir
Error DirCapture::connectDir(const std::string& docId,
const core::FilePath& workingDir)
{
if (workingDir.exists())
{
// prefer manually specified working directory
workingDir_ = workingDir;
}
else
{
// no manually specified dir; use working directory to doc path, if it
// has one
std::string docPath;
source_database::getPath(docId, &docPath);
if (!docPath.empty())
{
workingDir_ = module_context::resolveAliasedPath(docPath).parent();
}
}
if (!workingDir_.empty())
{
// if we have a working directory, switch to it, and save directory we're
// changing from (so we can detect changes)
FilePath currentDir = FilePath::safeCurrentPath(workingDir_);
if (currentDir != workingDir_)
{
Error error = FilePath::makeCurrent(workingDir_.absolutePath());
if (error)
return error;
}
prevWorkingDir_ = currentDir.absolutePath();
}
NotebookCapture::connect();
return Success();
}
示例12: savePlotAsMetafile
Error PlotManager::savePlotAsMetafile(const core::FilePath& filePath,
int widthPx,
int heightPx)
{
#ifdef _WIN32
// calculate size in inches
double widthInches = pixelsToInches(widthPx);
double heightInches = pixelsToInches(heightPx);
// generate code for creating metafile device
boost::format fmt("{ require(grDevices, quietly=TRUE); "
" win.metafile(filename=\"%1%\", width=%2%, height=%3%, "
" restoreConsole=FALSE); }");
std::string deviceCreationCode = boost::str(fmt % string_utils::utf8ToSystem(filePath.absolutePath()) %
widthInches %
heightInches);
return savePlotAsFile(deviceCreationCode);
#else
return systemError(boost::system::errc::not_supported, ERROR_LOCATION);
#endif
}
示例13: escape
std::string escape(const ::core::FilePath &path)
{
return escape(string_utils::utf8ToSystem(path.absolutePath()));
}
示例14: start
void AsyncRProcess::start(const char* rCommand,
const core::FilePath& workingDir,
AsyncRProcessOptions rOptions)
{
// R binary
core::FilePath rProgramPath;
core::Error error = module_context::rScriptPath(&rProgramPath);
if (error)
{
LOG_ERROR(error);
onCompleted(EXIT_FAILURE);
return;
}
// args
std::vector<std::string> args;
args.push_back("--slave");
if (rOptions & R_PROCESS_VANILLA)
args.push_back("--vanilla");
args.push_back("-e");
args.push_back(rCommand);
// options
core::system::ProcessOptions options;
options.terminateChildren = true;
if (rOptions & R_PROCESS_REDIRECTSTDERR)
options.redirectStdErrToStdOut = true;
// if a working directory was specified, use it
if (!workingDir.empty())
{
options.workingDir = workingDir;
}
// forward R_LIBS so the child process has access to the same libraries
// we do
core::system::Options childEnv;
core::system::environment(&childEnv);
std::string libPaths = module_context::libPathsString();
if (!libPaths.empty())
{
core::system::setenv(&childEnv, "R_LIBS", libPaths);
options.environment = childEnv;
}
core::system::ProcessCallbacks cb;
using namespace module_context;
cb.onContinue = boost::bind(&AsyncRProcess::onContinue,
AsyncRProcess::shared_from_this());
cb.onStdout = boost::bind(&AsyncRProcess::onStdout,
AsyncRProcess::shared_from_this(),
_2);
cb.onStderr = boost::bind(&AsyncRProcess::onStderr,
AsyncRProcess::shared_from_this(),
_2);
cb.onExit = boost::bind(&AsyncRProcess::onProcessCompleted,
AsyncRProcess::shared_from_this(),
_1);
error = module_context::processSupervisor().runProgram(
rProgramPath.absolutePath(),
args,
options,
cb);
if (error)
{
LOG_ERROR(error);
onCompleted(EXIT_FAILURE);
}
else
{
isRunning_ = true;
}
}
示例15: readCollectionFromFile
Error readCollectionFromFile(
const core::FilePath& filePath,
CollectionType* pCollection,
boost::function<ReadCollectionAction(const std::string& line,
typename CollectionType::value_type* pValue)>
parseFunction,
bool trimAndIgnoreBlankLines=true)
{
using namespace boost::system::errc ;
// open the file stream
boost::shared_ptr<std::istream> pIfs;
Error error = filePath.open_r(&pIfs);
if (error)
return error;
// create insert iterator
std::insert_iterator<CollectionType> insertIterator(*pCollection,
pCollection->begin());
try
{
// read each line
std::string nextLine ;
while (true)
{
// read the next line
std::getline(*pIfs, nextLine) ;
if (pIfs->eof())
break;
else if (pIfs->fail())
return systemError(io_error, ERROR_LOCATION);
// trim whitespace then ignore it if it is a blank line
if (trimAndIgnoreBlankLines)
{
boost::algorithm::trim(nextLine) ;
if (nextLine.empty())
continue ;
}
// parse it and add it to the collection
typename CollectionType::value_type value ;
ReadCollectionAction action = parseFunction(nextLine, &value);
if (action == ReadCollectionAddLine)
{
*insertIterator++ = value ;
}
else if (action == ReadCollectionIgnoreLine)
{
// do nothing
}
else if (action == ReadCollectionTerminate)
{
break; // exit read loop
}
}
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
error.addProperty("path", filePath.absolutePath());
return error;
}
return Success() ;
}