本文整理汇总了C++中boost::filesystem::path::branch_path方法的典型用法代码示例。如果您正苦于以下问题:C++ path::branch_path方法的具体用法?C++ path::branch_path怎么用?C++ path::branch_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::filesystem::path
的用法示例。
在下文中一共展示了path::branch_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClearEmptyParents
void TorrentFilesModel::ClearEmptyParents (boost::filesystem::path path)
{
const auto pos = Path2Node_.find (path);
if (pos == Path2Node_.end ())
{
qWarning () << Q_FUNC_INFO
<< "unknown path"
<< path.c_str ();
return;
}
const auto& node = pos->second;
if (!node->IsEmpty ())
{
UpdateSizeGraph (RootNode_);
return;
}
const auto& parentNode = node->GetParent ();
const auto nodeRow = node->GetRow ();
const auto& parentIndex = FindIndex (path.branch_path ());
beginRemoveRows (parentIndex, nodeRow, nodeRow);
parentNode->EraseChild (parentNode->begin () + nodeRow);
Path2Node_.erase (pos);
endRemoveRows ();
ClearEmptyParents (path.branch_path ());
}
示例2: _createDirectories
static void _createDirectories(Transport::Config *config, boost::filesystem::path ph) {
if (ph.empty() || exists(ph)) {
return;
}
// First create branch, by calling ourself recursively
_createDirectories(config, ph.branch_path());
// Now that parent's path exists, create the directory
boost::filesystem::create_directory(ph);
#ifndef WIN32
if (!CONFIG_STRING(config, "service.group").empty() && !CONFIG_STRING(config, "service.user").empty()) {
struct group *gr;
if ((gr = getgrnam(CONFIG_STRING(config, "service.group").c_str())) == NULL) {
std::cerr << "Invalid service.group name " << CONFIG_STRING(config, "service.group") << "\n";
}
struct passwd *pw;
if ((pw = getpwnam(CONFIG_STRING(config, "service.user").c_str())) == NULL) {
std::cerr << "Invalid service.user name " << CONFIG_STRING(config, "service.user") << "\n";
}
chown(ph.string().c_str(), pw->pw_uid, gr->gr_gid);
}
#endif
}
示例3: create_parents
void create_parents( const fs::path &dpath )
{
string err( "create_parent(): " );
fs::path branch( dpath.branch_path() );
string who("create_parents");
if( dpath.empty() ) {
err.append( "cannot create an empty path." );
throw CannotCreateParents( err );
}
else if( !exists(dpath) ) {
if( branch.empty() ) create_directory( dpath );
else if( !exists(branch) ) {
create_parents( branch );
create_directory( dpath );
}
else if( is_directory(branch) ) create_directory( dpath );
else {
err.append( branch.native_file_string() ); err.append( " is not a directory." );
throw CannotCreateParents( err );
}
}
else if( !is_directory(dpath) ) {
err.append( dpath.native_file_string() ); err.append( " is not a directory." );
throw CannotCreateParents( err );
}
return;
}
示例4: parent
inline SAGA_EXPORT std::string parent(boost::filesystem::path const& p)
{
#if BOOST_VERSION >= 103600
return p.parent_path().string();
#else
return p.branch_path().string();
#endif
}
示例5: while
//! get the relative file path from the host directory
static std::string get_rel_file_path(const fs::path &file){
fs::path abs_path = file.branch_path();
fs::path rel_path = file.leaf();
while (not abs_path.empty() and abs_path.leaf() != "host"){
rel_path = abs_path.leaf() / rel_path;
abs_path = abs_path.branch_path();
}
return rel_path.string();
}
示例6: correctPathCase
fs::path correctPathCase(fs::path Path) {
using namespace boost::filesystem;
#ifndef CASE_SENSITIVE_FILESYSTEM
if (!exists(Path))
return path();
return Path;
#else
// If the path is OK as it stands, do nothing.
if (exists(Path)) return Path;
// If the path doesn't seem to be OK, track backwards through it
// looking for the point at which the problem first arises. Path
// will contain the parts of the path that exist on the current
// filesystem, and pathElts will contain the parts after that point,
// which may have incorrect case.
stack<string> pathElts;
while (!Path.empty() && !exists(Path)) {
pathElts.push(Path.filename().string());
Path = Path.branch_path();
}
// Now proceed forwards through the possibly-incorrect elements.
while (!pathElts.empty()) {
// Does this element need to be a directory?
// (If we are searching for /foo/bar/baz, and /foo contains a file
// bar and a directory Bar, then we need to know which is the one
// we're looking for. This will still be unreliable if /foo
// contains directories bar and Bar, but a full backtracking
// search would be complicated; for now this should be adequate!)
const bool needDir = pathElts.size() > 1;
string elt(pathElts.top());
pathElts.pop();
// Does this element exist?
if (exists(Path/elt) && (!needDir || is_directory(Path/elt))) {
// If so, use it.
Path /= elt;
} else {
// If not, search for a suitable candidate.
to_upper(elt);
directory_iterator end;
bool found = false;
for (directory_iterator dir(Path); dir != end; ++dir) {
string uleaf = dir->path().filename().string();
to_upper(uleaf);
if (uleaf == elt && (!needDir || is_directory(*dir))) {
Path /= dir->path().filename();
found = true;
break;
}
}
if (!found) return "";
}
}
return Path.string();
#endif
}
示例7: ensureParentDirCreated
boost::filesystem::path ensureParentDirCreated(const boost::filesystem::path& p) {
const boost::filesystem::path parent = p.branch_path();
if (!boost::filesystem::exists(parent)) {
ensureParentDirCreated(parent);
log() << "creating directory " << parent.string() << endl;
boost::filesystem::create_directory(parent);
flushMyDirectory(parent); // flushes grandparent to ensure parent exists after crash
}
verify(boost::filesystem::is_directory(parent));
return parent;
}
示例8: flushMyDirectory
void flushMyDirectory(const boost::filesystem::path& file) {
#ifdef __linux__ // this isn't needed elsewhere
static bool _warnedAboutFilesystem = false;
// if called without a fully qualified path it asserts; that makes mongoperf fail.
// so make a warning. need a better solution longer term.
// massert(13652, str::stream() << "Couldn't find parent dir for file: " << file.string(),);
if (!file.has_branch_path()) {
log() << "warning flushMyDirectory couldn't find parent dir for file: "
<< file.string();
return;
}
boost::filesystem::path dir = file.branch_path(); // parent_path in new boosts
LOG(1) << "flushing directory " << dir.string();
int fd = ::open(dir.string().c_str(), O_RDONLY); // DO NOT THROW OR ASSERT BEFORE CLOSING
massert(13650, str::stream() << "Couldn't open directory '" << dir.string()
<< "' for flushing: " << errnoWithDescription(),
fd >= 0);
if (fsync(fd) != 0) {
int e = errno;
if (e == EINVAL) { // indicates filesystem does not support synchronization
if (!_warnedAboutFilesystem) {
log() << "\tWARNING: This file system is not supported. For further information"
<< " see:"
<< startupWarningsLog;
log() << "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems"
<< startupWarningsLog;
log() << "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated "
<< "this warning." << startupWarningsLog;
_warnedAboutFilesystem = true;
}
}
else {
close(fd);
massert(13651, str::stream() << "Couldn't fsync directory '" << dir.string()
<< "': " << errnoWithDescription(e),
false);
}
}
close(fd);
#endif
}
示例9: handleFileRenamed
void TorrentFilesModel::handleFileRenamed (int torrent, int file, const QString& newName)
{
if (torrent != Index_)
return;
const auto filePos = std::find_if (Path2Node_.begin (), Path2Node_.end (),
[file] (const Path2Node_t::value_type& pair)
{ return pair.second->FileIndex_ == file; });
if (filePos == Path2Node_.end ())
{
qWarning () << Q_FUNC_INFO
<< "unknown file index"
<< file
<< "for torrent"
<< torrent
<< "was renamed to"
<< newName;
return;
}
const auto node = filePos->second;
ClearEmptyParents (filePos->first);
const boost::filesystem::path newPath { newName.toUtf8 ().constData () };
const auto& parentNode = MkParentIfDoesntExist (newPath, true);
node->Name_ = QString::fromUtf8 (newPath.leaf ().string ().c_str ());
node->Reparent (parentNode);
beginInsertRows (FindIndex (newPath.branch_path ()), parentNode->GetRowCount (), parentNode->GetRowCount ());
Path2Node_ [newPath] = node;
parentNode->AppendExisting (node);
endInsertRows ();
UpdateSizeGraph (RootNode_);
}
示例10: lib_file
/**
* Non-Windows shared library constructor. This ensures that the environment
* variable \c TWEEK_BASE_DIR is set as soon as this shared library is loaded.
* If it is not set, then it sets it based on an assumption about the
* structure of a Tweek installation. More specifically, an assumption is made
* that this shared library lives in the \c lib subdirectory of the Tweek
* installation. Therefore, the root of the Tweek installation is the parent
* of the directory containing this shared library.
*/
extern "C" void __attribute ((constructor)) tweekLibraryInit()
{
fs::path base_dir;
const char* env_dir = std::getenv("TWEEK_BASE_DIR");
// If TWEEK_BASE_DIR is not set, look up the path to this shared library
// and use it to provide a default setting for that environment variable.
if ( NULL == env_dir )
{
Dl_info info;
info.dli_fname = 0;
const int result =
#if defined(__GNUC__) && __GNUC_MAJOR__ < 4
dladdr((void*) &tweekLibraryInit, &info);
#else
dladdr(reinterpret_cast<void*>(&tweekLibraryInit), &info);
#endif
// NOTE: dladdr(3) really does return a non-zero value on success.
if ( 0 != result )
{
try
{
fs::path lib_file(info.dli_fname, fs::native);
lib_file = fs::system_complete(lib_file);
#if defined(VPR_OS_IRIX) && defined(_ABIN32)
const std::string bit_suffix("32");
#elif defined(VPR_OS_IRIX) && defined(_ABI64) || \
defined(VPR_OS_Linux) && defined(__x86_64__)
const std::string bit_suffix("64");
#else
const std::string bit_suffix("");
#endif
// Get the directory containing this shared library.
const fs::path lib_path = lib_file.branch_path();
// Start the search for the root of the Tweek installation in the
// parent of the directory containing this shared library.
base_dir = lib_path.branch_path();
// Use the lib subdirectory to figure out when we have found the
// root of the Tweek installation tree.
const fs::path lib_subdir(std::string("lib") + bit_suffix);
bool found(false);
while ( ! found && ! base_dir.empty() )
{
try
{
if ( ! fs::exists(base_dir / lib_subdir) )
{
base_dir = base_dir.branch_path();
}
else
{
found = true;
}
}
catch (fs::filesystem_error&)
{
base_dir = base_dir.branch_path();
}
}
if ( found )
{
setenv("TWEEK_BASE_DIR",
base_dir.native_directory_string().c_str(), 1);
}
}
catch (fs::filesystem_error& ex)
{
std::cerr << "Automatic assignment of TWEEK_BASE_DIR failed:\n"
<< ex.what() << std::endl;
}
}
}
else
{
try
{
base_dir = fs::path(env_dir, fs::native);
}
catch (fs::filesystem_error& ex)
{
std::cerr << "Invalid path set in TWEEK_BASE_DIR environment "
<< "variable:\n" << ex.what() << std::endl;
}
}
//.........这里部分代码省略.........
示例11:
inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
{
return p.branch_path();
}
示例12: doc
//.........这里部分代码省略.........
for (match_result_vec_t::iterator i = results.begin();
results.end() != i;
++i, ++idx)
{
i->number = idx;
BiobaseTablePssmEntry * pssm_entry = BiobaseDb::singleton().get_pssm_entry(i->link);
assert((size_t) i->result.position < seq.size());
if (min_threshold <= i->result.score)
{
const bool is_in_max_chain =
0 != max_chain
&&
max_chain->end() != std::find_if( max_chain->begin(), max_chain->end(), std::bind1st( detail::hit_is_same(), *i ) );
doc.add_result(
i->result,
*pssm_entry,
idx,
is_in_max_chain );
++num_added;
}
}
if (0 == num_added)
{
throw std::logic_error( "No hits above threshold" );
}
factor_scores_map_t factors;
find_factors_for_matches(results, factors);
//cout << factors.size() << " factors associated with these matches" << std::endl;
//for each factor - in score order
while (! factors.empty() && 0 != max_num_factors--)
{
//find the factor with the highest score
factor_scores_map_t::iterator best = factors.end();
for (factor_scores_map_t::iterator f = factors.begin();
factors.end() != f;
++f)
{
if (factors.end() == best || f->second.score > best->second.score)
{
best = f;
}
}
assert(best != factors.end());
Factor * factor = BiobaseDb::singleton().get_entry<FACTOR_DATA>(best->first);
if (0 != factor)
{
doc.add_factor(factor, best->second.hits);
}
factors.erase(best);
}
if( notes.size() )
{
doc.add_notes( notes );
}
add_tooltip_support(doc.doc, doc.doc_root);
dom_print(doc.doc, file._BOOST_FS_NATIVE().c_str());
//copy the script to the same directory
try
{
fs::path script(BioEnvironment::singleton().get_svg_script_file());
fs::path script_dest(file.branch_path());
script_dest /= script.leaf();
//only copy if destination older
if (! fs::exists(script_dest) || fs::last_write_time(script) > fs::last_write_time(script_dest))
{
//remove first if exists
if (fs::exists(script_dest))
{
fs::remove(script_dest);
}
fs::copy_file(script, script_dest);
}
}
catch (const std::exception & ex)
{
cerr << ex.what() << endl;
}
XMLPlatformUtils::Terminate();
if (open)
{
open_file(file);
}
}
示例13: process_ipp_file
void process_ipp_file(const fs::path& file, bool positive_test)
{
std::cout << "Info: Scanning file: " << file.string() << std::endl;
// our variables:
std::string file_text;
std::string macro_name;
std::string namespace_name;
fs::path positive_file;
fs::path negative_file;
// load the file into memory so we can scan it:
fs::ifstream ifs(file);
std::copy(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>(), std::back_inserter(file_text));
ifs.close();
// scan for the macro name:
boost::regex macro_regex("//\\s*MACRO\\s*:\\s*(\\w+)");
boost::smatch macro_match;
if(boost::regex_search(file_text, macro_match, macro_regex))
{
macro_name = macro_match[1];
macro_list.insert(macro_name);
namespace_name = boost::regex_replace(file_text, macro_regex, "\\L$1", boost::format_first_only | boost::format_no_copy);
}
if(macro_name.empty())
{
std::cout << "Error: no macro definition found in " << file.string();
}
else
{
std::cout << "Info: Macroname: " << macro_name << std::endl;
}
// get the output filesnames:
boost::regex file_regex("boost_([^.]+)\\.ipp");
positive_file = file.branch_path() / boost::regex_replace(file.leaf().string(), file_regex, "$1_pass.cpp");
negative_file = file.branch_path() / boost::regex_replace(file.leaf().string(), file_regex, "$1_fail.cpp");
write_test_file(positive_file, macro_name, namespace_name, file.leaf().string(), positive_test, true);
write_test_file(negative_file, macro_name, namespace_name, file.leaf().string(), positive_test, false);
// always create config_test data,
// positive and negative tests go to separate streams, because for some
// reason some compilers choke unless we put them in a particular order...
std::ostream* pout = positive_test ? &config_test1a : &config_test1;
*pout << "#if";
if(!positive_test)
*pout << "n";
*pout << "def " << macro_name
<< "\n#include \"" << file.leaf().string() << "\"\n#else\nnamespace "
<< namespace_name << " = empty_boost;\n#endif\n";
config_test2 << " if(0 != " << namespace_name << "::test())\n"
" {\n"
" std::cerr << \"Failed test for " << macro_name << " at: \" << __FILE__ << \":\" << __LINE__ << std::endl;\n"
" ++error_count;\n"
" }\n";
// always generate the jamfile data:
jamfile << "test-suite \"" << macro_name << "\" : \n"
"[ run " << positive_file.leaf().string() << " <template>config_options ]\n"
"[ compile-fail " << negative_file.leaf().string() << " <template>config_options ] ;\n";
jamfile_v2 << "test-suite \"" << macro_name << "\" : \n"
"[ run ../" << positive_file.leaf().string() << " ]\n"
"[ compile-fail ../" << negative_file.leaf().string() << " ] ;\n";
// Generate data for the Build-checks test file:
build_config_test << "#ifdef TEST_" << macro_name << std::endl;
build_config_test << "# include \"../test/" << file.leaf().string() << "\"\n";
build_config_test << "namespace test = " << namespace_name << ";\n#endif\n";
// Generate data for the build-checks Jamfile:
static const boost::regex feature_regex("boost_(?:no|has)_(.*)");
std::string feature_name = boost::regex_replace(namespace_name, feature_regex, "\\1");
build_config_jamfile << "run-simple test_case.cpp : : : <define>TEST_" << macro_name << " : " << feature_name << " ;\n";
build_config_jamfile << "alias " << feature_name << " : " << feature_name << ".output ;\n";
build_config_jamfile << "explicit " << feature_name << " ;\n";
}
示例14: result
std::pair<const char*, bool> alert(const char* message_text,
const char* window_name,
const char* button_0_name,
const char* button_1_name,
const char* button_2_name,
const char* checkbox_name,
const boost::filesystem::path& icon_path,
std::size_t default_button_index,
std::size_t cancel_button_index)
{
if ((button_0_name || button_1_name || button_2_name) == false)
return std::make_pair<const char*, bool>(0, false);
std::stringstream sheet;
std::stringstream layout;
boost::filesystem::path icon_directory_path;
// The sheet for the alert dialog
sheet <<
"sheet alert_sheet\n"
"{\n"
"interface:\n"
" checkbox_value: false;\n"
"output:\n"
" result <== { checkbox_value: checkbox_value };\n"
"}\n"
;
// Start by filling out the header for the layout of the alert
layout <<
"layout alert_layout\n"
"{\n"
" view dialog(name: '" << window_name << "', placement: place_row, spacing: 10)\n"
" {\n";
if (icon_path != boost::filesystem::path())
{
icon_directory_path = icon_path.branch_path();
layout <<
" label_t(image: '" << icon_path.leaf() << "')\n"
;
}
layout <<
" column()\n"
" {\n"
" static_text(name:'" << message_text << "', horizontal: align_fill, characters: 25);\n"
;
// add the checkbox if we have a name for one
if (checkbox_name)
{
layout <<
"checkbox(name: '" << checkbox_name << "', bind: @checkbox_value);\n"
;
}
// add the button set
layout <<
"row(horizontal: align_right)\n"
"{\n"
;
// add the buttons in *reverse* order, so the first is rightmost
append_button_to_layout(layout, button_2_name, 2, default_button_index == 2, cancel_button_index == 2);
append_button_to_layout(layout, button_1_name, 1, default_button_index == 1, cancel_button_index == 1);
append_button_to_layout(layout, button_0_name, 0, default_button_index == 0, cancel_button_index == 0);
// close out the rest of the layout
layout <<
" }\n" // row
" }\n" // column
" }\n" // dialog
"}\n" // layout
;
// finally set up the params for the modal dialog interface call
dialog_result_t result(handle_dialog(dictionary_t(),
dictionary_t(),
dictionary_t(),
dialog_display_s,
layout,
sheet,
&always_break,
icon_directory_path));
bool is_checked(get_value(result.command_m, static_name_t("checkbox_value")).cast<bool>());
// NOTE (fbrereto) : Here is why we require the name of the action to be "bN", where N is the index
std::size_t index(std::atoi(&result.terminating_action_m.c_str()[1]));
if (index == 0)
return std::make_pair(button_0_name, is_checked);
else if (index == 1)
return std::make_pair(button_1_name, is_checked);
return std::make_pair(button_2_name, is_checked);
}
示例15: drillDown
void drillDown( boost::filesystem::path root,
bool use_db,
bool use_coll,
bool oplogReplayLimit,
bool top_level=false) {
bool json_metadata = false;
LOG(2) << "drillDown: " << root.string() << endl;
// skip hidden files and directories
if (root.leaf()[0] == '.' && root.leaf() != ".")
return;
if ( is_directory( root ) ) {
boost::filesystem::directory_iterator end;
boost::filesystem::directory_iterator i(root);
boost::filesystem::path indexes;
while ( i != end ) {
boost::filesystem::path p = *i;
i++;
if (use_db) {
if (boost::filesystem::is_directory(p)) {
error() << "ERROR: root directory must be a dump of a single database" << endl;
error() << " when specifying a db name with --db" << endl;
printHelp(cout);
return;
}
}
if (use_coll) {
if (boost::filesystem::is_directory(p) || i != end) {
error() << "ERROR: root directory must be a dump of a single collection" << endl;
error() << " when specifying a collection name with --collection" << endl;
printHelp(cout);
return;
}
}
// don't insert oplog
if (top_level && !use_db && p.leaf() == "oplog.bson")
continue;
if ( p.leaf() == "system.indexes.bson" ) {
indexes = p;
} else {
drillDown(p, use_db, use_coll, oplogReplayLimit);
}
}
if (!indexes.empty() && !json_metadata) {
drillDown(indexes, use_db, use_coll, oplogReplayLimit);
}
return;
}
if ( endsWith( root.string().c_str() , ".metadata.json" ) ) {
// Metadata files are handled when the corresponding .bson file is handled
return;
}
if ( ! ( endsWith( root.string().c_str() , ".bson" ) ||
endsWith( root.string().c_str() , ".bin" ) ) ) {
error() << "don't know what to do with file [" << root.string() << "]" << endl;
return;
}
log() << root.string() << endl;
if ( root.leaf() == "system.profile.bson" ) {
log() << "\t skipping" << endl;
return;
}
string ns;
if (use_db) {
ns += _db;
}
else {
string dir = root.branch_path().string();
if ( dir.find( "/" ) == string::npos )
ns += dir;
else
ns += dir.substr( dir.find_last_of( "/" ) + 1 );
if ( ns.size() == 0 )
ns = "test";
}
verify( ns.size() );
string oldCollName = root.leaf(); // Name of the collection that was dumped from
oldCollName = oldCollName.substr( 0 , oldCollName.find_last_of( "." ) );
if (use_coll) {
ns += "." + _coll;
}
else {
ns += "." + oldCollName;
}
//.........这里部分代码省略.........