本文整理汇总了C++中boost::filesystem::path::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ path::begin方法的具体用法?C++ path::begin怎么用?C++ path::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::filesystem::path
的用法示例。
在下文中一共展示了path::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: p
TEST_F(PathTest, root_parent)
{
const fs::path p("/");
{
int i = 0;
for (auto it = p.begin(); it != p.end(); ++it)
{
++i;
}
EXPECT_EQ(1, i);
}
const fs::path q(p.parent_path());
{
int i = 0;
for (auto it = q.begin(); it != q.end(); ++it)
{
++i;
}
EXPECT_EQ(0, i);
}
}
示例2: move
static boost::filesystem::path path_sub(const boost::filesystem::path& lft, const boost::filesystem::path& rht)
{
boost::filesystem::path::iterator lft_itr = lft.begin();
boost::filesystem::path::iterator lft_end = lft.end();
boost::filesystem::path::iterator rht_itr = rht.begin();
boost::filesystem::path::iterator rht_end = rht.end();
while ((lft_itr != lft_end) && (rht_itr != rht_end))
{
if (*lft_itr != *rht_itr)
{
break;
}
++lft_itr;
++rht_itr;
}
boost::filesystem::path result;
for (; lft_itr != lft_end; ++lft_itr)
{
result /= *lft_itr;
}
return std::move(result);
}
示例3: naive_uncomplete
boost::filesystem::path naive_uncomplete(boost::filesystem::path const path,
boost::filesystem::path const base) {
if (path.has_root_path()){
if (path.root_path() != base.root_path()) {
return path;
} else {
return naive_uncomplete(path.relative_path(), base.relative_path());
}
} else {
if (base.has_root_path()) {
throw "cannot uncomplete a path relative path from a rooted base";
} else {
typedef boost::filesystem::path::const_iterator path_iterator;
path_iterator path_it = path.begin();
path_iterator base_it = base.begin();
while ( path_it != path.end() && base_it != base.end() ) {
if (*path_it != *base_it) break;
++path_it; ++base_it;
}
boost::filesystem::path result;
for (; base_it != base.end(); ++base_it) {
result /= "..";
}
for (; path_it != path.end(); ++path_it) {
result /= *path_it;
}
return result;
}
}
}
示例4: dir_contains_path
bool dir_contains_path(boost::filesystem::path dir, boost::filesystem::path path)
{
dir = normalized_path(fs::system_complete(dir));
path = normalized_path(fs::system_complete(path));
for (fs::path::const_iterator diri(dir.begin()), pathi(path.begin());
diri != dir.end();
++diri, ++pathi)
if (pathi == path.end()
|| *diri != *pathi)
return false;
return true;
}
示例5: makeRelative
fs::path makeRelative(fs::path fromPath, fs::path toPath)
{
fs::path res;
for(fs::path::iterator from = fromPath.begin(), to = toPath.begin(); to != toPath.end(); ++to)
{
if(*from != *to)
res /= (*to);
if(from != fromPath.end())
++from;
}
return res;
}
示例6: AddFileAndParents
unsigned short int AddFileAndParents(boost::filesystem::path p, unsigned short int parent, std::string prefix, file_list& files)
{
if(!boost::filesystem::exists(p))
{
std::cerr << "Could not open " << p.string() << std::endl;
return parent;
}
boost::filesystem::path base;
for(boost::filesystem::path::iterator it = p.begin(); it != p.end(); ++it)
{
if(base.empty())
{
base = *it;
}
else
{
std::string name = base.string() + "/" + it->string();
base = boost::filesystem::path(name);
}
parent = AddFile(base, parent, prefix, files);
}
return parent;
}
示例7: ScanFile
void ScanFile(std::vector<ImageEntryType>& List, boost::filesystem::path const& Path)
{
if (!is_directory(Path))
{
AddFile(List, Path, Path.leaf());
return;
}
using namespace boost::filesystem;
typedef boost::filesystem::recursive_directory_iterator Iterator;
std::size_t BaseOffset=std::distance(Path.begin(), Path.end());
for (Iterator i(Path), ie; i!=ie; ++i)
{
if (is_symlink(*i))
i.no_push();
if (!is_regular_file(*i))
continue;
path Absolute=*i;
path Relative;
auto j=Absolute.begin();
std::size_t c=0;
for (; j!=Absolute.end(); ++j, ++c)
if (c >= BaseOffset)
Relative /= *j;
if (!Relative.empty())
AddFile(List, Path/Relative, Relative);
}
}
示例8:
boost::filesystem::path
fcppt::filesystem::strip_prefix(
boost::filesystem::path const &_prefix,
boost::filesystem::path const &_path
)
{
boost::filesystem::path result;
std::for_each(
std::next(
_path.begin(),
fcppt::cast::to_signed(
fcppt::filesystem::num_subpaths(
_prefix
)
)
),
_path.end(),
[
&result
](
boost::filesystem::path const &_entry
)
{
result /=
_entry;
}
);
return
result;
}
示例9: MakePathRelative
boost::filesystem::path MultiresImagePlugin::MakePathRelative(boost::filesystem::path path, boost::filesystem::path base)
{
// Borrowed from: https://svn.boost.org/trac/boost/ticket/1976#comment:2
if (path.has_root_path())
{
if (path.root_path() != base.root_path())
{
return path;
}
else
{
return MakePathRelative(path.relative_path(), base.relative_path());
}
}
else
{
if (base.has_root_path())
{
ROS_WARN("Cannot uncomplete a path relative path from a rooted base.");
return path;
}
else
{
typedef boost::filesystem::path::const_iterator path_iterator;
path_iterator path_it = path.begin();
path_iterator base_it = base.begin();
while (path_it != path.end() && base_it != base.end())
{
if (*path_it != *base_it)
break;
++path_it;
++base_it;
}
boost::filesystem::path result;
for (; base_it != base.end(); ++base_it)
{
result /= "..";
}
for (; path_it != path.end(); ++path_it)
{
result /= *path_it;
}
return result;
}
}
}
示例10: chopOffFirstElement
void chopOffFirstElement( boost::filesystem::path & fileName )
{
boost::filesystem::path reducedPath;
boost::filesystem::path::iterator pit = fileName.begin();
for ( ++pit ; pit != fileName.end() ; ++pit )
{
reducedPath /= *pit;
}
fileName = reducedPath;
}
示例11: make_relative
fs::path make_relative(fs::path a_From, fs::path a_To)
{
a_From = fs::absolute(a_From); a_To = fs::absolute(a_To);
fs::path ret;
fs::path::const_iterator itrFrom(a_From.begin()), itrTo(a_To.begin());
// Find common base
for (fs::path::const_iterator toEnd(a_To.end()), fromEnd(a_From.end());
itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo; ++itrFrom, ++itrTo);
// Navigate backwards in directory to reach previously found base
for (fs::path::const_iterator fromEnd(a_From.end());
itrFrom != fromEnd; ++itrFrom)
{
if( (*itrFrom) != "." )
ret /= "..";
}
// Now navigate down the directory branch
ret.append( itrTo, a_To.end() );
return ret;
}
示例12: makeRelativePath
// Return path when appended to from will resolve to same as to
boost::filesystem::path makeRelativePath(boost::filesystem::path from, boost::filesystem::path to)
{
boost::filesystem::path ret;
boost::filesystem::path::const_iterator itrFrom(from.begin()), itrTo(to.begin());
from = boost::filesystem::absolute(from);
to = boost::filesystem::absolute(to);
// Find common base
for (boost::filesystem::path::const_iterator toEnd(to.end()), fromEnd(from.end()); itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo; ++itrFrom, ++itrTo) ;
// Navigate backwards in directory to reach previously found base
for (boost::filesystem::path::const_iterator fromEnd(from.end()); itrFrom != fromEnd; ++itrFrom) {
if ((*itrFrom) != ".")
ret /= "..";
}
// Now navigate down the directory branch
ret.append(itrTo, to.end());
return ret;
}
示例13: getStormLibPath
// StormLib needs paths with windows style \'s
std::string getStormLibPath(const bfs::path& path)
{
std::string retval = "";
for(bfs::path::iterator it = path.begin(); it != path.end(); ++it)
{
retval += it->string() + "\\";
}
retval = retval.substr(0, retval.size()-1);
return retval;
}
示例14: lf
boost::filesystem::path normalized_path(const boost::filesystem::path& path)
{
if (path.empty())
return path;
fs::path temp;
fs::path::iterator start( path.begin() );
fs::path::iterator last( path.end() );
fs::path::iterator stop( last-- );
for ( fs::path::iterator itr( start ); itr != stop; ++itr )
{
if (*itr == "."
&& itr != start
&& itr != last)
continue;
// ignore a name and following ".."
if (!temp.empty()
&& *itr == "..")
{
string lf( temp.filename() );
if (!lf.empty()
&& lf != "."
&& lf != "/"
# ifdef BOOST_WINDOWS_PATH
&& !(lf.size() == 2
&& lf[1] == ':')
# endif
&& lf != "..")
{
temp.remove_filename();
continue;
}
}
temp /= *itr;
if (itr != last
&& temp.has_root_path()
&& fs::is_symlink(temp))
{
temp = normalized_path(readlink(temp));
if (temp.filename() == ".")
temp = temp.parent_path();
}
}
if (temp.empty())
temp /= ".";
return temp;
}
示例15: resolvePath
// expands "./my/path.sfc" to "[relativeTo]/my/path.sfc"
// if allowHome is true, also expands "~/my/path.sfc" to "/home/pi/my/path.sfc"
fs::path resolvePath(const fs::path& path, const fs::path& relativeTo, bool allowHome)
{
// nothing here
if(path.begin() == path.end())
return path;
if(*path.begin() == ".")
{
fs::path ret = relativeTo;
for(auto it = ++path.begin(); it != path.end(); ++it)
ret /= *it;
return ret;
}
if(allowHome && *path.begin() == "~")
{
fs::path ret = getHomePath();
for(auto it = ++path.begin(); it != path.end(); ++it)
ret /= *it;
return ret;
}
return path;
}