void AssertEquals(const glm::dvec3& a, const glm::dvec3& b, const std::string& msg) { bool failure = false; failure |= CheckDouble(a.x, b.x); failure |= CheckDouble(a.y, b.y); failure |= CheckDouble(a.z, b.z); if (failure) { std::cout << "Failed: " + msg << std::endl; std::cout << a << " != " << b << std::endl; fail_num++; } }
void AssertEquals(double a, double b, const std::string& msg) { if (CheckDouble(a, b)) { std::cout << "Failed: " + msg << std::endl; std::cout << a << " != " << b << std::endl; fail_num++; } }
bool DoubleParameter::TranslateExtras(const char * value, const char * extras) { if (value[0] != 0 || !CheckDouble(extras)) return false; Translate(extras); return true; }
bool LongParameters::TranslateExtras(const char * cstr, const char * extras) { if (strchr(cstr, ':') != NULL) return false; int option = index.FindStem(cstr); if (option == -2) { // No need to explain ambiguity here ... will be handle by later call // to Translate() // ExplainAmbiguity(cstr); return false; } LongParameterList * ptr; if (option >= 0) ptr = (LongParameterList *) index.Object(option); else { option = legacyIndex.FindFirstStem(cstr); if (option < 0) return false; ptr = (LongParameterList *) legacyIndex.Object(option); ptr->touched = true; } if (ptr->type == LP_INT_PARAMETER && CheckInteger(extras)) { *(int *) ptr->value = atoi(extras); return true; } else if (ptr->type == LP_DOUBLE_PARAMETER && CheckDouble(extras)) { *(double *) ptr->value = atof(extras); return true; } else if (ptr->type == LP_STRING_PARAMETER) { *(String *) ptr->value = extras; return true; } return false; }
//转换成double,格式为.0 CString CStringChecker::FormatDouble( LPCTSTR cStr ) { CString str = cStr; str.Trim(' '); if(str.IsEmpty()) return ""; if(CheckDouble(str)) { if(str[0] == '-')str.Delete(0); str.TrimLeft('0'); if(str.IsEmpty() || str[0] == '.') { str = '0' + str; } if(CheckIntNumber(str)) { str += ".0"; } else if(str.FindOneOf("eE") == -1) { BOOL bDelete = TRUE; int nStart = str.Find('.') + 1; int nEnd = str.GetLength() - 1; for(int i = nEnd; i >= nStart; i--) { if(str[i] != '0') { bDelete = FALSE; break; } } if(bDelete) { str.Delete(nStart + 1, nEnd - nStart); } } if(*cStr == '-')str = '-' + str; } return str; }
PRINTSIZECHECKRESULT CPrintSize::CheckLastActiveItem(void) { PRINTSIZECHECKRESULT Result; Result = PRINT_SIZE_CHECK_UNCHANGED; switch (m_last_active_item_id) { case IDC_INCHES_WIDE: { Result = CheckDouble(IDC_INCHES_WIDE, m_inches_wide, m_min_inches_wide, m_max_inches_wide, PRINT_SIZE_INCHES_PRECISION); if (Result == PRINT_SIZE_CHECK_CHANGED) { m_Size.x = MakeFixed(m_inches_wide); compute_x_scale(); } break; } case IDC_INCHES_TALL: { Result = CheckDouble(IDC_INCHES_TALL, m_inches_tall, m_min_inches_tall, m_max_inches_tall, PRINT_SIZE_INCHES_PRECISION); if (Result == PRINT_SIZE_CHECK_CHANGED) { m_Size.y = MakeFixed(m_inches_tall); compute_y_scale(); } break; } case IDC_SHEETS_WIDE: { Result = CheckInt(IDC_SHEETS_WIDE, m_sheets_wide, m_min_sheets_wide, m_max_sheets_wide); if (Result == PRINT_SIZE_CHECK_CHANGED) { m_Size.x = m_Tile.x*m_sheets_wide; if (m_TileOverlap.x == 0) { m_Size.x -= (m_PaperMargins.Left+m_PaperMargins.Right); } else { m_Size.x -= (m_sheets_wide-1)*m_TileOverlap.x; } m_inches_wide = MakeDouble(m_Size.x); compute_x_scale(); } break; } case IDC_SHEETS_TALL: { Result = CheckInt(IDC_SHEETS_TALL, m_sheets_tall, m_min_sheets_tall, m_max_sheets_tall); if (Result == PRINT_SIZE_CHECK_CHANGED) { m_Size.y = m_Tile.y*m_sheets_tall; if (m_TileOverlap.y == 0) { m_Size.y -= (m_PaperMargins.Top+m_PaperMargins.Bottom); } else { m_Size.y -= (m_sheets_tall-1)*m_TileOverlap.y; } m_inches_tall = MakeDouble(m_Size.y); compute_y_scale(); } break; } case IDC_PRINT_SCALE: { Result = CheckDouble(IDC_PRINT_SCALE, m_scale, m_min_scale, m_max_scale, PRINT_SIZE_PERCENT_PRECISION); break; } } if (Result == PRINT_SIZE_CHECK_CHANGED) { update_size_from_scale(); update_all_but(m_last_active_item_id); } return Result; }
CString XMLRestriction::CheckDatatype(XmlDataType p_type,CString p_value) { CString result; // Empty value, nothing to check if(p_value.IsEmpty()) { return result; } try { // Checking only base datatypes // String and CDATA are never checked! switch(p_type & XDT_MaskTypes) { case XDT_AnyURI: result = CheckAnyURI (p_value); break; case XDT_Base64Binary: result = CheckBase64 (p_value); break; case XDT_Boolean: result = CheckBoolean (p_value); break; case XDT_Date: result = CheckDate (p_value); break; case XDT_Integer: result = CheckInteger (p_value); break; case XDT_Decimal: result = CheckDouble (p_value,false); break; case XDT_Double: result = CheckDouble (p_value,true); break; case XDT_DateTime: result = CheckDateTime (p_value,false); break; case XDT_DateTimeStamp: result = CheckDateTime (p_value,true); break; case XDT_Float: result = CheckDouble (p_value,true); break; case XDT_Duration: result = CheckDuration (p_value); break; case XDT_DayTimeDuration: result = CheckDaySecond(p_value); break; case XDT_YearMonthDuration: result = CheckYearMonth(p_value); break; case XDT_GregDay: result = CheckGregDay (p_value); break; case XDT_GregMonth: result = CheckGregMonth(p_value); break; case XDT_GregYear: result = CheckGregYear (p_value); break; case XDT_GregMonthDay: result = CheckGregMD (p_value); break; case XDT_GregYearMonth: result = CheckGregYM (p_value); break; case XDT_HexBinary: result = CheckHexBin (p_value); break; case XDT_Long: result = CheckLong (p_value); break; case XDT_Int: result = CheckLong (p_value); break; case XDT_Short: result = CheckShort (p_value); break; case XDT_NonNegativeInteger:result = CheckNNegInt (p_value); break; case XDT_PositiveInteger: result = CheckPosInt (p_value); break; case XDT_UnsignedLong: result = CheckUnsLong (p_value); break; case XDT_UnsignedInt: result = CheckUnsLong (p_value); break; case XDT_UnsignedShort: result = CheckUnsShort (p_value); break; case XDT_UnsignedByte: result = CheckUnsByte (p_value); break; case XDT_NonPositiveInteger:result = CheckNonPosInt(p_value); break; case XDT_NegativeInteger: result = CheckNegInt (p_value); break; case XDT_Time: result = CheckTime (p_value); break; case XDT_Token: result = CheckToken (p_value); break; case XDT_NMTOKEN: result = CheckNMTOKEN (p_value); break; case XDT_Name: result = CheckName (p_value); break; case XDT_ENTITY: result = CheckName (p_value); break; case XDT_ID: result = CheckName (p_value); break; case XDT_IDREF: result = CheckName (p_value); break; case XDT_QName: result = CheckQName (p_value); break; case XDT_NMTOKENS: result = CheckNMTOKENS (p_value); break; case XDT_ENTITIES: result = CheckNames (p_value); break; case XDT_IDREFS: result = CheckNames (p_value); break; default: break; } } catch(StdException& er) { ReThrowSafeException(er); // Primary datatype conversion went wrong result = er.GetErrorMessage(); } return result; }