本文整理汇总了C++中TryParse函数的典型用法代码示例。如果您正苦于以下问题:C++ TryParse函数的具体用法?C++ TryParse怎么用?C++ TryParse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TryParse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SplitString
void TextureReplacer::ParseHashRange(const std::string &key, const std::string &value) {
std::vector<std::string> keyParts;
SplitString(key, ',', keyParts);
std::vector<std::string> valueParts;
SplitString(value, ',', valueParts);
if (keyParts.size() != 3 || valueParts.size() != 2) {
ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, expecting addr,w,h = w,h", key.c_str(), value.c_str());
return;
}
u32 addr;
u32 fromW;
u32 fromH;
if (!TryParse(keyParts[0], &addr) || !TryParse(keyParts[1], &fromW) || !TryParse(keyParts[2], &fromH)) {
ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, key format is 0x12345678,512,512", key.c_str(), value.c_str());
return;
}
u32 toW;
u32 toH;
if (!TryParse(valueParts[0], &toW) || !TryParse(valueParts[1], &toH)) {
ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, value format is 512,512", key.c_str(), value.c_str());
return;
}
if (toW > fromW || toH > fromH) {
ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, range bigger than source", key.c_str(), value.c_str());
return;
}
const u64 rangeKey = ((u64)addr << 32) | (fromW << 16) | fromH;
hashranges_[rangeKey] = WidthHeightPair(toW, toH);
}
示例2: WxStrToStr
void CMemoryWindow::OnSetMemoryValue(wxCommandEvent& event)
{
if (!Memory::IsInitialized())
{
WxUtils::ShowErrorDialog(_("Cannot set uninitialized memory."));
return;
}
std::string str_addr = WxStrToStr(m_address_search_ctrl->GetValue());
u32 addr;
if (!TryParse("0x" + str_addr, &addr))
{
WxUtils::ShowErrorDialog(wxString::Format(_("Invalid address: %s"), str_addr.c_str()));
return;
}
std::string str_val = WxStrToStr(m_value_text_ctrl->GetValue());
u32 val;
if (!TryParse("0x" + str_val, &val))
{
WxUtils::ShowErrorDialog(wxString::Format(_("Invalid value: %s"), str_val.c_str()));
return;
}
PowerPC::HostWrite_U32(val, addr);
m_memory_view->Refresh();
}
示例3: SplitString
// Update the local perspectives array
void CFrame::LoadIniPerspectives()
{
Perspectives.clear();
std::vector<std::string> VPerspectives;
std::string _Perspectives;
IniFile ini;
ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
IniFile::Section* perspectives = ini.GetOrCreateSection("Perspectives");
perspectives->Get("Perspectives", &_Perspectives, "Perspective 1");
perspectives->Get("Active", &ActivePerspective, 0);
SplitString(_Perspectives, ',', VPerspectives);
for (auto& VPerspective : VPerspectives)
{
SPerspectives Tmp;
std::string _Section, _Perspective, _Widths, _Heights;
std::vector<std::string> _SWidth, _SHeight;
Tmp.Name = VPerspective;
// Don't save a blank perspective
if (Tmp.Name.empty())
{
continue;
}
_Section = StringFromFormat("P - %s", Tmp.Name.c_str());
IniFile::Section* perspec_section = ini.GetOrCreateSection(_Section);
perspec_section->Get("Perspective", &_Perspective,
"layout2|"
"name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|"
"name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|"
"dock_size(5,0,0)=22|dock_size(4,0,0)=333|");
perspec_section->Get("Width", &_Widths, "70,25");
perspec_section->Get("Height", &_Heights, "80,80");
Tmp.Perspective = StrToWxStr(_Perspective);
SplitString(_Widths, ',', _SWidth);
SplitString(_Heights, ',', _SHeight);
for (auto& Width : _SWidth)
{
int _Tmp;
if (TryParse(Width, &_Tmp))
Tmp.Width.push_back(_Tmp);
}
for (auto& Height : _SHeight)
{
int _Tmp;
if (TryParse(Height, &_Tmp))
Tmp.Height.push_back(_Tmp);
}
Perspectives.push_back(Tmp);
}
}
示例4: LoadPatchSection
void LoadPatchSection(const char *section, std::vector<Patch> &patches, IniFile &ini)
{
std::vector<std::string> lines;
if (!ini.GetLines(section, lines))
return;
Patch currentPatch;
for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
{
std::string line = *iter;
if (line.size())
{
if (line[0] == '+' || line[0] == '$')
{
// Take care of the previous code
if (currentPatch.name.size())
patches.push_back(currentPatch);
currentPatch.entries.clear();
// Set active and name
currentPatch.active = (line[0] == '+') ? true : false;
if (currentPatch.active)
currentPatch.name = line.substr(2, line.size() - 2);
else
currentPatch.name = line.substr(1, line.size() - 1);
continue;
}
std::string::size_type loc = line.find_first_of('=', 0);
if (loc != std::string::npos)
line[loc] = ':';
std::vector<std::string> items;
SplitString(line, ':', items);
if (items.size() >= 3)
{
PatchEntry pE;
bool success = true;
success &= TryParse(items[0], &pE.address);
success &= TryParse(items[2], &pE.value);
pE.type = PatchType(std::find(PatchTypeStrings, PatchTypeStrings + 3, items[1]) - PatchTypeStrings);
success &= (pE.type != (PatchType)3);
if (success)
currentPatch.entries.push_back(pE);
}
}
}
if (currentPatch.name.size() && currentPatch.entries.size())
patches.push_back(currentPatch);
}
示例5: TryParse
bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval, const wxString& separators )
{
dest = defval;
wxStringTokenizer parts( src, separators );
wxPoint point;
wxSize size;
if( !TryParse( point, parts ) ) return false;
if( !TryParse( size, parts ) ) return false;
dest = wxRect( point, size );
return true;
}
示例6: Parse
short NShort::Parse(const Text &text)
{
short s = 0;
if (!TryParse(text, s))
throw new Exception("Number out of limits", __FILE__, __LINE__, __func__);
return s;
}
示例7: Parse
unsigned char NUChar::Parse(const Text &text)
{
unsigned char n = 0;
if (!TryParse(text, n))
throw new Exception("Number out of limits", __FILE__, __LINE__, __func__);
return n;
}
示例8: Parse
T Parse( const wxString& src, const wxString& separators=L",")
{
T retval;
if( !TryParse( retval, src, separators ) )
throw Exception::ParseError( "Parse failure on call to " + fromUTF8(__WXFUNCTION__) + ": " + src );
return retval;
}
示例9: GetValueByRowCol
void CWatchView::OnMouseDownR(wxGridEvent& event)
{
// popup menu
int row = event.GetRow();
int col = event.GetCol();
m_selectedRow = row;
if (col == 1 || col == 2)
{
wxString strNewVal = GetValueByRowCol(row, col);
TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress);
}
wxMenu menu;
if (row != 0 && row != static_cast<int>(PowerPC::debug_interface.GetWatches().size() + 1))
{
// i18n: This kind of "watch" is used for watching emulated memory.
// It's not related to timekeeping devices.
menu.Append(IDM_DELETEWATCH, _("&Delete watch"));
}
if (row != 0 && row != static_cast<int>(PowerPC::debug_interface.GetWatches().size() + 1) &&
(col == 1 || col == 2))
{
menu.Append(IDM_ADDMEMCHECK, _("Add memory &breakpoint"));
menu.Append(IDM_VIEWMEMORY, _("View &memory"));
}
PopupMenu(&menu);
}
示例10: ParsePartitionDirectoryName
static std::optional<PartitionType> ParsePartitionDirectoryName(const std::string& name)
{
if (name.size() < 2)
return {};
if (!strcasecmp(name.c_str(), "DATA"))
return PartitionType::Game;
if (!strcasecmp(name.c_str(), "UPDATE"))
return PartitionType::Update;
if (!strcasecmp(name.c_str(), "CHANNEL"))
return PartitionType::Channel;
if (name[0] == 'P' || name[0] == 'p')
{
// e.g. "P-HA8E" (normally only used for Super Smash Bros. Brawl's VC partitions)
if (name[1] == '-' && name.size() == 6)
{
const u32 result = Common::swap32(reinterpret_cast<const u8*>(name.data() + 2));
return static_cast<PartitionType>(result);
}
// e.g. "P0"
if (std::all_of(name.cbegin() + 1, name.cend(), [](char c) { return c >= '0' && c <= '9'; }))
{
u32 result;
if (TryParse(name.substr(1), &result))
return static_cast<PartitionType>(result);
}
}
return {};
}
示例11: GetValueByRowCol
void CWatchView::OnMouseDownR(wxGridEvent& event)
{
// popup menu
int row = event.GetRow();
int col = event.GetCol();
m_selectedRow = row;
if (col == 1 || col == 2)
{
wxString strNewVal = GetValueByRowCol(row, col);
TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress);
}
wxMenu menu;
if (row != 0 && row != (int)(PowerPC::watches.GetWatches().size() + 1))
menu.Append(IDM_DELETEWATCH, _("&Delete watch"));
if (row != 0 && row != (int)(PowerPC::watches.GetWatches().size() + 1) && (col == 1 || col == 2))
{
menu.Append(IDM_ADDMEMCHECK, _("Add memory &breakpoint"));
menu.Append(IDM_VIEWMEMORY, _("View &memory"));
}
PopupMenu(&menu);
}
示例12: SplitString
// Update the local perspectives array
void CFrame::LoadIniPerspectives()
{
Perspectives.clear();
std::vector<std::string> VPerspectives;
std::string _Perspectives;
IniFile ini;
ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
ini.Get("Perspectives", "Perspectives", &_Perspectives, "Perspective 1");
ini.Get("Perspectives", "Active", &ActivePerspective, 0);
SplitString(_Perspectives, ',', VPerspectives);
for (u32 i = 0; i < VPerspectives.size(); i++)
{
SPerspectives Tmp;
std::string _Section, _Perspective, _Width, _Height;
std::vector<std::string> _SWidth, _SHeight;
Tmp.Name = VPerspectives[i];
// Don't save a blank perspective
if (Tmp.Name.empty()) continue;
_Section = StringFromFormat("P - %s", Tmp.Name.c_str());
ini.Get(_Section.c_str(), "Perspective", &_Perspective,
"layout2|"
"name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|"
"name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|"
"dock_size(5,0,0)=22|dock_size(4,0,0)=333|");
ini.Get(_Section.c_str(), "Width", &_Width, "70,25");
ini.Get(_Section.c_str(), "Height", &_Height, "80,80");
Tmp.Perspective = wxString::FromAscii(_Perspective.c_str());
SplitString(_Width, ',', _SWidth);
SplitString(_Height, ',', _SHeight);
for (u32 j = 0; j < _SWidth.size(); j++)
{
int _Tmp;
if (TryParse(_SWidth[j].c_str(), &_Tmp)) Tmp.Width.push_back(_Tmp);
}
for (u32 j = 0; j < _SHeight.size(); j++)
{
int _Tmp;
if (TryParse(_SHeight[j].c_str(), &_Tmp)) Tmp.Height.push_back(_Tmp);
}
Perspectives.push_back(Tmp);
}
}
示例13: TryParse
void IniLoader::Entry( const wxString& var, wxRect& value, const wxRect defvalue )
{
if( !m_Config )
{
value = defvalue; return;
}
TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue );
}
示例14: Get
bool IniFile::Section::Get(const std::string& key, double* value, double defaultValue)
{
std::string temp;
bool retval = Get(key, &temp);
if (retval && TryParse(temp, value))
return true;
*value = defaultValue;
return false;
}
示例15: Get
bool IniFile::Section::Get(const char* key, float* value, float defaultValue)
{
std::string temp;
bool retval = Get(key, &temp, 0);
if (retval && TryParse(temp.c_str(), value))
return true;
*value = defaultValue;
return false;
}