本文整理汇总了C++中boost::filesystem::path::generic_string方法的典型用法代码示例。如果您正苦于以下问题:C++ path::generic_string方法的具体用法?C++ path::generic_string怎么用?C++ path::generic_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::filesystem::path
的用法示例。
在下文中一共展示了path::generic_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
void Image::write(const boost::filesystem::path &pfname)
{
if(data::filename_is_png(pfname))
{
if(image_png_supports_bpp(m_b))
{
image_png_save(pfname.generic_string(), m_w, m_h, m_b, m_data);
}
else
{
std::ostringstream str;
str << '\'' << pfname << "': bit depth " << m_b << " not supported in PNG";
BOOST_THROW_EXCEPTION(std::runtime_error(str.str()));
}
}
else if(data::filename_is_jpeg(pfname))
{
if(image_jpeg_supports_bpp(m_b))
{
image_jpeg_save(pfname.generic_string(), m_w, m_h, m_b, m_data);
}
else
{
std::ostringstream str;
str << '\'' << pfname << "': bit depth " << m_b << " not supported in JPEG";
BOOST_THROW_EXCEPTION(std::runtime_error(str.str()));
}
}
else
{
std::ostringstream str;
str << "unknown image type: " << pfname;
BOOST_THROW_EXCEPTION(std::runtime_error(str.str()));
}
}
示例2: path
EditorColorScheme::EditorColorScheme(fs::path path) : path(path)
{
try {
boost::property_tree::read_json(path.generic_string(), pt);
_name = QString::fromStdString(pt.get<std::string>("name"));
_index = pt.get<int>("index");
} catch (const std::exception & e) {
PRINTB("Error reading color scheme file '%s': %s", path.generic_string() % e.what());
_name = "";
_index = 0;
}
}
示例3: open
Status FTDCFileWriter::open(const boost::filesystem::path& file) {
if (_archiveStream.is_open()) {
return {ErrorCodes::FileAlreadyOpen, "FTDCFileWriter is already open."};
}
_archiveFile = file;
// Ideally, we create a file from scratch via O_CREAT but there is not portable way via C++
// iostreams to do this.
_archiveStream.open(_archiveFile.c_str(),
std::ios_base::out | std::ios_base::binary | std::ios_base::app);
if (!_archiveStream.is_open()) {
return Status(ErrorCodes::FileNotOpen,
"Failed to open archive file " + file.generic_string());
}
// Set internal size tracking to reflect the current file size
_size = boost::filesystem::file_size(file);
_sizeInterim = 0;
_interimFile = FTDCUtil::getInterimFile(file);
_interimTempFile = FTDCUtil::getInterimTempFile(file);
_compressor.reset();
return Status::OK();
}
示例4: 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;
}
示例5: save
inline void save(Archive& ar,
const boost::filesystem::path& p,
const unsigned int /*version*/) {
std::string s;
s = p.generic_string();
ar & boost::serialization::make_nvp("path", s);
}
示例6: runtime_error
std::shared_ptr<rett> createAny(const boost::filesystem::path & libpath, const std::string & methodName)
{
#ifdef VCMI_ANDROID
// android currently doesn't support loading libs dynamically, so the access to the known libraries
// is possible only via specializations of this template
throw std::runtime_error("Could not resolve ai library " + libpath.generic_string());
#else
typedef void(* TGetAIFun)(std::shared_ptr<rett> &);
typedef void(* TGetNameFun)(char *);
char temp[150];
TGetAIFun getAI = nullptr;
TGetNameFun getName = nullptr;
#ifdef VCMI_WINDOWS
HMODULE dll = LoadLibraryW(libpath.c_str());
if (dll)
{
getName = (TGetNameFun)GetProcAddress(dll, "GetAiName");
getAI = (TGetAIFun)GetProcAddress(dll, methodName.c_str());
}
#else // !VCMI_WINDOWS
void *dll = dlopen(libpath.string().c_str(), RTLD_LOCAL | RTLD_LAZY);
if (dll)
{
getName = (TGetNameFun)dlsym(dll, "GetAiName");
getAI = (TGetAIFun)dlsym(dll, methodName.c_str());
}
#endif // VCMI_WINDOWS
if (!dll)
{
logGlobal->error("Cannot open dynamic library (%s). Throwing...", libpath.string());
throw std::runtime_error("Cannot open dynamic library");
}
else if(!getName || !getAI)
{
logGlobal->error("%s does not export method %s", libpath.string(), methodName);
#ifdef VCMI_WINDOWS
FreeLibrary(dll);
#else
dlclose(dll);
#endif
throw std::runtime_error("Cannot find method " + methodName);
}
getName(temp);
logGlobal->info("Loaded %s", temp);
std::shared_ptr<rett> ret;
getAI(ret);
if(!ret)
logGlobal->error("Cannot get AI!");
return ret;
#endif //!VCMI_ANDROID
}
示例7: is_it_done
bool is_it_done(
const bfs::path& filepath,
size_map_t& sizes ) {
bs::error_code ec;
if ( bfs::is_regular_file( filepath, ec ) &&
ec == err::success &&
( sizes.count( filepath.generic_string() ) == 0 ||
sizes[filepath.generic_string()] != bfs::file_size( filepath ) ) ) {
return false;
}
else if ( bfs::is_directory( filepath, ec ) && ec == err::success ) {
for ( bfs::directory_iterator iter( filepath ), end_iter; iter != end_iter; iter++ ) {
if ( !is_it_done( iter->path(), sizes ) ) {
return false;
}
}
}
return true;
}
示例8: beginParsing
void IParser::beginParsing(boost::filesystem::path path){
std::ifstream open(path.generic_string(),std::ios_base::binary);
m_size = boost::filesystem::file_size(path);
m_readPosition = 0;
m_buffer = new char[m_size];
open.read(m_buffer,m_size);
open.close();
m_document = DataDocumentPtr(new DataDocument);
}
示例9: target
void
writeNode(xercesc::DOMNode& node,
const boost::filesystem::path& file,
const WriteParameters& params)
{
Platform xmlplat;
xercesc::LocalFileFormatTarget target(String(file.generic_string()));
write_target(node, target, params);
}
示例10: 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());
}
}
示例11: setLink
void Attribute::setLink(const boost::filesystem::path &l)
{
_link = l.generic_string();
assert(name != _link);
data = NULL;
_m = Mat();
dims = 0;
size.resize(0);
}
示例12: 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
}
示例13: hashFile
void hashFile(const boost::filesystem::path& path, Hash& algorithm)
{
std::ifstream fileStream(path.generic_string(), std::ios::binary);
if(fileStream.is_open()) {
while(!fileStream.eof()) {
char buffer[4096];
fileStream.read(buffer, 4096);
int bytesRead = fileStream.gcount();
algorithm.add(buffer, bytesRead);
}
}
}
示例14: open
Status FTDCFileReader::open(const boost::filesystem::path& file) {
_stream.open(file.c_str(), std::ios_base::in | std::ios_base::binary);
if (!_stream.is_open()) {
return Status(ErrorCodes::FileStreamFailed, "Failed to open file " + file.generic_string());
}
_fileSize = boost::filesystem::file_size(file);
_file = file;
return Status::OK();
}
示例15: handle
boost::optional<ModuleTemplate> ModuleTemplateInstance::CreateFromPath(boost::filesystem::path const& path)
{
#ifdef _WIN32
HMODULE syshandle = LoadLibrary(path.generic_string().c_str());
#else // Posix
void* syshandle = dlopen(path.generic_string().c_str(), RTLD_LAZY);
#endif
if (!syshandle)
return boost::none;
InternalHandleType handle(syshandle, [](void* handle)
{
#ifdef _WIN32
FreeLibrary((HMODULE)handle);
#else // Posix
dlclose(handle);
#endif
});
#ifdef _WIN32
unwrap_function<ModuleCreateFunction>::function_ptr const function =
(unwrap_function<ModuleCreateFunction>::function_ptr)GetProcAddress(syshandle, CREATE_MODULE_FUNCTION_NAME);
#else // Posix
// Silences "warning: dereferencing type-punned pointer will break strict-aliasing rules" warnings according to:
// http://en.wikipedia.org/wiki/Dynamic_loading
union { unwrap_function<ModuleCreateFunction>::function_ptr function; void* raw; } alias;
alias.raw = dlsym(syshandle, CREATE_MODULE_FUNCTION_NAME);
unwrap_function<ModuleCreateFunction>::function_ptr function = alias.function;
#endif
if (!function)
return boost::none;
return boost::make_optional(ModuleTemplate(
new ModuleTemplateInstance(std::move(handle), function)));
}