当前位置: 首页>>代码示例>>C++>>正文


C++ core::FilePath类代码示例

本文整理汇总了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() ;
}
开发者ID:harupiko,项目名称:rstudio,代码行数:31,代码来源:FileSerializer.hpp

示例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;
}
开发者ID:Brackets,项目名称:rstudio,代码行数:10,代码来源:SessionBuild.cpp

示例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();
}
开发者ID:rlugojr,项目名称:rstudio,代码行数:10,代码来源:NotebookHtmlWidgets.cpp

示例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);
}
开发者ID:Brackets,项目名称:rstudio,代码行数:29,代码来源:SessionCompilePdfSupervisor.cpp

示例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() ;
}
开发者ID:Brackets,项目名称:rstudio,代码行数:35,代码来源:LocalStreamSocketUtils.hpp

示例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();
}
开发者ID:rstudio,项目名称:rstudio,代码行数:8,代码来源:NotebookData.cpp

示例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;
}
开发者ID:AlanCal,项目名称:rstudio,代码行数:10,代码来源:SessionExecuteChunkOperation.hpp

示例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();
}
开发者ID:jwpaulson,项目名称:rstudio,代码行数:42,代码来源:FileSerializer.hpp

示例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() ;
}
开发者ID:harupiko,项目名称:rstudio,代码行数:40,代码来源:FileSerializer.hpp

示例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);

}
开发者ID:dirkschumacher,项目名称:rstudio,代码行数:16,代码来源:SessionTexUtils.cpp

示例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();
}
开发者ID:dirkschumacher,项目名称:rstudio,代码行数:38,代码来源:NotebookWorkingDir.cpp

示例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
}
开发者ID:Bangjie,项目名称:rstudio,代码行数:23,代码来源:RGraphicsPlotManager.cpp

示例13: escape

std::string escape(const ::core::FilePath &path)
{
   return escape(string_utils::utf8ToSystem(path.absolutePath()));
}
开发者ID:howarthjw,项目名称:rstudio,代码行数:4,代码来源:PosixShellUtils.cpp

示例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;
}
}
开发者ID:James-Arnold,项目名称:rstudio,代码行数:73,代码来源:SessionAsyncRProcess.cpp

示例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() ;
}
开发者ID:harupiko,项目名称:rstudio,代码行数:69,代码来源:FileSerializer.hpp


注:本文中的core::FilePath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。