本文整理汇总了C++中boost::filesystem::path::native方法的典型用法代码示例。如果您正苦于以下问题:C++ path::native方法的具体用法?C++ path::native怎么用?C++ path::native使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::filesystem::path
的用法示例。
在下文中一共展示了path::native方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void operator()(const boost::filesystem::path & data)
{
not_cmd = true;
if (exe.empty())
exe = data.native();
else
args.push_back(data.native());
}
示例2: AddFolder
void ZipArchiveImpl::AddFolder(const bfs::path& path, const bfs::path& archive_path)
{
++m_Info.folderCount;
zip_fileinfo fileinfo;
fileinfo.internal_fa = 0;
#ifdef _WIN32
fileinfo.external_fa = ::GetFileAttributesW(path.native().c_str());
#else
{
struct stat path_stat;
if (::stat(path.native().c_str(), &path_stat) == 0)
{
fileinfo.external_fa = path_stat.st_mode;
}
}
#endif
fileinfo.dosDate = 0;
// Read the time from the filesystem and convert it
auto fsTime = bfs::last_write_time(path);
auto posixTime = boost::posix_time::from_time_t(fsTime);
auto tm = boost::posix_time::to_tm(posixTime);
/* TODO: this is how to get the time for a physfs file
boost::posix_time::ptime posixTime;
auto milisPastEpoc = PHYSFS_getLastModTime(path.generic_string().c_str());
if (milisPastEpoc >= 0)
time = boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1), boost::posix_time::milliseconds(milisPastEpoc));
else
time = boost::posix_time::second_clock::local_time();
*/
fileinfo.tmz_date.tm_hour = tm.tm_hour;
fileinfo.tmz_date.tm_min = tm.tm_min;
fileinfo.tmz_date.tm_sec = tm.tm_sec;
fileinfo.tmz_date.tm_year = tm.tm_year;
fileinfo.tmz_date.tm_mon = tm.tm_mon;
fileinfo.tmz_date.tm_mday = tm.tm_mday;
auto r = zipOpenNewFileInZip(m_File, (archive_path.generic_string() + "/").c_str(),
&fileinfo,
nullptr, 0,
nullptr, 0,
nullptr,
Z_DEFLATED,
Z_BEST_SPEED);
zipCloseFileInZip(m_File);
for (bfs::directory_iterator it(path), end = bfs::directory_iterator(); it != end; ++it)
{
AddPath(it->path(), archive_path / it->path().filename());
}
}
示例3: info
void
read_slice_channel(
T view,
boost::filesystem::path aff_x_file) {
vigra::ImageImportInfo info(aff_x_file.native().c_str());
vigra::MultiArray<2, float> data(info.shape());
vigra::importImage(aff_x_file.native().c_str(), data);
for (int x = 0; x < info.shape()[0]; x++)
for (int y = 0; y < info.shape()[1]; y++)
view[x][y] = data(x, y);
}
示例4: throwIfExists
void throwIfExists(const boost::filesystem::path& file) {
if (boost::filesystem::exists(file)) {
std::stringstream ss;
ss << "File exists: " << file.native();
throw std::runtime_error(ss.str());
}
}
示例5: load_library
void load_library() {
if (handle_ != NULL)
unload_library();
handle_ = LoadLibrary(module_.native().c_str());
if (handle_ == NULL)
throw dll_exception("Could not load library: " + utf8::cvt<std::string>(error::lookup::last_error()) + ": " + module_.filename().string());
}
示例6: make_rooted_path
FS::path ConfdUnittestHarness::make_rooted_path(
FS::path filename)
{
try {
// Can handle $RIFT_ROOT
std::string raw_fullpath = filename.native();
const char RIFT_ROOT[] = "$RIFT_ROOT";
if (raw_fullpath.substr(0, sizeof(RIFT_ROOT)-1) == RIFT_ROOT) {
raw_fullpath.replace(0, sizeof(RIFT_ROOT)-1, rift_root_.c_str());
}
FS::path fullpath = raw_fullpath;
if (!fullpath.is_absolute()) {
fullpath = cwd_/fullpath;
}
return fullpath;
} catch (const FS::filesystem_error& fe) {
cerr << "Filesystem error: " << fe.what()
<< ": " << fe.path1()
<< ", " << fe.path2()
<< std::endl;
throw std::exception(); // don't rethrow, to prevent being recaught by harness
}
}
示例7: try_run_file
void try_run_file(const boost::filesystem::path & cur)
{
if(cur.extension().native().compare(".py"))
{
return;
}
script_file_parser script_file(cur.native());
if(script_file.is_valid())
{
boost::filesystem::path work, out;
create_directories(cur, work, out);
auto parent = cur.parent_path();
auto start = parent.begin();
for(auto p = config::tests.begin(); p != config::tests.end() && *p == *start; ++p, ++start) ;
for(; start != parent.end(); ++start)
{
script_file.add_keyword((*start).native());
}
script_file.add_title(cur.stem().native());
if(config::query->evaluate(script_file))
{
script_scheduler()->schedule_file(cur, work, out);
}
}
}
示例8: ofstream
/**
* Creates a new log_writer instance which will emit output to the specified file.
* @param output_file Path identifying file to write XML to.
* @param create If output_file doesn't exist, indicates whether to create it on the fly. Defaults to true.
* @param write_header indicates if the XML preamble should be written on startup
* @param write_footer indicates if the XML closure tags should be written on shutdown.
* @param specific_pid specify the PID to create log for
* @param specific_application_name specify the application name to create log for
* @returns shared pointer to newly instanced log_writer.
*/
std::shared_ptr<log_writer> log_writer::create_from_file_path(
const boost::filesystem::path& output_file, const bool& create,
const bool& write_header, const bool& write_footer,
const pid_type& specific_pid, const std::string& specific_application_name)
{
try
{
using namespace boost::filesystem;
// determine if the file exists
if (!exists(output_file))
{
// the file doesn't exist.
// check to see if we should create it...
if (create)
{
//
// ideally - I would like to check the validity of the requested file here but
// boost::filesystem::native() is having some problems with relative paths such
// as "./log.xml" (incl. the leading ./); which is apparently not a valid file path.
// instead we'll have to push on and rely on the resulting exception to indicate bad files.
//
// determine the parent directory path (required for relative paths)
auto parent_directory = absolute(output_file).branch_path();
boost::system::error_code filesystem_error;
// ensure parent directory exists, or create it
if (!exists(parent_directory) && !create_directories(
parent_directory, filesystem_error))
{
using namespace inglenook::core::exceptions;
// the parent path doesn't exist and we failed to create it.
BOOST_THROW_EXCEPTION(failed_to_create_log_exception()
<< boost_filesystem_error(filesystem_error)
<< inglenook_error_number(log_exception_bad_file_path));
}
}
else // the file does not exist, and we were not instructed to create it.
{
using namespace inglenook::core::exceptions;
BOOST_THROW_EXCEPTION(log_not_found_exception()
<< inglenook_error_number(log_exception_bad_file_path));
}
}
// at this point either the log exists, or we are good to create it
// so attempt to open the specified file path for appending data.
return std::shared_ptr<log_writer>(new log_writer(std::shared_ptr<std::ofstream>(
new std::ofstream(output_file.native(), std::ios::app)),
write_header, write_footer, specific_pid,
specific_application_name));
}
catch(boost::exception& ex)
{
// if anything goes wrong augment exception with the file path we were working with.
ex << log_file_name(output_file);
throw;
}
}
示例9: read_image
void read_image( boost::filesystem::path const& pathname, DiskImage<PixelType>& output_image ){
// make sure the file exists
if( boost::filesystem::exists( pathname ) == false ){
throw std::runtime_error(std::string(std::string("error: File \"") + pathname.native() + std::string("\" does not exist.")).c_str());
}
// compute the required driver
GEO::ImageDriverType driver = compute_driver( pathname, DriverOptions::READ_ONLY );
// create the resource
DiskResource<PixelType> resource;
boost::shared_ptr<GEO::IO::ImageDriverBase> image_driver(nullptr);
/**
* Iterate through potential drivers
*/
if( driver == ImageDriverType::GDAL ){
image_driver = boost::shared_ptr<GEO::IO::ImageDriverBase>(new GEO::IO::GDAL::ImageDriverGDAL(pathname));
image_driver->open();
}
else{
throw std::runtime_error("Unknown driver type.");
}
// set the resource
resource.setDriver( image_driver );
// set the driver
output_image.setResource(resource);
}
示例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
void
mack::options::configuration_file::parse(
boost::filesystem::path const& file_path,
mack::options::program_options* options)
{
if (options == NULL)
{
BOOST_THROW_EXCEPTION(mack::core::null_pointer_error());
}
try
{
parse(mack::core::files::read_file(file_path), options);
}
catch (mack::options::no_such_option_error e)
{
if (boost::get_error_info<mack::core::files::errinfo_file>(e) == NULL)
{
// this is the configuration file with the erroneous line
e << mack::core::files::errinfo_file(file_path.native());
} // else error from within a further configuration file
throw;
}
catch (mack::options::no_such_namespace_error e)
{
if (boost::get_error_info<mack::core::files::errinfo_file>(e) == NULL)
{
e << mack::core::files::errinfo_file(file_path.native());
}
throw;
}
catch (mack::options::invalid_value_error e)
{
if (boost::get_error_info<mack::core::files::errinfo_file>(e) == NULL)
{
e << mack::core::files::errinfo_file(file_path.native());
}
throw;
}
catch (mack::options::no_value_error e)
{
if (boost::get_error_info<mack::core::files::errinfo_file>(e) == NULL)
{
e << mack::core::files::errinfo_file(file_path.native());
}
throw;
}
}
示例12:
inline std::string
pathstr(const filesystem::path& p)
{
#ifdef _WIN32
return Strutil::utf16_to_utf8(p.native());
#else
return p.string();
#endif
}
示例13: PathString
std::string PathString(const fs::path& path) {
#ifndef FREEORION_WIN32
return path.string();
#else
fs::path::string_type native_string = path.native();
std::string retval;
utf8::utf16to8(native_string.begin(), native_string.end(), std::back_inserter(retval));
return retval;
#endif
}
示例14: loadFile
size_t IOFactory::loadFile( std::list<Chunk> &ret, const boost::filesystem::path &filename, util::istring suffix_override, util::istring dialect )
{
FileFormatList formatReader;
formatReader = getFileFormatList( filename.string(), suffix_override, dialect );
const util::istring with_dialect = dialect.empty() ?
util::istring( "" ) : util::istring( " with dialect \"" ) + dialect + "\"";
if ( formatReader.empty() ) {
if( !boost::filesystem::exists( filename ) ) {
LOG( Runtime, error ) << util::MSubject( filename )
<< " does not exist as file, and no suitable plugin was found to generate data from "
<< ( suffix_override.empty() ? util::istring( "that name" ) : util::istring( "the suffix \"" ) + suffix_override + "\"" );
} else if( suffix_override.empty() ) {
LOG( Runtime, error ) << "No plugin found to read " << filename << with_dialect;
} else {
LOG( Runtime, error ) << "No plugin supporting the requested suffix " << suffix_override << with_dialect << " was found";
}
} else {
BOOST_FOREACH( FileFormatList::const_reference it, formatReader ) {
LOG( ImageIoDebug, info )
<< "plugin to load file" << with_dialect << " " << util::MSubject( filename ) << ": " << it->getName();
try {
int loaded=it->load( ret, filename.native(), dialect, m_feedback );
BOOST_FOREACH( Chunk & ref, ret ) {
if ( ! ref.hasProperty( "source" ) )
ref.setPropertyAs( "source", filename.native() );
}
return loaded;
} catch ( std::runtime_error &e ) {
if( suffix_override.empty() ) {
LOG( Runtime, formatReader.size() > 1 ? warning : error )
<< "Failed to load " << filename << " using " << it->getName() << with_dialect << " ( " << e.what() << " )";
} else {
LOG( Runtime, warning )
<< "The enforced format " << it->getName() << " failed to read " << filename << with_dialect
<< " ( " << e.what() << " ), maybe it just wasn't the right format";
}
}
}
LOG_IF( boost::filesystem::exists( filename ) && formatReader.size() > 1, Runtime, error ) << "No plugin was able to load: " << util::MSubject( filename ) << with_dialect;
}
示例15: png_read_and_convert_image
inline void png_read_and_convert_image(const boost::filesystem::path& path,Image& im) {
#if defined (_WIN32)
boost::filesystem::path::string_type path_native = path.native();
FILE* file = _wfopen(path_native.c_str(), L"rb");
gil::png_read_and_convert_image(file,im);
fclose(file);
#else
std::string filename = path.generic_string();
png_read_and_convert_image(filename.c_str(),im);
#endif
}