예제 #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);
}
예제 #2
0
파일: NNumber.cpp 프로젝트: x414e54/nano
bool NNumber::EncodableCanEncode(const NVariant &theValue)
{	const NNumber	*theObject;

	if (theValue.IsNumeric())
		return(true);

	theObject = theValue.GetValue<NNumber>();
	return(theObject != NULL);
}
예제 #3
0
파일: NNumber.cpp 프로젝트: x414e54/nano
//============================================================================
//		NNumber::NNumber : Constructor.
//----------------------------------------------------------------------------
NNumber::NNumber(const NVariant &theValue)
{


	// Initialise ourselves
	SetUInt8(0);

	if (theValue.IsNumeric())
		SetValue(theValue);
}
예제 #4
0
파일: NNumber.cpp 프로젝트: x414e54/nano
void NNumber::EncodableEncodeObject(NEncoder &theEncoder, const NVariant &theValue)
{	const NNumber		*theObject;
	const NVariant		*srcValue;
	NNumber				tmpNumber;
	NVariant			tmpValue;

	if (theValue.IsNumeric())
		{
		tmpNumber = NNumber(theValue);
		tmpValue  = NVariant(tmpNumber);
		srcValue  = &tmpValue;
		}
	else
		srcValue = &theValue;
		
	theObject = srcValue->GetValue<NNumber>();
	theObject->EncodeSelf(theEncoder);
}
예제 #5
0
파일: NNumber.cpp 프로젝트: x414e54/nano
//============================================================================
//		NNumber::SetValue : Set the value.
//----------------------------------------------------------------------------
bool NNumber::SetValue(const NVariant &theValue)
{	UInt8					valueUInt8;
	UInt16					valueUInt16;
	UInt32					valueUInt32;
	UInt64					valueUInt64;
	SInt8					valueSInt8;
	SInt16					valueSInt16;
	SInt32					valueSInt32;
	SInt64					valueSInt64;
	Float32					valueFloat32;
	Float64					valueFloat64;
	int						valueInt;
	long					valueLong;
	NString					valueString;



	// Set the value
	//
	// NVariant treats some unsized types as numeric, to support literal constants.
	if (theValue.GetValue(*this))
		; // Assigned to this

	else if (theValue.GetValue(valueUInt8))
		SetUInt8(valueUInt8);

	else if (theValue.GetValue(valueUInt16))
		SetUInt16(valueUInt16);
	
	else if (theValue.GetValue(valueUInt32))
		SetUInt32(valueUInt32);
	
	else if (theValue.GetValue(valueUInt64))
		SetUInt64(valueUInt64);
	
	else if (theValue.GetValue(valueSInt8))
		SetSInt8(valueSInt8);
	
	else if (theValue.GetValue(valueSInt16))
		SetSInt16(valueSInt16);
	
	else if (theValue.GetValue(valueSInt32))
		SetSInt32(valueSInt32);
	
	else if (theValue.GetValue(valueSInt64))
		SetSInt64(valueSInt64);
	
	else if (theValue.GetValue(valueFloat32))
		SetFloat32(valueFloat32);
	
	else if (theValue.GetValue(valueFloat64))
		SetFloat64(valueFloat64);
	
	else if (theValue.GetValue(valueInt))
		SetSInt64(valueInt);
	
	else if (theValue.GetValue(valueLong))
		SetSInt64(valueLong);
	
	else if (theValue.GetValue(valueString))
		return(SetValue(valueString));

	else
		return(false);

	return(true);
}
예제 #6
0
파일: NVariant.cpp 프로젝트: refnum/nano
//============================================================================
//		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);
}