本文整理汇总了C++中fs::file::trunc方法的典型用法代码示例。如果您正苦于以下问题:C++ file::trunc方法的具体用法?C++ file::trunc怎么用?C++ file::trunc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs::file
的用法示例。
在下文中一共展示了file::trunc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save_gui_cfg
void save_gui_cfg()
{
YAML::Emitter out;
out.SetSeqFormat(YAML::Flow);
out << g_gui_cfg;
// Save to file
s_gui_cfg.seek(0);
s_gui_cfg.trunc(0);
s_gui_cfg.write(out.c_str(), out.size());
}
示例2: ppu_decoder_modes
//.........这里部分代码省略.........
s_subpanel_core1->Add(chbox_core_load_liblv2, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_core2->Add(s_round_core_lle, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_core->Add(s_subpanel_core1);
s_subpanel_core->Add(s_subpanel_core2);
// Graphics
s_subpanel_graphics1->Add(s_round_gs_render, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics1->Add(s_round_gs_res, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics1->Add(s_round_gs_d3d_adapter, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics1->Add(chbox_gs_dump_color, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics1->Add(chbox_gs_read_color, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics1->Add(chbox_gs_dump_depth, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics1->Add(chbox_gs_read_depth, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics1->Add(chbox_gs_gl_legacy_buffers, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics2->Add(s_round_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics2->Add(s_round_gs_frame_limit, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics2->AddSpacer(68);
s_subpanel_graphics2->Add(chbox_gs_debug_output, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics2->Add(chbox_gs_overlay, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics2->Add(chbox_gs_log_prog, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics2->Add(chbox_gs_vsync, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_graphics->Add(s_subpanel_graphics1);
s_subpanel_graphics->Add(s_subpanel_graphics2);
// Input - Output
s_subpanel_io1->Add(s_round_io_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_io1->Add(s_round_io_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_io1->Add(s_round_io_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_io2->Add(s_round_io_camera, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_io2->Add(s_round_io_camera_type, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_io->Add(s_subpanel_io1);
s_subpanel_io->Add(s_subpanel_io2);
// Audio
s_subpanel_audio->Add(s_round_audio_out, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_audio->Add(chbox_audio_dump, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_audio->Add(chbox_audio_conv, wxSizerFlags().Border(wxALL, 5).Expand());
// Miscellaneous
s_subpanel_misc->Add(chbox_hle_exitonstop, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_misc->Add(chbox_hle_always_start, wxSizerFlags().Border(wxALL, 5).Expand());
// Auto Pause
s_subpanel_misc->Add(chbox_dbg_ap_systemcall, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_misc->Add(chbox_dbg_ap_functioncall, wxSizerFlags().Border(wxALL, 5).Expand());
// Networking
s_subpanel_networking->Add(s_round_net_status, wxSizerFlags().Border(wxALL, 5).Expand());
// System
s_subpanel_system->Add(chbox_vfs_enable_host_root, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_system->Add(s_round_sys_lang, wxSizerFlags().Border(wxALL, 5).Expand());
// Buttons
wxBoxSizer* s_b_panel(new wxBoxSizer(wxHORIZONTAL));
s_b_panel->Add(new wxButton(this, wxID_OK), wxSizerFlags().Border(wxALL, 5).Bottom());
s_b_panel->Add(new wxButton(this, wxID_CANCEL), wxSizerFlags().Border(wxALL, 5).Bottom());
// Resize panels
SetSizerAndFit(s_subpanel_core, false);
SetSizerAndFit(s_subpanel_graphics, false);
SetSizerAndFit(s_subpanel_io, false);
SetSizerAndFit(s_subpanel_audio, false);
SetSizerAndFit(s_subpanel_misc, false);
SetSizerAndFit(s_subpanel_networking, false);
SetSizerAndFit(s_subpanel_system, false);
SetSizerAndFit(s_b_panel, false);
SetSize(width + 26, height + 80);
if (ShowModal() == wxID_OK)
{
std::set<std::string> lle_selected;
for (auto& i : lle_module_list)
{
if (i.second) // selected
{
lle_selected.emplace(i.first);
}
}
saved.reset();
saved["Core"]["Load libraries"] = std::vector<std::string>(lle_selected.begin(), lle_selected.end());
for (auto& pad : pads)
{
pad->save();
}
loaded += saved;
YAML::Emitter out;
emit(out, loaded);
// Save config
config.seek(0);
config.trunc(0);
config.write(out.c_str(), out.size());
}
}
示例3: save_object
void save_object(const fs::file& stream, const psf::registry& psf)
{
std::vector<def_table_t> indices; indices.reserve(psf.size());
// Generate indices and calculate key table length
std::size_t key_offset = 0, data_offset = 0;
for (const auto& entry : psf)
{
def_table_t index;
index.key_off = ::narrow<u32>(key_offset);
index.param_fmt = entry.second.type();
index.param_len = entry.second.size();
index.param_max = entry.second.max();
index.data_off = ::narrow<u32>(data_offset);
// Update offsets:
key_offset += ::narrow<u32>(entry.first.size() + 1); // key size
data_offset += index.param_max;
indices.push_back(index);
}
// Align next section (data) offset
key_offset = ::align(key_offset, 4);
// Generate header
header_t header;
header.magic = "\0PSF"_u32;
header.version = 0x101;
header.off_key_table = ::narrow<u32>(sizeof(header_t) + sizeof(def_table_t) * psf.size());
header.off_data_table = ::narrow<u32>(header.off_key_table + key_offset);
header.entries_num = ::narrow<u32>(psf.size());
// Save header and indices
stream.write(header);
stream.write(indices);
// Save key table
for (const auto& entry : psf)
{
stream.write(entry.first);
stream.write('\0');
}
// Skip padding
stream.trunc(stream.seek(header.off_data_table));
// Save data
for (const auto& entry : psf)
{
const auto fmt = entry.second.type();
const u32 max = entry.second.max();
if (fmt == format::integer && max == sizeof(u32))
{
const le_t<u32> value = entry.second.as_integer();
stream.write(value);
}
else if (fmt == format::string || fmt == format::array)
{
const std::string& value = entry.second.as_string();
const std::size_t size = std::min<std::size_t>(max, value.size());
if (value.size() + (fmt == format::string) > max)
{
// TODO: check real limitations of PSF format
LOG_ERROR(LOADER, "Entry value shrinkage (key='%s', value='%s', size=0x%zx, max=0x%x)", entry.first, value, size, max);
}
stream.write(value);
stream.trunc(stream.seek(max - size, fs::seek_cur)); // Skip up to max_size
}
else
{
fmt::throw_exception("Invalid entry format (key='%s', fmt=0x%x)" HERE, entry.first, fmt);
}
}
}