本文整理汇总了C++中fs::path::generic_string方法的典型用法代码示例。如果您正苦于以下问题:C++ path::generic_string方法的具体用法?C++ path::generic_string怎么用?C++ path::generic_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs::path
的用法示例。
在下文中一共展示了path::generic_string方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_short_path
fs::path get_short_path(const fs::path& p)
{
// truncate path no more than "x/y":
std::string s = p.generic_string();
std::string::size_type n = s.find('/');
if(n != std::string::npos)
{
n = s.find('/', n+1);
if(n != std::string::npos)
s.erase(n);
}
return s;
}
示例2: loadObject
void AudioObjApp::loadObject( fs::path filepath )
{
try {
ObjLoader loader( DataSourcePath::create( filepath.string() ) );
TriMesh mesh;
loader.load( &mesh );
mVbo = gl::VboMesh( mesh );
}
catch( ... ) {
console() << "cannot load file: " << filepath.generic_string() << endl;
return;
}
}
示例3: generateCode
bool CCompilerDriver::generateCode(const fs::path &inputPath, std::string &code)
{
CFileStream stream(inputPath.generic_string());
CStderrErrorStream errorStream;
CScanner scanner(stream, errorStream);
CParseContext context(scanner, errorStream);
CEmittingParser parser(context);
if (!parser.ParseAll())
{
return false;
}
code = parser.GetResultCode();
return true;
}
示例4: path_to_generic
std::string path_to_generic(fs::path const& x)
{
return x.generic_string();
}
示例5:
const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const
{
if (prebuildinfo.external_toolchain_file ||
(!prebuildinfo.cmake_system_name.empty() && prebuildinfo.cmake_system_name != "WindowsStore"))
{
static Toolset external_toolset = []() -> Toolset {
Toolset ret;
ret.dumpbin = "";
ret.supported_architectures = {
ToolsetArchOption{"", System::get_host_processor(), System::get_host_processor()}};
ret.vcvarsall = "";
ret.vcvarsall_options = {};
ret.version = "external";
ret.visual_studio_root_path = "";
return ret;
}();
return external_toolset;
}
#if !defined(_WIN32)
Checks::exit_with_message(VCPKG_LINE_INFO, "Cannot build windows triplets from non-windows.");
#else
const std::vector<Toolset>& vs_toolsets =
this->toolsets.get_lazy([this]() { return VisualStudio::find_toolset_instances_preferred_first(*this); });
std::vector<const Toolset*> candidates = Util::element_pointers(vs_toolsets);
const auto tsv = prebuildinfo.platform_toolset.get();
auto vsp = prebuildinfo.visual_studio_path.get();
if (!vsp && !default_vs_path.empty())
{
vsp = &default_vs_path;
}
if (tsv && vsp)
{
Util::stable_keep_if(
candidates, [&](const Toolset* t) { return *tsv == t->version && *vsp == t->visual_studio_root_path; });
Checks::check_exit(VCPKG_LINE_INFO,
!candidates.empty(),
"Could not find Visual Studio instance at %s with %s toolset.",
vsp->u8string(),
*tsv);
Checks::check_exit(VCPKG_LINE_INFO, candidates.size() == 1);
return *candidates.back();
}
if (tsv)
{
Util::stable_keep_if(candidates, [&](const Toolset* t) { return *tsv == t->version; });
Checks::check_exit(
VCPKG_LINE_INFO, !candidates.empty(), "Could not find Visual Studio instance with %s toolset.", *tsv);
}
if (vsp)
{
const fs::path vs_root_path = *vsp;
Util::stable_keep_if(candidates,
[&](const Toolset* t) { return vs_root_path == t->visual_studio_root_path; });
Checks::check_exit(VCPKG_LINE_INFO,
!candidates.empty(),
"Could not find Visual Studio instance at %s.",
vs_root_path.generic_string());
}
Checks::check_exit(VCPKG_LINE_INFO, !candidates.empty(), "No suitable Visual Studio instances were found");
return *candidates.front();
#endif
}
示例6: read_lib
LibInfo read_lib(const fs::path& path)
{
std::fstream fs(path, std::ios::in | std::ios::binary | std::ios::ate);
Checks::check_exit(VCPKG_LINE_INFO, fs.is_open(), "Could not open file %s for reading", path.generic_string());
read_and_verify_archive_file_signature(fs);
Marker marker;
marker.set_to_current_pos(fs);
// First Linker Member
const ArchiveMemberHeader first_linker_member_header = ArchiveMemberHeader::read(fs);
Checks::check_exit(VCPKG_LINE_INFO,
first_linker_member_header.name().substr(0, 2) == "/ ",
"Could not find proper first linker member");
marker.advance_by(ArchiveMemberHeader::HEADER_SIZE + first_linker_member_header.member_size());
marker.seek_to_marker(fs);
const ArchiveMemberHeader second_linker_member_header = ArchiveMemberHeader::read(fs);
Checks::check_exit(VCPKG_LINE_INFO,
second_linker_member_header.name().substr(0, 2) == "/ ",
"Could not find proper second linker member");
// The first 4 bytes contains the number of archive members
const auto archive_member_count = read_value_from_stream<uint32_t>(fs);
const OffsetsArray offsets = OffsetsArray::read(fs, archive_member_count);
marker.advance_by(ArchiveMemberHeader::HEADER_SIZE + second_linker_member_header.member_size());
marker.seek_to_marker(fs);
const bool has_longname_member_header = peek_value_from_stream<uint16_t>(fs) == 0x2F2F;
if (has_longname_member_header)
{
const ArchiveMemberHeader longnames_member_header = ArchiveMemberHeader::read(fs);
marker.advance_by(ArchiveMemberHeader::HEADER_SIZE + longnames_member_header.member_size());
marker.seek_to_marker(fs);
}
std::set<MachineType> machine_types;
// Next we have the obj and pseudo-object files
for (const uint32_t offset : offsets.data)
{
marker.set_to_offset(offset + ArchiveMemberHeader::HEADER_SIZE); // Skip the header, no need to read it.
marker.seek_to_marker(fs);
const auto first_two_bytes = peek_value_from_stream<uint16_t>(fs);
const bool is_import_header = to_machine_type(first_two_bytes) == MachineType::UNKNOWN;
const MachineType machine =
is_import_header ? ImportHeader::read(fs).machine_type() : CoffFileHeader::read(fs).machine_type();
machine_types.insert(machine);
}
return {std::vector<MachineType>(machine_types.cbegin(), machine_types.cend())};
}
示例7: read_dll
DllInfo read_dll(const fs::path& path)
{
std::fstream fs(path, std::ios::in | std::ios::binary | std::ios::ate);
Checks::check_exit(VCPKG_LINE_INFO, fs.is_open(), "Could not open file %s for reading", path.generic_string());
read_and_verify_pe_signature(fs);
CoffFileHeader header = CoffFileHeader::read(fs);
const MachineType machine = header.machine_type();
return {machine};
}
示例8: upgrade_to_slash_terminated_sorted_format
static void upgrade_to_slash_terminated_sorted_format(Files::Filesystem& fs,
std::vector<std::string>* lines,
const fs::path& listfile_path)
{
static bool was_tracked = false;
if (lines->empty())
{
return;
}
if (lines->at(0).back() == '/')
{
return; // File already in the new format
}
if (!was_tracked)
{
was_tracked = true;
Metrics::track_property("listfile", "update to new format");
}
// The files are sorted such that directories are placed just before the files they contain
// (They are not necessarily sorted alphabetically, e.g. libflac)
// Therefore we can detect the entries that represent directories by comparing every element with the next one
// and checking if the next has a slash immediately after the current one's length
for (size_t i = 0; i < lines->size() - 1; i++)
{
std::string& current_string = lines->at(i);
const std::string& next_string = lines->at(i + 1);
const size_t potential_slash_char_index = current_string.length();
// Make sure the index exists first
if (next_string.size() > potential_slash_char_index && next_string.at(potential_slash_char_index) == '/')
{
current_string += '/'; // Mark as a directory
}
}
// After suffixing the directories with a slash, we can now sort.
// We cannot sort before adding the suffixes because the following (actual example):
/*
x86-windows/include/FLAC <<<<<< This would be separated from its group due to sorting
x86-windows/include/FLAC/all.h
x86-windows/include/FLAC/assert.h
x86-windows/include/FLAC/callback.h
x86-windows/include/FLAC++
x86-windows/include/FLAC++/all.h
x86-windows/include/FLAC++/decoder.h
x86-windows/include/FLAC++/encoder.h
*
x86-windows/include/FLAC/ <<<<<< This will now be kept with its group when sorting
x86-windows/include/FLAC/all.h
x86-windows/include/FLAC/assert.h
x86-windows/include/FLAC/callback.h
x86-windows/include/FLAC++/
x86-windows/include/FLAC++/all.h
x86-windows/include/FLAC++/decoder.h
x86-windows/include/FLAC++/encoder.h
*/
// Note that after sorting, the FLAC++/ group will be placed before the FLAC/ group
// The new format is lexicographically sorted
std::sort(lines->begin(), lines->end());
// Replace the listfile on disk
const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated";
fs.write_lines(updated_listfile_path, *lines);
fs.rename(updated_listfile_path, listfile_path);
}