本文整理汇总了C++中boost::filesystem::path::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ path::empty方法的具体用法?C++ path::empty怎么用?C++ path::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::filesystem::path
的用法示例。
在下文中一共展示了path::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copy_files
inline
void copy_files(const boost::filesystem::path& path_from,
const boost::filesystem::path& path_to)
{
if (path_from.empty() || path_to.empty())
throw std::runtime_error("empty path");
if (! boost::filesystem::exists(path_from) || ! boost::filesystem::exists(path_to))
throw std::runtime_error("no path");
if (! boost::filesystem::is_directory(path_to))
throw std::runtime_error("destination is not a directory");
boost::filesystem::path destination = path_to / path_from.leaf();
if (! boost::filesystem::is_directory(path_from))
boost::filesystem::copy_file(path_from, destination);
else {
boost::filesystem::create_directory(destination);
boost::filesystem::directory_iterator iter_end;
for (boost::filesystem::directory_iterator iter(path_from); iter != iter_end; ++ iter)
copy_files(*iter, destination);
}
}
示例2: remove_all
inline
void remove_all(const boost::filesystem::path& path)
{
if (__is_directory(path)) {
std::vector<boost::filesystem::path> paths;
#if BOOST_FILESYSTEM_VERSION == 2
DIR* dirp = (path.empty() ? ::opendir(".") : ::opendir(path.directory_string().c_str()));
#else
DIR* dirp = (path.empty() ? ::opendir(".") : ::opendir(path.string().c_str()));
#endif
if (dirp) {
struct dirent* dp;
do {
errno = 0;
if ((dp = readdir(dirp)) != 0) {
const std::string path_leaf(dp->d_name);
if (path_leaf != "." && path_leaf != "..")
paths.push_back(path / path_leaf);
}
} while (dp);
::closedir(dirp);
}
std::for_each(paths.begin(), paths.end(), utils::filesystem::remove_all);
}
#if BOOST_FILESYSTEM_VERSION == 2
if (__exists(path))
::remove(path.file_string().c_str());
#else
if (__exists(path))
::remove(path.string().c_str());
#endif
errno = 0;
}
示例3:
static void
setupLogging(std::string levelArg, bfs::path pathArg)
{
bp::log::Configurator cfg;
cfg.loadConfigFile();
// Set the default log file.
// One case we'll need this is when daemon is in -fg mode but
// configured logging destination is "file".
cfg.setPath(bp::paths::getObfuscatedWritableDirectory() /
"BrowserPlusCore.log");
// Currently there is no policy for service harness processes to
// log to any other file than BrowserPlusCore.log.
// Let's take the tack for now that harnesses never rollover that file.
cfg.setFileMode( bp::log::kAppend );
////
// Handle any command line arguments.
//
if (!levelArg.empty()) {
cfg.setLevel( bp::log::levelFromString( levelArg ) );
}
if (!pathArg.empty()) {
cfg.setDestination( bp::log::kDestFile );
cfg.setPath( pathArg );
}
// Configure.
cfg.configure();
}
示例4: logger_init
void logger_init(
const std::string& path,
LogPriority level,
const std::string& format,
const std::string& compress,
const std::string& purgeCount)
{
if (_enableLogging)
{
_logFile = path;
if (!_logDirectory.empty())
{
//
// Application override for the directory
//
std::string lfile = OSS::boost_file_name(_logFile);
_logFile = operator/(_logDirectory, lfile);
}
AutoPtr<FileChannel> rotatedFileChannel(new FileChannel(OSS::boost_path(_logFile)));
rotatedFileChannel->setProperty("rotation", "daily");
rotatedFileChannel->setProperty("archive", "timestamp");
rotatedFileChannel->setProperty("compress", compress);
rotatedFileChannel->setProperty("purgeCount", purgeCount);
AutoPtr<Formatter> formatter(new PatternFormatter(format.c_str()));
AutoPtr<Channel> formattingChannel(new FormattingChannel(formatter, rotatedFileChannel));
_pLogger = &(Logger::create("OSS.logger", formattingChannel, level));
}
}
示例5: Set_Image_Dir
void cFlyon::Set_Image_Dir(fs::path dir)
{
if (dir.empty()) {
return;
}
// if not image directory
if (!File_Exists(pResource_Manager->Get_Game_Pixmaps_Directory() / dir / utf8_to_path("closed_1.settings")) && !File_Exists(pResource_Manager->Get_Game_Pixmaps_Directory() / dir / utf8_to_path("closed_1.png"))) {
std::cerr << "Warning: Flyon image files not found; does the flyon directory "
<< path_to_utf8(dir) << " exist?" << std::endl;
return;
}
m_img_dir = dir;
// clear images
Clear_Images();
// set images
Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("closed_1.png")));
Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("closed_2.png")));
Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("open_1.png")));
Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("open_2.png")));
// set start image
Set_Image_Num(0, 1);
Set_Animation(1);
Set_Animation_Image_Range(0, 3);
Set_Time_All(130, 1);
Reset_Animation();
}
示例6: memset
bool
statFile(const bfs::path& p,
FileInfo& fi)
{
// init to zero
memset(&fi, 0, sizeof(fi));
if (p.empty()) return false;
struct stat s;
if (::stat(p.c_str(), &s) != 0) return false;
// set times
#ifdef MACOSX
fi.mtime = s.st_mtimespec.tv_sec;
fi.ctime = s.st_ctimespec.tv_sec;
fi.atime = s.st_atimespec.tv_sec;
#elif defined(LINUX)
fi.mtime = s.st_mtime;
fi.ctime = s.st_ctime;
fi.atime = s.st_atime;
#else
#error "unsupported platform"
#endif
// set mode and size
fi.mode = s.st_mode;
fi.sizeInBytes = s.st_size;
// set device and file ids
fi.deviceId = s.st_rdev;
fi.fileIdLow = s.st_ino;
return true;
}
示例7:
void
DataTableWriter::initialise()
{
using ::std::ios_base;
myLastWriteCoords = DataTable::Coords(0, 0);
myFullWriteRequired = true;
const bool fileExists = fs::exists(myOutputPath);
// Make sure that all the folders up the filename exist
if(!fileExists)
{
const fs::path parentPath = myOutputPath.parent_path();
if(!parentPath.empty() && !exists(parentPath))
fs::create_directories(parentPath);
}
::std::ios_base::openmode openMode = ios_base::out;
if(fileExists && myAppend)
openMode = openMode | ios_base::ate;
// Try opening the file
myOutStream.open(myOutputPath, openMode);
// Save the write marker
myWriteMarker = myOutStream.tellp();
// Listen for changes to the table
myTable.addDataTableChangeListener(this);
}
示例8: _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
}
示例9: 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;
}
示例10: IsPluginMaster
bool IsPluginMaster(boost::filesystem::path filename) {
char buffer[MAXLENGTH];
char* bufptr = buffer;
ModHeader modHeader;
if (filename.empty())
return false;
ifstream file(filename.native().c_str(), ios_base::binary | ios_base::in);
if (file.bad())
//throw boss_error(BOSS_ERROR_FILE_READ_FAIL, filename.string());
return false;
// Reads the first MAXLENGTH bytes into the buffer
file.read(&buffer[0], sizeof(buffer));
// Check for the 'magic' marker at start
if (Read<uint>(bufptr) != Record::TES4){
return false;
}
// Next field is the total header size
/*uint headerSize =*/ Read<uint>(bufptr);
// Next comes the header record Flags
uint flags = Read<uint>(bufptr);
// LSb of this record's flags is used to indicate if the
// mod is a master or a plugin
return ((flags & 0x1) != 0);
}
示例11: parse_lang_code_file
void parse_lang_code_file() {
if(g_executable_path.empty()) throw(std::runtime_error("executable_path is empty"));
boost::filesystem::path iso_file(g_executable_path/PLUGINS_NAVTEQ_ISO_639_2_UTF_8_TXT);
std::ifstream file(iso_file.string());
assert(file.is_open());
std::string line;
std::string delim = "|";
if (file.is_open()){
while (getline(file, line, '\n')){
std::vector<std::string> lv;
auto start = 0u;
auto end = line.find(delim);
while (end != std::string::npos){
lv.push_back(line.substr(start, end-start));
start = end + delim.length();
end = line.find(delim, start);
}
std::string iso_639_2 = lv.at(0);
std::string iso_639_1 = lv.at(2);
if (!iso_639_1.empty()) g_lang_code_map.insert(std::make_pair(iso_639_2, iso_639_1));
}
file.close();
}
}
示例12: file
GTEST_TEST_F(ReadFile, write) {
ASSERT_FALSE(kFilePath.empty());
static const byte data[5] = { 0x12, 0x34, 0x56, 0x78, 0x90 };
// Create the input file
boost::filesystem::ofstream testFile(kFilePath, std::ofstream::binary);
testFile.write(reinterpret_cast<const char *>(data), ARRAYSIZE(data));
testFile.flush();
ASSERT_FALSE(testFile.fail());
testFile.close();
// Read the file with our ReadFile class
Common::ReadFile file(kFilePath.generic_string());
ASSERT_TRUE(file.isOpen());
EXPECT_EQ(file.size(), ARRAYSIZE(data));
byte readData[ARRAYSIZE(data)];
const size_t readCount = file.read(readData, sizeof(readData));
EXPECT_EQ(readCount, ARRAYSIZE(readData));
file.close();
ASSERT_FALSE(file.isOpen());
// Compare
for (size_t i = 0; i < ARRAYSIZE(data); i++)
EXPECT_EQ(readData[i], data[i]) << "At index " << i;
}
示例13: exists
bool DatabaseImpl::exists(const boost::filesystem::path& database)
{
RAISE_INVALID_ARGUMENT_IF(database.empty(), "database name is empty");
RAISE_INVALID_ARGUMENT_IF(openDatabase_, "database is open");
ManagedDatabaseFiles databaseFiles(database);
return databaseFilesExist(databaseFiles);
}
示例14: open
void DatabaseImpl::open(const boost::filesystem::path& database, const Options& options)
{
RAISE_INVALID_ARGUMENT_IF(database.empty(), "database name is empty");
options.validate();
RAISE_INVALID_ARGUMENT_IF(openDatabase_, "database is already open");
openDatabase_.reset(new OpenDatabase(database, options));
}
示例15: open_writer
bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
{
const boost::filesystem::path dir_path = file_path.parent_path();
if (!dir_path.empty())
{
if (boost::filesystem::exists(dir_path))
{
if (!boost::filesystem::is_directory(dir_path))
{
LOG_PRINT_RED_L0("export directory path is a file: " << dir_path);
return false;
}
}
else
{
if (!boost::filesystem::create_directory(dir_path))
{
LOG_PRINT_RED_L0("Failed to create directory " << dir_path);
return false;
}
}
}
m_raw_data_file = new std::ofstream();
bool do_initialize_file = false;
uint64_t num_blocks = 0;
if (! boost::filesystem::exists(file_path))
{
LOG_PRINT_L0("creating file");
do_initialize_file = true;
num_blocks = 0;
}
else
{
num_blocks = count_blocks(file_path.string());
LOG_PRINT_L0("appending to existing file with height: " << num_blocks-1 << " total blocks: " << num_blocks);
}
m_height = num_blocks;
if (do_initialize_file)
m_raw_data_file->open(file_path.string(), std::ios_base::binary | std::ios_base::out | std::ios::trunc);
else
m_raw_data_file->open(file_path.string(), std::ios_base::binary | std::ios_base::out | std::ios::app | std::ios::ate);
if (m_raw_data_file->fail())
return false;
m_output_stream = new boost::iostreams::stream<boost::iostreams::back_insert_device<buffer_type>>(m_buffer);
if (m_output_stream == nullptr)
return false;
if (do_initialize_file)
initialize_file();
return true;
}