本文整理汇总了C++中SmartPtr::DefaultNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ SmartPtr::DefaultNumber方法的具体用法?C++ SmartPtr::DefaultNumber怎么用?C++ SmartPtr::DefaultNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmartPtr
的用法示例。
在下文中一共展示了SmartPtr::DefaultNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNumericValue
bool OptionsList::GetNumericValue(const std::string& tag, Number& value,
const std::string& prefix) const
{
SmartPtr<const RegisteredOption> option = NULL;
if (IsValid(reg_options_)) {
option = reg_options_->GetOption(tag);
if (IsNull(option)) {
std::string msg = "IPOPT tried to get the value of Option: " + tag;
msg += ". It is not a valid registered option.";
THROW_EXCEPTION(OPTION_INVALID, msg);
}
if (option->Type() != OT_Number) {
std::string msg = "IPOPT tried to get the value of Option: " + tag;
msg += ". It is a valid option, but it is of type ";
if (option->Type() == OT_Integer) {
msg += " Integer";
}
else if (option->Type() == OT_String) {
msg += " String";
}
else {
msg += " Unknown";
}
msg += ", not of type Number. Please check the documentation for options.";
if (IsValid(jnlst_)) {
option->OutputDescription(*jnlst_);
}
THROW_EXCEPTION(OPTION_INVALID, msg);
}
}
std::string strvalue;
if (find_tag(tag, prefix, strvalue)) {
char* p_end;
Number retval = strtod(strvalue.c_str(), &p_end);
if (*p_end!='\0' && !isspace(*p_end)) {
std::string msg = "Option \"" + tag +
"\": Double value expected, but non-numeric value \"" +
strvalue+"\" found.\n";
THROW_EXCEPTION(OPTION_INVALID, msg);
}
value = retval;
return true;
}
else if (IsValid(option)) {
value = option->DefaultNumber();
return false;
}
return false;
}
示例2: GetNumericValue
bool OptionsList::GetNumericValue(const std::string& tag, Number& value,
const std::string& prefix) const
{
SmartPtr<const RegisteredOption> option = NULL;
if (IsValid(reg_options_)) {
option = reg_options_->GetOption(tag);
if (IsNull(option)) {
std::string msg = "IPOPT tried to get the value of Option: " + tag;
msg += ". It is not a valid registered option.";
THROW_EXCEPTION(OPTION_INVALID, msg);
}
if (option->Type() != OT_Number) {
std::string msg = "IPOPT tried to get the value of Option: " + tag;
msg += ". It is a valid option, but it is of type ";
if (option->Type() == OT_Integer) {
msg += " Integer";
}
else if (option->Type() == OT_String) {
msg += " String";
}
else {
msg += " Unknown";
}
msg += ", not of type Number. Please check the documentation for options.";
if (IsValid(jnlst_)) {
option->OutputDescription(*jnlst_);
}
THROW_EXCEPTION(OPTION_INVALID, msg);
}
}
std::string strvalue;
if (find_tag(tag, prefix, strvalue)) {
// Some people like to use 'd' instead of 'e' in floating point
// numbers. Therefore, we change a 'd' to an 'e'
char* buffer = new char[strvalue.length()+1];
strcpy(buffer, strvalue.c_str());
for (int i=0; i<(int)strvalue.length(); ++i) {
if (buffer[i]=='d' || buffer[i]=='D') {
buffer[i] = 'e';
}
}
char* p_end;
Number retval = strtod(buffer, &p_end);
if (*p_end!='\0' && !isspace(*p_end)) {
delete [] buffer;
std::string msg = "Option \"" + tag +
"\": Double value expected, but non-numeric value \"" +
strvalue+"\" found.\n";
THROW_EXCEPTION(OPTION_INVALID, msg);
}
delete [] buffer;
value = retval;
return true;
}
else if (IsValid(option)) {
value = option->DefaultNumber();
return false;
}
return false;
}