std::string ScalarSelectionDialog::GetValueString(const wxVariant& variant, std::type_index type, int precision) { std::string result; if (!variant.IsNull()) { if (IsFloat(type)) { std::stringstream strstream; if (precision > 0) { strstream << std::setprecision(precision) << std::fixed << variant.GetDouble(); } else { strstream << std::fixed << variant.GetDouble(); } auto tmpStr = strstream.str(); size_t last_not_zero = tmpStr.find_last_not_of('0'); result = tmpStr.substr(0, last_not_zero == std::string::npos ? last_not_zero : last_not_zero+1); } else if (IsIntegral(type)) { result = std::to_string(variant.GetInteger()); } } return result; }
void ScalarSelectionDialog::AssignToValue() { auto valueStr = m_pTextCtrl->GetValue().ToStdString(); if (IsFloat(m_type)) { m_value = std::stod(valueStr); } else if (IsIntegral(m_type)) { m_value = std::stol(valueStr); } }
bool Value::isIntegral() const { switch (type()) { case intValue: case uintValue: return true; case realValue: #if defined(JSON_HAS_INT64) // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we // require the value to be strictly less than the limit. return value_.real_ >= double(minInt64) && value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_); #else return value_.real_ >= minInt && value_.real_ <= maxUInt && IsIntegral(value_.real_); #endif // JSON_HAS_INT64 default: break; } return false; }
bool Value::isUInt() const { switch (type_) { case intValue: return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt); case uintValue: return value_.uint_ <= maxUInt; case realValue: return value_.real_ >= 0 && value_.real_ <= maxUInt && IsIntegral(value_.real_); default: break; } return false; }
bool Value::isInt() const { switch (type()) { case intValue: #if defined(JSON_HAS_INT64) return value_.int_ >= minInt && value_.int_ <= maxInt; #else return true; #endif case uintValue: return value_.uint_ <= UInt(maxInt); case realValue: return value_.real_ >= minInt && value_.real_ <= maxInt && IsIntegral(value_.real_); default: break; } return false; }
bool Value::isInt64() const { #if defined(JSON_HAS_INT64) switch (type_) { case intValue: return true; case uintValue: return value_.uint_ <= UInt64(maxInt64); case realValue: // Note that maxInt64 (= 2^63 - 1) is not exactly representable as a // double, so double(maxInt64) will be rounded up to 2^63. Therefore we // require the value to be strictly less than the limit. return value_.real_ >= double(minInt64) && value_.real_ < double(maxInt64) && IsIntegral(value_.real_); default: break; } #endif // JSON_HAS_INT64 return false; }
StdProperty* TypeBasic::FindProperty( const wchar_t* name ) { StdProperty* prop = NULL; if ( IsIntegral() ) { prop = FindIntProperty( name ); if ( prop != NULL ) return prop; } if ( IsFloatingPoint() ) { prop = FindFloatProperty( name ); if ( prop != NULL ) return prop; } return Type::FindProperty( name ); }
bool Value::isUInt() const { switch (type_) { case intValue: #if defined(JSON_HAS_INT64) return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt); #else return value_.int_ >= 0; #endif case uintValue: #if defined(JSON_HAS_INT64) return value_.uint_ <= maxUInt; #else return true; #endif case realValue: return value_.real_ >= 0 && value_.real_ <= maxUInt && IsIntegral(value_.real_); default: break; } return false; }