//============================================================================ // NCommandLine::GetFlagFloat64 : Get a float64_t flag value. //---------------------------------------------------------------------------- float64_t NCommandLine::GetFlagFloat64(const NString &theArgument) const { float64_t theResult; NString theFlag; // Get the value theFlag = GetFlagString(theArgument); theResult = NNumber(theFlag).GetFloat64(); return(theResult); }
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); }
//============================================================================ // 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); }