Ejemplo n.º 1
0
//============================================================================
//		NPreferences::GetValue : Get a value.
//----------------------------------------------------------------------------
NVariant NPreferences::GetValue(const NString &theKey) const
{	NVariant		theValue;



	// Validate our parameters
	NN_ASSERT(!theKey.IsEmpty());
	


	// Get the value
	theValue = NTargetPreferences::GetValue(theKey);
	if (!theValue.IsValid())
		theValue = NPropertyStore::GetValue(theKey);
	
	return(theValue);
}
Ejemplo n.º 2
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);
}