本文整理汇总了C++中fs::path::file_string方法的典型用法代码示例。如果您正苦于以下问题:C++ path::file_string方法的具体用法?C++ path::file_string怎么用?C++ path::file_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs::path
的用法示例。
在下文中一共展示了path::file_string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseMaterials
void parseMaterials(GeometryConverter *cvt, std::ostream &os, const fs::path &texturesDir,
const fs::path &mtlFileName, std::set<std::string> &mtlList) {
SLog(EInfo, "Loading OBJ materials from \"%s\" ..", mtlFileName.file_string().c_str());
fs::ifstream is(mtlFileName);
if (is.bad() || is.fail())
SLog(EError, "Unexpected I/O error while accessing material file '%s'!",
mtlFileName.file_string().c_str());
std::string buf, line;
std::string mtlName;
Spectrum diffuse(0.0f);
std::string diffuseMap, maskMap;
while (is >> buf) {
if (buf == "newmtl") {
mtlList.insert(mtlName);
addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap);
std::getline(is, line);
mtlName = trim(line.substr(1, line.length()-1));
diffuse = Spectrum(0.0f);
diffuseMap = "";
maskMap = "";
} else if (buf == "Kd") {
Float r, g, b;
is >> r >> g >> b;
if (cvt->m_srgb)
diffuse.fromSRGB(r, g, b);
else
diffuse.fromLinearRGB(r, g, b);
} else if (buf == "map_Kd") {
示例2: time
void
FileCollectionTest::setUp()
{
fs::remove_all(testFolder);
fs::create_directory(folderTest);
fs::create_directory(folderTest/testDirectory);
{
ofstream test0(fileTest0.file_string().c_str());
ofstream test1(fileTest1.file_string().c_str());
ofstream test2(fileTest2.file_string().c_str());
ofstream test3(fileTest3.file_string().c_str());
}
struct ::utimbuf times;
times.actime = time(NULL);
times.modtime = times.actime - 8;
utime( fileTest0.file_string().c_str(), × );
times.actime -= 1;
times.modtime += 1;
utime( fileTest1.file_string().c_str(), × );
times.actime -= 1;
times.modtime += 1;
utime( fileTest2.file_string().c_str(), × );
times.actime -= 1;
times.modtime += 1;
utime( fileTest3.file_string().c_str(), × );
}
示例3:
void
FileOperationMetaTest::testFileOperationSubNone(
auto_ptr<FileOperationInterface> & oper, const fs::path & fileMeta,
const fs::path & fileEntity,
const string & tapeName)
{
string tape;
char buffer[1024] = "hello,world!\n";
char bufferRead[sizeof(buffer)];
size_t size;
struct stat stat;
errno = 0;
CPPUNIT_ASSERT( false == oper->GetStat(stat) );
CPPUNIT_ASSERT_ERRNO_( ENOENT == errno);
errno = 0;
CPPUNIT_ASSERT( false == oper->Read(0,bufferRead,sizeof(bufferRead),size) );
CPPUNIT_ASSERT_ERRNO_( EBADF == errno);
errno = 0;
CPPUNIT_ASSERT( false == oper->Write(0,buffer,sizeof(buffer),size) );
CPPUNIT_ASSERT_ERRNO_( EBADF == errno);
CPPUNIT_ASSERT( ! fs::exists(fileMeta) );
CPPUNIT_ASSERT( ! fs::exists(fileEntity) );
errno = 0;
CPPUNIT_ASSERT( false == oper->OpenFile(O_RDWR) );
CPPUNIT_ASSERT_ERRNO_( ENOENT == errno);
CPPUNIT_ASSERT_MESSAGE( fileEntity.file_string(),
true == oper->CreateFile(O_RDWR,0644,false) );
CPPUNIT_ASSERT( fs::exists(fileMeta) );
CPPUNIT_ASSERT( fs::exists(fileEntity) );
CPPUNIT_ASSERT( true == oper->Delete() );
CPPUNIT_ASSERT( ! fs::exists(fileMeta) );
CPPUNIT_ASSERT( ! fs::exists(fileEntity) );
CPPUNIT_ASSERT( true == oper->GetTape(tape) );
CPPUNIT_ASSERT( tape == tapeName );
}
示例4: md5sum
bool md5sum(const fs::path &path, md5digest &digest)
{
try {
Exiv2::FileIo io(path.file_string());
if (io.open() != 0)
return false;
Exiv2::IoCloser closer(io);
Exiv2::byte buff[4096];
MD5_CTX context;
MD5Init(&context);
long read_count = io.read(buff, 4096);
while(read_count) {
MD5Update(&context, buff, read_count);
read_count = io.read(buff, 4096);
}
MD5Final(digest, &context);
return true;
}
catch (std::exception& ) {
return false;
}
}
示例5: sizeof
void
FileOperationMetaTest::testFileOperationSubCreateTruncate(
auto_ptr<MetaManager> & meta,
const fs::path & path,
auto_ptr<FileOperationInterface> & oper,
const fs::path & fileMeta,
const fs::path & fileEntity,
const string & tapeName)
{
string tape;
auto_ptr<Inode> inode;
char buffer[1024] = "hello,world!\n";
char bufferRead[sizeof(buffer)];
size_t size;
struct stat stat;
CPPUNIT_ASSERT( ! fs::exists(fileMeta) );
CPPUNIT_ASSERT( ! fs::exists(fileEntity) );
errno = 0;
CPPUNIT_ASSERT( false == oper->GetStat(stat) );
CPPUNIT_ASSERT_ERRNO_( ENOENT == errno);
errno = 0;
CPPUNIT_ASSERT( false == oper->Read(0,bufferRead,sizeof(bufferRead),size) );
CPPUNIT_ASSERT_ERRNO_( EBADF == errno);
errno = 0;
CPPUNIT_ASSERT( false == oper->Write(0,buffer,sizeof(buffer),size) );
CPPUNIT_ASSERT_ERRNO_( EBADF == errno);
CPPUNIT_ASSERT( ! fs::exists(fileMeta) );
CPPUNIT_ASSERT( ! fs::exists(fileEntity) );
errno = 0;
CPPUNIT_ASSERT( false == oper->OpenFile(O_RDWR) );
CPPUNIT_ASSERT_ERRNO_( ENOENT == errno);
CPPUNIT_ASSERT( ! fs::exists(fileMeta) );
CPPUNIT_ASSERT( ! fs::exists(fileEntity) );
CPPUNIT_ASSERT( true == oper->CreateFile(O_RDWR,0644,false) );
CPPUNIT_ASSERT( fs::exists(fileMeta) );
CPPUNIT_ASSERT_MESSAGE( fileEntity.file_string(), fs::exists(fileEntity) );
inode.reset(meta->GetInode(path));
errno = 0;
CPPUNIT_ASSERT( false == oper->CreateFile(O_RDWR,0644,false) );
CPPUNIT_ASSERT_ERRNO_( EEXIST == errno);
tape.clear();
CPPUNIT_ASSERT( true == oper->GetTape(tape) );
CPPUNIT_ASSERT( tapeName == tape );
tape.clear();
CPPUNIT_ASSERT( true == inode->GetTape(tape) );
CPPUNIT_ASSERT( tapeName == tape );
CPPUNIT_ASSERT( true == oper->Write(0,buffer,sizeof(buffer),size) );
CPPUNIT_ASSERT( fs::exists(fileMeta) );
CPPUNIT_ASSERT( fs::exists(fileEntity) );
CPPUNIT_ASSERT( true == oper->GetStat(stat) );
CPPUNIT_ASSERT( sizeof(buffer) == stat.st_size );
CPPUNIT_ASSERT( true == oper->Truncate( sizeof(buffer) - 5 ) );
CPPUNIT_ASSERT( true == oper->GetStat(stat) );
CPPUNIT_ASSERT( sizeof(buffer) - 5 == stat.st_size );
CPPUNIT_ASSERT( true == oper->Truncate( sizeof(buffer) + 5 ) );
CPPUNIT_ASSERT( true == oper->GetStat(stat) );
CPPUNIT_ASSERT( sizeof(buffer) + 5 == stat.st_size );
CPPUNIT_ASSERT( true == oper->Truncate( sizeof(buffer) ) );
CPPUNIT_ASSERT( true == oper->GetStat(stat) );
CPPUNIT_ASSERT( sizeof(buffer) == stat.st_size );
tape.clear();
CPPUNIT_ASSERT( true == oper->GetTape(tape) );
CPPUNIT_ASSERT( tapeName == tape );
tape.clear();
CPPUNIT_ASSERT( true == inode->GetTape(tape) );
CPPUNIT_ASSERT( tape == tapeName );
}
示例6: process_directory
void process_directory(const fs::path &directory, const long depth,
ProcessParams ¶ms)
{
// Exclude entire directories
bool exclude = false;
std::vector<std::string>::const_iterator x_iter = params.excludes.begin();
std::vector<std::string>::const_iterator x_end = params.excludes.end();
for( ; x_iter != x_end; ++x_iter ) {
if(boost::contains(directory.file_string(), *x_iter)) {
exclude = true;
break;
}
}
if(exclude) {
info(std::string("excluding directory: ") + directory.file_string() +
" matched: " + *x_iter);
++params.dir_ex_count;
return;
}
try {
fs::directory_iterator p_iter(directory), p_end;
for( ; p_iter != p_end; ++p_iter) {
if( is_directory(*p_iter) ) {
// recurse if we haven't hit the limit
if(depth < params.limit_depth)
process_directory(p_iter->path(), depth + 1, params);
else {
info(std::string("depth reached, skipping: ") +
p_iter->path().file_string());
}
}
else if( is_regular_file(*p_iter) ) {
// Check again for excluding file names
exclude = false;
x_iter = params.excludes.begin();
for( ; x_iter != x_end; ++x_iter ) {
if(boost::contains(p_iter->path().file_string(), *x_iter)) {
exclude = true;
break;
}
}
if(exclude) {
info(std::string("excluding file: ") + p_iter->path().file_string() +
" matched: " + *x_iter);
++params.file_ex_count;
continue;
}
try {
const fs::path dest_subdir = build_dest(*p_iter);
fs::path dest_file;
if(!dest_subdir.empty())
dest_file = params.dest_dir / dest_subdir;
else if(params.ignore_unsorted) {
info(std::string("ignoring unsorted: ") + p_iter->path().file_string());
++params.unsorted_ignored_count;
continue;
}
else {
info(std::string("unsorted file (missing metadata): ") + p_iter->path().file_string());
dest_file = params.unsorted_dir;
++params.unsorted_count;
}
dest_file /= p_iter->filename();
if(fs::exists(dest_file)) {
if(params.ignore_dups) {
info(std::string("ignoring: ") + p_iter->path().file_string() +
" duplicates: " + dest_file.file_string());
++params.dups_ignored_count;
continue;
}
else {
if(params.force) {
info(std::string("force removing: ") + dest_file.file_string() + " for: "
+ p_iter->path().file_string());
if(!params.dry_run)
fs::remove(dest_file);
}
else if(params.rename) {
info(std::string("renaming: ") + p_iter->path().file_string() +
" duplicates: " + dest_file.file_string());
dest_file = uniquify(dest_file);
}
else {
info(std::string("duplicate file: ") + p_iter->path().file_string() +
" of: " + dest_file.file_string());
dest_file = params.dups_dir / dest_subdir / p_iter->filename();
// Ugh, more dup possibilities
if(fs::exists(dest_file)) {
info(std::string("renaming: ") + p_iter->path().file_string() +
" duplicates: " + dest_file.file_string());
dest_file = uniquify(dest_file);
}
}
++params.dups_count;
}
//.........这里部分代码省略.........