Esempio n. 1
0
//============================================================================
//		NDate::Compare : Compare the value.
//----------------------------------------------------------------------------
NComparison NDate::Compare(const NDate &theValue) const
{


    // Compare the value
    return(GetComparison(mTime, theValue.mTime));
}
Esempio n. 2
0
//============================================================================
//		NComparable::CompareData : Compare two blocks of data.
//----------------------------------------------------------------------------
template<typename T> NComparison NComparable<T>::CompareData(NIndex theSize1, const void *thePtr1,
															 NIndex theSize2, const void *thePtr2) const
{	NComparison		theResult;



	// Compare the data
	//
	// Since differently-sized bits of data can't be ordered, we compare
	// by size first and only examine content if we have equal sizes.
	if (theSize1 != theSize2)
		theResult = GetComparison(theSize1, theSize2);
	else
		{
		if (thePtr1 == thePtr2)
			theResult = kNCompareEqualTo;
		else
			theResult = GetComparison(memcmp(thePtr1, thePtr2, (size_t) theSize1));
		}
	
	return(theResult);
}
Esempio n. 3
0
const Comparison& ComparisonFactory::ReconstructFromProto(const serialization::Comparison &proto) {
  DCHECK(ProtoIsValid(proto))
      << "Attempted to create Comparison from an invalid proto description:\n"
      << proto.DebugString();

  switch (proto.comparison_id()) {
    case serialization::Comparison::EQUAL:
      return GetComparison(ComparisonID::kEqual);
    case serialization::Comparison::NOT_EQUAL:
      return GetComparison(ComparisonID::kNotEqual);
    case serialization::Comparison::LESS:
      return GetComparison(ComparisonID::kLess);
    case serialization::Comparison::LESS_OR_EQUAL:
      return GetComparison(ComparisonID::kLessOrEqual);
    case serialization::Comparison::GREATER:
      return GetComparison(ComparisonID::kGreater);
    case serialization::Comparison::GREATER_OR_EQUAL:
      return GetComparison(ComparisonID::kGreaterOrEqual);
    default:
      FATAL_ERROR("Unrecognized ComparisonID in ComparisonFactory::ReconstructFromProto");
  }
}
Esempio n. 4
0
//============================================================================
//		NNumber::Compare : Compare the value.
//----------------------------------------------------------------------------
NComparison NNumber::Compare(const NNumber &theValue) const
{	Float64				valueFloat64_1, valueFloat64_2;
	Float32				valueFloat32_1, valueFloat32_2;
	SInt64				valueInt64_1,  valueInt64_2;
	NComparison			theResult;



	// Compare equal types
	if (mPrecision == theValue.mPrecision || (IsInteger() && theValue.IsInteger()))
		{
		switch (mPrecision) {
			case kNPrecisionInt8:
			case kNPrecisionInt16:
			case kNPrecisionInt32:
			case kNPrecisionInt64:
				theResult = GetComparison(mValue.integer, theValue.mValue.integer);
				break;
			
			case kNPrecisionFloat32:
				valueFloat32_1 = (Float32)          mValue.real;
				valueFloat32_2 = (Float32) theValue.mValue.real;
				theResult      = GetComparison(valueFloat32_1, valueFloat32_2);
				break;

			case kNPrecisionFloat64:
				theResult = GetComparison(mValue.real, theValue.mValue.real);
				break;

			default:
				NN_LOG("Unknown precision: %d", mPrecision);
				theResult = kNCompareLessThan;
				break;
			}
		}


	// Compare dis-similar types
	else
		{
		switch (mPrecision) {
			case kNPrecisionInt8:
			case kNPrecisionInt16:
			case kNPrecisionInt32:
			case kNPrecisionInt64:
				valueInt64_1 =          GetSInt64();
				valueInt64_2 = theValue.GetSInt64();
				theResult    = GetComparison(valueInt64_1, valueInt64_2);
				break;

			case kNPrecisionFloat32:
				valueFloat32_1 =          GetFloat32();
				valueFloat32_2 = theValue.GetFloat32();
				theResult      = GetComparison(valueFloat32_1, valueFloat32_2);
				break;

			case kNPrecisionFloat64:
				valueFloat64_1 =          GetFloat64();
				valueFloat64_2 = theValue.GetFloat64();
				theResult      = GetComparison(valueFloat64_1, valueFloat64_2);
				break;

			default:
				NN_LOG("Unknown precision: %d", mPrecision);
				theResult = kNCompareLessThan;
				break;
			}
		}

	return(theResult);
}
Esempio n. 5
0
	// Compare the value
	NComparison Compare(const TEncodable &theValue) const
	{
		return(GetComparison(this, &theValue));
	}
Esempio n. 6
0
//============================================================================
//		NVariant::CompareValues : Compare two values.
//----------------------------------------------------------------------------
NComparison NVariant::CompareValues(const NVariant &value1, const NVariant &value2)
{   NComparison		theResult;



    // Check the values
    //
    // Testing by address gives us a fast test for equality, and a default
    // order for undefined cases (e.g., comparing different types).
    theResult = GetComparison(value1.mData, value2.mData);
    if (theResult == kNCompareEqualTo)
        return(theResult);



    // Check for NULL values
    //
    // NULL values can't be compared.
    if (!value1.IsValid() || !value2.IsValid())
        NN_LOG("Attempted to compare a NULL value");



    // Check for mismatched types
    //
    // Different types can't be compared, except for numeric values which we can
    // push through an NNumber to obtain a comparison.
    else if (value1.GetType() != value2.GetType())
    {
        if (value1.IsNumeric() && value2.IsNumeric())
            theResult = NNumber(value1).Compare(NNumber(value2));
        else
            NN_LOG("Attempted to compare different types (%s) (%s)", value1.GetType().name(), value2.GetType().name());
    }



    // Compare the values
    //
    // NVariant provides default comparisons for standard comparable objects.
    //
    // This list can be extended in the future to support new types. Unfortunately we can't
    // automatically determine if a type is a sub-class of NComparable, since our type may
    // also be a built-in type like 'long' rather than an object.
    else
    {
        if (value1.IsNumeric())
            theResult = NNumber(value1).Compare(NNumber(value2));

        else if (value1.IsType(typeid(NBitVector)))
            theResult = CompareValuesT<NBitVector>(value1, value2);

        else if (value1.IsType(typeid(NColor)))
            theResult = CompareValuesT<NColor>(value1, value2);

        else if (value1.IsType(typeid(NData)))
            theResult = CompareValuesT<NData>(value1, value2);

        else if (value1.IsType(typeid(NDate)))
            theResult = CompareValuesT<NDate>(value1, value2);

        else if (value1.IsType(typeid(NDictionary)))
            theResult = CompareValuesT<NDictionary>(value1, value2);

        else if (value1.IsType(typeid(NFile)))
            theResult = CompareValuesT<NFile>(value1, value2);

        else if (value1.IsType(typeid(NPoint)))
            theResult = CompareValuesT<NPoint>(value1, value2);

        else if (value1.IsType(typeid(NRange)))
            theResult = CompareValuesT<NRange>(value1, value2);

        else if (value1.IsType(typeid(NRectangle)))
            theResult = CompareValuesT<NRectangle>(value1, value2);

        else if (value1.IsType(typeid(NSize)))
            theResult = CompareValuesT<NSize>(value1, value2);

        else if (value1.IsType(typeid(NString)))
            theResult = CompareValuesT<NString>(value1, value2);

        else if (value1.IsType(typeid(NVector)))
            theResult = CompareValuesT<NVector>(value1, value2);

        else
            NN_LOG("NVariant::CompareValues passed an unknown type (%s)", value1.GetType().name());
    }

    return(theResult);
}