本文整理汇总了C++中boost::filesystem::path::parent_path方法的典型用法代码示例。如果您正苦于以下问题:C++ path::parent_path方法的具体用法?C++ path::parent_path怎么用?C++ path::parent_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::filesystem::path
的用法示例。
在下文中一共展示了path::parent_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
optional<unique_ref<fspp::Node>> CryDevice::Load(const bf::path &path) {
// TODO Split into smaller functions
ASSERT(path.is_absolute(), "Non absolute path given");
callFsActionCallbacks();
if (path.parent_path().empty()) {
//We are asked to load the base directory '/'.
return optional<unique_ref<fspp::Node>>(make_unique_ref<CryDir>(this, none, none, _rootKey));
}
auto parentWithGrandparent = LoadDirBlobWithParent(path.parent_path());
auto parent = std::move(parentWithGrandparent.blob);
auto grandparent = std::move(parentWithGrandparent.parent);
auto optEntry = parent->GetChild(path.filename().native());
if (optEntry == boost::none) {
return boost::none;
}
const auto &entry = *optEntry;
switch(entry.type()) {
case fspp::Dir::EntryType::DIR:
return optional<unique_ref<fspp::Node>>(make_unique_ref<CryDir>(this, std::move(parent), std::move(grandparent), entry.key()));
case fspp::Dir::EntryType::FILE:
return optional<unique_ref<fspp::Node>>(make_unique_ref<CryFile>(this, std::move(parent), std::move(grandparent), entry.key()));
case fspp::Dir::EntryType::SYMLINK:
return optional<unique_ref<fspp::Node>>(make_unique_ref<CrySymlink>(this, std::move(parent), std::move(grandparent), entry.key()));
}
ASSERT(false, "Switch/case not exhaustive");
}
示例2: getResourceDirPath
void getResourceDirPath(boost::filesystem::path& path)
{
#if defined(SQUIDGE_PLATFORM_MACOSX)
// Executable location is at 'Squidge.app/Contents/MacOS/Squidge'
// Resource directory is at 'Squidge.app/Contents/Resources'
getExecutablePath(path);
path = path.parent_path().parent_path();
path /= "Resources";
path = canonical(path);
#elif defined(SQUIDGE_PLATFORM_WINDOWS)
// Executable location is at '.../Squidge.exe'
// Resource directory is at '.../Resources'
getExecutablePath(path);
path = path.parent_path();
path /= "Resources";
path = canonical(path);
#else
#error No impl of getResourceDirPath on this platform!
#endif
}
示例3: checkSaveLoadInr
void ImageReaderWriterTest::checkSaveLoadInr( ::fwData::Image::sptr image )
{
// inr only support image origin (0,0,0)
::fwData::Image::OriginType origin(3,0);
image->setOrigin(origin);
// save image in inr
const ::boost::filesystem::path PATH = "imageInrTest/image.inr.gz";
::boost::filesystem::create_directories( PATH.parent_path() );
::fwItkIO::ImageWriter::sptr myWriter = ::fwItkIO::ImageWriter::New();
myWriter->setObject(image);
myWriter->setFile(PATH);
myWriter->write();
// load Image
::fwData::Image::sptr image2 = ::fwData::Image::New();
::fwItkIO::ImageReader::sptr myReader = ::fwItkIO::ImageReader::New();
myReader->setObject(image2);
myReader->setFile(PATH);
myReader->read();
::boost::filesystem::remove_all( PATH.parent_path().string() );
::fwItkIO::ut::helper::roundSpacing(image2);
::fwTest::helper::ExcludeSetType exclude;
exclude.insert("window_center");
exclude.insert("window_width");
// check Image
// inr only support float spacing and float origin => add tolerance for comparison (+/-0.00001)
CPPUNIT_ASSERT(::fwTest::helper::compare(image, image2, exclude));
}
示例4:
CLogger::CLogger(const std::string& name,
const boost::filesystem::path& logFilePath)
: m_name(name)
{
if (!boost::filesystem::exists(logFilePath.parent_path()))
boost::filesystem::create_directories(logFilePath.parent_path());
m_logFile.open(logFilePath.string(), std::ofstream::out | std::ofstream::app);
}
示例5: main
int main()
{
boost::filesystem::path const this_source_file = __FILE__;
boost::filesystem::path const test_includes_root =
this_source_file.parent_path();
boost::filesystem::path const sources_root = test_includes_root / "sources";
boost::filesystem::path const headers_root =
test_includes_root.parent_path() / "silicium";
std::string const linux_system_name = "linux";
std::string const windows_system_name = "win32";
std::string const current_system_name =
#ifdef _WIN32
windows_system_name
#else
linux_system_name
#endif
;
std::unordered_set<std::string> blacklist;
blacklist.insert(windows_system_name);
blacklist.insert(linux_system_name);
#ifdef _WIN32
blacklist.insert("posix");
#endif
blacklist.erase(current_system_name);
blacklist.insert("delegator");
auto const is_relevant_directory =
[&blacklist](boost::filesystem::path const &dir)
{
return blacklist.count(dir.leaf().string()) == 0;
};
std::set<std::string> all_headers;
auto const add_header = [&all_headers](std::string const &header_name)
{
// sort the headers by name for a deterministic ordering
all_headers.insert(header_name);
};
generate_sources_recursively(
sources_root, headers_root, "", is_relevant_directory, add_header);
auto const all_headers_file_name =
sources_root / current_system_name / "_all_headers_.cpp";
std::ofstream all_headers_file(all_headers_file_name.string());
if (!all_headers_file)
{
throw std::runtime_error("Cannot open file " +
all_headers_file_name.string());
}
for (std::string const &header_name : all_headers)
{
all_headers_file << "#include " << header_name << '\n';
}
}
示例6: treeA
TEST (PCL, Outofcore_Octree_Build)
{
boost::filesystem::remove_all (filename_otreeA.parent_path ());
boost::filesystem::remove_all (filename_otreeB.parent_path ());
Eigen::Vector3d min (-32.0, -32.0, -32.0);
Eigen::Vector3d max (32.0, 32.0, 32.0);
// Build two trees using each constructor
// depth of treeA will be same as B because 1/2^3 > .1 and 1/2^4 < .1
// depth really affects performance
octree_disk treeA (min, max, .1, filename_otreeA, "ECEF");
octree_disk treeB (4, min, max, filename_otreeB, "ECEF");
// Equidistributed uniform pseudo-random number generator
boost::mt19937 rng(rngseed);
// For testing sparse
//boost::uniform_real<double> dist(0,1);
// For testing less sparse
boost::normal_distribution<float> dist (0.5f, .1f);
// Create a point
PointT p;
points.resize (numPts);
//ignore these fields from the UR point for now
// p.r = p.g = p.b = 0;
// p.nx = p.ny = p.nz = 1;
// p.cameraCount = 0;
// p.error = 0;
// p.triadID = 0;
// Radomize it's position in space
for (size_t i = 0; i < numPts; i++)
{
p.x = dist (rng);
p.y = dist (rng);
p.z = dist (rng);
points[i] = p;
}
// Add to tree
treeA.addDataToLeaf (points);
// Add to tree
treeB.addDataToLeaf (points);
}
示例7: cleanUpFilesystem
void cleanUpFilesystem ()
{
//clear existing trees from test path
boost::filesystem::remove_all (filename_otreeA.parent_path ());
boost::filesystem::remove_all (filename_otreeB.parent_path ());
boost::filesystem::remove_all (filename_otreeA_LOD.parent_path ());
boost::filesystem::remove_all (filename_otreeB_LOD.parent_path ());
boost::filesystem::remove_all (outofcore_path.parent_path ());
}
示例8: listInAbsoluteDirectory
inline Status listInAbsoluteDirectory(const fs::path& path,
std::vector<std::string>& results,
GlobLimits limits) {
if (path.filename() == "*" && !pathExists(path.parent_path())) {
return Status(1, "Directory not found: " + path.parent_path().string());
}
if (path.filename() == "*" && !isDirectory(path.parent_path())) {
return Status(1, "Path not a directory: " + path.parent_path().string());
}
genGlobs(path.string(), results, limits);
return Status(0, "OK");
}
示例9: findRepository
bool RLogMill::findRepository(boost::filesystem::path& dir, std::string& log_format) {
dir = absolute(dir);
//fprintf(stderr, "find repository from initial path: %s\n", dir.string().c_str());
while(is_directory(dir)) {
if(is_directory(dir / ".git")) log_format = "git";
else if(is_directory(dir / ".hg")) log_format = "hg";
else if(is_directory(dir / ".bzr")) log_format = "bzr";
else if(is_directory(dir / ".svn")) log_format = "svn";
if(!log_format.empty()) {
//fprintf(stderr, "found '%s' repository at: %s\n", log_format.c_str(), dir.string().c_str());
return true;
}
if(!dir.has_parent_path()) return false;
dir = dir.parent_path();
}
return false;
}
示例10: runtime_error
boost::filesystem::path readlink(const boost::filesystem::path&
#ifndef BOOST_WINDOWS_API
path
#endif
)
{
#ifdef BOOST_WINDOWS_API
throw std::runtime_error("readlink() not implemented on Windows");
#else
string link(path.external_file_string());
vector<char> buf(512);
for (;;)
{
const ssize_t len = readlink(link.c_str(), &buf[0], buf.size());
if (len == -1)
{
if (errno == ENAMETOOLONG)
{
buf.resize(2 * buf.size());
continue;
}
throw system_error(error_code(errno, get_system_category()));
}
return path.parent_path() / string(&buf[0], len);
}
#endif
}
示例11: create
void File::create() const {
const boost::filesystem::path abs = boost::filesystem::absolute(path);
const boost::filesystem::path dir = abs.parent_path();
createDirectories(dir);
mknod();
chown();
}
示例12: rename
void CryNode::rename(const bf::path &to) {
device()->callFsActionCallbacks();
if (_parent == none) {
//We are the root direcory.
throw FuseErrnoException(EBUSY);
}
auto targetDirWithParent = _device->LoadDirBlobWithParent(to.parent_path());
auto targetDir = std::move(targetDirWithParent.blob);
auto targetDirParent = std::move(targetDirWithParent.parent);
auto old = (*_parent)->GetChild(_key);
if (old == boost::none) {
throw FuseErrnoException(EIO);
}
fsblobstore::DirEntry oldEntry = *old; // Copying this (instead of only keeping the reference) is necessary, because the operations below (i.e. RenameChild()) might make a reference invalid.
auto onOverwritten = [this] (const blockstore::Key &key) {
device()->RemoveBlob(key);
};
_updateParentModificationTimestamp();
if (targetDir->key() == (*_parent)->key()) {
targetDir->RenameChild(oldEntry.key(), to.filename().native(), onOverwritten);
} else {
_updateTargetDirModificationTimestamp(*targetDir, std::move(targetDirParent));
targetDir->AddOrOverwriteChild(to.filename().native(), oldEntry.key(), oldEntry.type(), oldEntry.mode(), oldEntry.uid(), oldEntry.gid(),
oldEntry.lastAccessTime(), oldEntry.lastModificationTime(), onOverwritten);
(*_parent)->RemoveChild(oldEntry.name());
// targetDir is now the new parent for this node. Adapt to it, so we can call further operations on this node object.
_parent = cpputils::to_unique_ptr(std::move(targetDir));
}
}
示例13: extract
bool ZipArchive::extract(boost::filesystem::path from, boost::filesystem::path where, std::vector<std::string> what)
{
unzFile archive = unzOpen2_64(from.c_str(), FileStream::GetMinizipFilefunc());
auto onExit = vstd::makeScopeGuard([&]()
{
unzClose(archive);
});
for (const std::string & file : what)
{
if (unzLocateFile(archive, file.c_str(), 1) != UNZ_OK)
return false;
const boost::filesystem::path fullName = where / file;
const boost::filesystem::path fullPath = fullName.parent_path();
boost::filesystem::create_directories(fullPath);
// directory. No file to extract
// TODO: better way to detect directory? Probably check return value of unzOpenCurrentFile?
if (boost::algorithm::ends_with(file, "/"))
continue;
FileStream destFile(fullName, std::ios::out | std::ios::binary);
if (!destFile.good())
return false;
if (!extractCurrent(archive, destFile))
return false;
}
return true;
}
示例14: createAndOpenFile
int FilesystemImpl::createAndOpenFile(const bf::path &path, mode_t mode, uid_t uid, gid_t gid) {
PROFILE(_createAndOpenFileNanosec);
auto dir = LoadDir(path.parent_path());
PROFILE(_createAndOpenFileNanosec_withoutLoading);
auto file = dir->createAndOpenFile(path.filename().native(), mode, uid, gid);
return _open_files.open(std::move(file));
}
示例15: ParseException
static std::string
loadFile (boost::property_tree::ptree &config,
const boost::filesystem::path &file)
{
boost::filesystem::path extension = file.extension();
boost::filesystem::path extension2 = file.stem().extension();
std::string fileName = file.filename().string();
boost::property_tree::ptree readConfig;
if (extension2.string() == ".conf") {
if (extension.string() == ".json") {
boost::property_tree::read_json (file.string(), readConfig);
} else if (extension.string() == ".info") {
boost::property_tree::read_info (file.string(), readConfig);
} else if (extension.string() == ".ini") {
boost::property_tree::read_ini (file.string(), readConfig);
} else if (extension.string() == ".xml") {
boost::property_tree::read_xml (file.string(), readConfig);
} else {
throw ParseException ("Unknonw file format");
}
} else {
throw ParseException ("Unknonw file format");
}
mergePropertyTrees (config, readConfig);
config.put ("configPath", file.parent_path().string() );
fileName = fileName.substr (0, fileName.size() - extension.string().size() );
fileName = fileName.substr (0, fileName.size() - extension2.string().size() );
return fileName;
}