Чиста поржать
int numeric_compare(int a, int b)
{
return a - b;
}
int cv_numeric_compare(CValue& left, CValue& right)
{
return left.GetNumeric().Compare(right.GetNumeric());
}
int string_compare(LPCSTR left, LPCSTR right, TVTIndexDescrRecord const& IdxRec)
{
if( IdxRec.NoCaseStringCompare )
{
if( IdxRec.TrimStrings )
return FastCompareNoCase.CompareTrimSpc(left, right);
else
return FastCompareNoCase.Compare(left, right);
}
else if ( IdxRec.TrimStrings )
return FastCompare.CompareTrimSpc(left, right);
else
return FastCompare.Compare(left, right);
}
int cv_string_compare(CValue& left, CValue& right, TVTIndexDescrRecord const& IdxRec)
{
return string_compare((LPCSTR)CString(left.Format()), (LPCSTR)CString(right.Format()), IdxRec);
}
int date_compare(CDate const& d1, CDate const& d2)
{
int comp_res = numeric_compare(d1.GetYear(), d2.GetYear());
if( comp_res ) return comp_res;
comp_res = numeric_compare(d1.GetMonth(), d2.GetMonth());
if( comp_res ) return comp_res;
comp_res = numeric_compare(d1.GetMonthDay(), d2.GetMonthDay());
return comp_res;
}
int time_compare(CEventTime const& t1, CEventTime const& t2)
{
if( t1 < t2 ) return -1;
else if( t1 > t2 ) return 1;
return 0;
}
inline DWORD gettypeid(CValue const &cv)
{
return cv.m_mdid ? cv.m_mdid : cv.ValTypeID;
}
int inner_compare(CValue &left, CValue &right)
{
int diff;
if( !(diff = gettypeid(left) - gettypeid(right)) )
{
if( !(diff = left.m_ObjID.GetlObjID() - right.m_ObjID.GetlObjID()) )
diff = FastCompare.Compare(left.m_ObjID.DBSign.Sign, right.m_ObjID.DBSign.Sign);
}
return diff;
}
int CValue_compare(CValue &left, CValue &right, TVTIndexDescrRecord const& IdxRec)
{
int nTypeCodeLeft = left.GetTypeCode();
int nTypeCodeRight = right.GetTypeCode();
if( nTypeCodeLeft == nTypeCodeRight )
{
switch( nTypeCodeLeft )
{
case UNDEFINE_TYPE_1C:
return 0;
break;
case NUMBER_TYPE_1C:
return cv_numeric_compare(left, right);
break;
case STRING_TYPE_1C:
return string_compare(left.m_String.operator LPCSTR(), right.m_String.operator LPCSTR(), IdxRec);
break;
case DATE_TYPE_1C:
{
CDate &d1 = left.GetDate(), &d2 = right.GetDate();
return date_compare(d1, d2);
}
break;
case REFERENCE_TYPE_1C:
{
if( IdxRec.CompareType == CmpByInnerRepr )
return inner_compare(left, right);
// учтено время жизни указателей
int comp_res = cv_string_compare(left, right, IdxRec);
if( comp_res == 0 )
comp_res = inner_compare(left, right);
return comp_res;
}
break;
case DOCUMENT_TYPE_1C:
if( IdxRec.CompareType == CmpByInnerRepr )
{
return inner_compare(left, right);
}
else
{
CDate d1(0,0,0), d2(0,0,0);
CEventTime t1, t2;
GetDateTimeFromValue(left, d1, t1);
GetDateTimeFromValue(right, d2, t2);
int comp_res = date_compare(d1, d2);
if( comp_res == 0 ) comp_res = time_compare(t1, t2);
return comp_res;
}
break;
case AGREGATE_TYPE_1C:
{
if( IdxRec.CompareType == CmpByInnerRepr )
return left.m_Context - right.m_Context;
int comp_res = cv_string_compare(left, right, IdxRec);
if( comp_res == 0 )
comp_res = left.m_Context - right.m_Context;
return comp_res;
}
break;
default:
if( IdxRec.CompareType == CmpByInnerRepr )
return inner_compare(left, right);
else
return cv_string_compare(left, right, IdxRec);
}
}
else
{
return numeric_compare(nTypeCodeLeft, nTypeCodeRight);
}
}
int CVTIndexRecord::compare(CVTIndexRecord& RightRecord)
{
int sz = IndexFields->size();
for( int i = 0; i < sz; i++ )
{
int comp_res;
TVTIndexDescrRecord &IdxRec = IndexFields->operator[](i);
CValue &left = Row->GetValue(IdxRec.ColumnNumber);
CValue &right = RightRecord.Row->GetValue(IdxRec.ColumnNumber);
/*
try{
comp_res = CValue_compare(left, right, IdxRec);
} catch(...)
{
RuntimeError("Ошибка памяти при сравнении строк в индексе. rows: %p vs %p; values: %p vs %p",
Row, RightRecord.Row, &left, &right);
}
if( comp_res != 0 ) return comp_res * IdxRec.Direction;
*/
comp_res = CValue_compare(left, right, IdxRec);
if (comp_res)
{
if (IdxRec.Direction < 0)
comp_res =-comp_res;
return comp_res;
}
}
return 0;
}
Этот фрагмент отвечает на все вопросы, затронутые тут.
И я не думаю, что хоть один вменяемый программист станет преобразовывать числа в строки для сравнения.