本文整理汇总了C++中bfs::path::string方法的典型用法代码示例。如果您正苦于以下问题:C++ path::string方法的具体用法?C++ path::string怎么用?C++ path::string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bfs::path
的用法示例。
在下文中一共展示了path::string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copy_folder
void basics::copy_folder(const bfs::path& frompath, const bfs::path& topath)
{
// Check whether the function call is valid
if (!bfs::exists(frompath) || !bfs::is_directory(frompath)) {
std::stringstream err;
err << "Source directory " << frompath.string() << " does not exist or is not a directory.";
throw std::runtime_error(err.str());
}
if(bfs::exists(topath)) {
std::stringstream err;
err << "Destination directory " << topath.string() << " already exists.";
throw std::runtime_error(err.str());
}
// Create the destination directory
if(!bfs::create_directory(topath))
{
std::stringstream err;
err << "Unable to create destination directory " << topath.string();
throw std::runtime_error(err.str());
}
// Iterate through the source directory
for(bfs::directory_iterator file(frompath); file != bfs::directory_iterator(); ++file) {
bfs::path current(file->path());
if(bfs::is_directory(current)) {
// Found directory: Recursion
copy_folder(current, topath / current.filename());
}
else {
// Found file: Copy
bfs::copy_file(current, topath / current.filename());
}
}
}
示例2: saveToFile
void World::saveToFile(const bfs::path & path) const
{
Logger::get().debug("Сохранение объектов в файл %1%") % path.string();
json::Object jworld(json::Object::Hash);
// Local rect
{
b2AABB combinedAABB;
combinedAABB.lowerBound.Set( FLT_MAX, FLT_MAX);
combinedAABB.upperBound.Set(-FLT_MAX, -FLT_MAX);
for(const b2Body * b2body = getB2World()->GetBodyList(); b2body; b2body = b2body->GetNext())
{
const Body * body = static_cast<const Body *>(b2body->GetUserData());
if(body->isDynamic())
combinedAABB.Combine(body->getB2AABB());
}
jworld.add("aabb", Rectf::fromB2AABB(combinedAABB).toJson());
}
// Bodies
{
json::Object jentities(json::Object::Array);
for(auto it = getBodyIterator(); it; ++it)
if(it.get()->isDynamic())
jentities.add(it.get()->getEntity()->toJson());
jworld.add("entities", std::move(jentities));
}
std::ofstream file(path.string());
assert(file.good());
file << std::move(jworld.toString(false));
}
示例3: openBamFile
void BamReaderPool::openBamFile(const bfs::path& file) {
if (file.empty()) {
throw BamReaderPoolException("No BAM file specified.");
}
std::lock_guard<std::mutex> lock(poolmtx_); // GUARD
closeBamFile_nolock();
if (!open_) {
// try to open all readers
for (BamTools::BamReader& reader : readers_) {
if (!reader.Open(file.c_str())) {
throw BamReaderPoolException(
"Unable to open BAM file " + file.string() + ":\n\t"
+ reader.GetErrorString());
}
}
// try to open index
for (BamTools::BamReader& reader : readers_) {
if (!reader.LocateIndex()) {
throw BamReaderPoolException(
"Unable to open BAM index file " + file.string() + ":\n\t"
+ reader.GetErrorString());
}
}
// all are open, now push them onto the queue
for (BamTools::BamReader& reader : readers_) {
pushReader(reader);
}
file_ = file;
open_ = true;
} else {
throw BamReaderPoolException("Failed to close BAM reader pool.");
}
}
示例4: find
void find(const bfs::path& cdb_path, const options& opt)
{
config cfg = load_config(cdb_path / "config");
const bfs::path cdb_root = cdb_path.parent_path();
const bfs::path search_root = bfs::initial_path();
std::size_t prefix_size = 0;
std::string file_match;
if(opt.m_options.count("-a") == 0 && search_root != cdb_root)
{
file_match = "^" + escape_regex(
search_root.generic_string().substr(cdb_root.string().size() + 1) + "/") + ".*";
prefix_size = search_root.string().size() - cdb_root.string().size();
}
file_lock lock(cdb_path / "lock");
lock.lock_sharable();
const char* find_regex_options =
opt.m_options.count("-i") ? "i" : "";
const char* file_regex_options =
cfg.get_value("nocase-file-match") == "on" ? "i" : "";
bool trim = cfg.get_value("find-trim-ws") == "on";
unsigned thread_count = get_thread_count(cfg);
unsigned buffer_count = get_buffer_count(thread_count);
for(unsigned i = 0; i != opt.m_args.size(); ++i)
{
database_ptr db = open_database(cdb_path / "db");
std::string pattern = opt.m_args[i];
if(opt.m_options.count("-v"))
pattern = escape_regex(pattern);
mt_search mts(*db, trim, prefix_size, buffer_count);
auto worker = [&]
{
mts.search_db(compile_regex(pattern, 0, find_regex_options),
compile_regex(file_match, 0, file_regex_options));
};
boost::thread_group workers;
for(unsigned i = 0; i != thread_count-1; ++i)
workers.create_thread(worker);
worker();
workers.join_all();
}
}
示例5: generateRunInfo
void RunFolderGenerator::generateRunInfo() const
{
using boost::property_tree::ptree;
ptree pt;
pt.put("RunInfo.<xmlattr>.xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
pt.put("RunInfo.<xmlattr>.xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
pt.put("RunInfo.<xmlattr>.Version", "2");
pt.put("RunInfo.Run.<xmlattr>.Id", runFolder_);
pt.put("RunInfo.Run.<xmlattr>.Number", runInfo_.runNumber);
pt.put("RunInfo.Run.<xmlattr>.TileNameMethod", runInfo_.tileNameMethod);
ptree &run = pt.get_child("RunInfo.Run");
run.put("Flowcell", flowcell_);
run.put("Date", runFolderDate_);
run.put("FlowcellLayout.<xmlattr>.LaneCount", runInfo_.laneCount);
run.put("FlowcellLayout.<xmlattr>.SurfaceCount", runInfo_.surfaceCount);
run.put("FlowcellLayout.<xmlattr>.SwathCount", runInfo_.swathCount);
run.put("FlowcellLayout.<xmlattr>.TileCount", runInfo_.tileCount);
run.put("Reads", "");
ptree &reads = run.get_child("Reads");
int readNum = 1;
BOOST_FOREACH(const eagle::io::ReadDescription &rd, runInfo_.reads)
{
ptree read;
// Attributes for recent RunInfo.xml format
read.put("<xmlattr>.Number", readNum++);
read.put("<xmlattr>.IsIndexedRead", rd.isIndex?"Y":"N");
read.put("<xmlattr>.NumCycles", rd.lastCycle - rd.firstCycle + 1);
// Attributes for older RunInfo.xml format
read.put("<xmlattr>.FirstCycle", rd.firstCycle);
read.put("<xmlattr>.LastCycle", rd.lastCycle);
if (rd.isIndex)
{
read.put("Index", "");
}
reads.add_child("Read", read);
}
const boost::property_tree::xml_writer_settings<string> w(' ', 2);
const bfs::path runInfoPath = runFolderPath_ / "RunInfo.xml";
// DEBUG
std::clog << "Writing RunInfo file " << runInfoPath.string() << std::endl;
write_xml(runInfoPath.string(), pt, std::locale(), w);
}
示例6:
DistributedObject::DistributedObject(const bfs::path& file)
: persistence_enabled_(false),
path_(bfs::path()),
file_(!path_.string().empty() && !file.string().empty() ? (path_ / file) : bfs::path()),
timestamp_(0)
{
}
示例7: VideoAssetException
VideoAsset::VideoAsset(bfs::path videoFile, bfs::path path, bool copy) : path(path) {
try {
name = path.filename().string();
if(!bfs::exists(videoFile)) throw VideoAssetException("video File doesn't exist!");
if(!bfs::exists(path) || !bfs::is_directory(path)) throw VideoAssetException("Destination folder doesn't exist");
if(copy) {
video_path = path;
video_path /= videoFile.filename();
bfs::copy_file(videoFile, video_path, bfs::copy_option::overwrite_if_exists);
} else video_path = videoFile;
isExternal = !copy;
loadPlayerSync();
writeInfoFile();
hasTimetable = false;
hasShotBoundaries = false;
hasHistograms = false;
hasMeans = false;
isReady = false;
} catch (const bfs::filesystem_error& ex) {
(*Tobago.log)(Log::ERROR) << "Error creating video asset " << path.string() << ": " << ex.what();
throw VideoAssetException(ex.what());
}
}
示例8: create_file
void create_file(const bfs::path& ph, const string& contents)
{
ofstream f(ph.string().c_str());
if (!f)
throw bfs::filesystem_error("create_file", ph, error_code(errno, SYSTEMCATEGORY));
if (!contents.empty()) f << contents;
}
示例9: testDefaultTabHandler
void testDefaultTabHandler(const bfs::path& datafile)
{
const char* alphabet = "abcd";
const char* numbers = "1234";
TabReader tr;
VectorTabHandler vth;
tr.setHandler(&vth);
tr.process(datafile.string().c_str());
VectorTabHandler::const_iterator it = vth.begin();
cout << (* (*it).begin()) << endl;
size_t y=0;
for (; it != vth.end(); it++)
{
size_t x=0;
for (vector<string>::const_iterator it2=(*it).begin(); it2!=(*it).end();it2++)
{
const char* value = (*it2).c_str();
unit_assert(value[0] == alphabet[x]);
unit_assert(value[1] == numbers[y]);
x++;
}
cerr << endl;
y++;
}
}
示例10: expand_pathmask
PWIZ_API_DECL void expand_pathmask(const bfs::path& pathmask,
vector<bfs::path>& matchingPaths)
{
using bfs::path;
#ifdef WIN32
path maskParentPath = pathmask.branch_path();
WIN32_FIND_DATA fdata;
HANDLE srcFile = FindFirstFileEx(pathmask.string().c_str(), FindExInfoStandard, &fdata, FindExSearchNameMatch, NULL, 0);
if (srcFile == INVALID_HANDLE_VALUE)
return; // no matches
do
{
if (strcmp(fdata.cFileName, ".") != 0 &&
strcmp(fdata.cFileName, "..") != 0)
matchingPaths.push_back( maskParentPath / fdata.cFileName );
}
while (FindNextFile(srcFile, &fdata));
FindClose(srcFile);
#else
glob_t globbuf;
int rv = glob(pathmask.string().c_str(), 0, NULL, &globbuf);
if(rv > 0 && rv != GLOB_NOMATCH)
throw runtime_error("FindFilesByMask(): glob() error");
DIR* curDir = opendir(".");
struct stat curEntryData;
for (size_t i=0; i < globbuf.gl_pathc; ++i)
{
stat(globbuf.gl_pathv[i], &curEntryData);
if (S_ISDIR(curEntryData.st_mode) ||
S_ISREG(curEntryData.st_mode) ||
S_ISLNK(curEntryData.st_mode))
matchingPaths.push_back(globbuf.gl_pathv[i]);
}
closedir(curDir);
globfree(&globbuf);
#endif
}
示例11:
/**
* @brief Returns file type.
*
* Determinates file type based on its name.
*/
condor2nav::TPathType condor2nav::PathType(const bfs::path &fileName)
{
std::string str{fileName.string()};
if(str.size() > 2 && str[0] == '\\' && str[1] != '\\')
return TPathType::ACTIVE_SYNC;
else
return TPathType::LOCAL;
}
示例12: testMSIHandler
void testMSIHandler(const bfs::path& datafile)
{
TabReader tr;
MSIHandler mh;
tr.setHandler(&mh);
tr.process(datafile.string().c_str());
}
示例13: ConvertSound
void WiiPlatform::ConvertSound(bfs::path filename, SoundResource *obj)
{
std::ostringstream cmd;
cmd << this->GetName() << PLATFORM_PATH_SEPARATOR_STR << "sox ";
cmd << filename.string().c_str() << " -b 16 ";
cmd << obj->GetInputPath().string().c_str();
RUN_COMMAND(cmd);
}
示例14: request_new_project_path
bfs::path request_new_project_path( bfs::path default_path )
{
if( default_path.empty() )
default_path = path::DEFAULT_PROJECTS_DIR;
return bfs::path( QFileDialog::getExistingDirectory( nullptr
, QObject::tr("New AOS Designer Project Location")
, QString::fromStdString( default_path.string() )
).toStdString() );
}
示例15: loadFromFile
void World::loadFromFile(const bfs::path & path, const Vec2f & posModifier)
{
Logger::get().debug("Загрузка объектов из файла %1%") % path.string();
json::Parser jparser;
jparser.readFile(path.string());
const json::Object & jroot = jparser.getRoot();
// Local rect
Rectf aabb = Rectf::fromJson(jroot.get("aabb"));
// Entities
for(const json::Object & jentity : jroot.get("entities").getArray())
{
Entity * entity = Entity::fromJson(this, jentity);
entity->getBody()->setPos(
entity->getBody()->getPos() + Vec2f(-aabb.x + posModifier.x,
-aabb.y + posModifier.y));
}
}