当前位置: 首页>>代码示例>>C++>>正文


C++ CDatum::IsNumber方法代码示例

本文整理汇总了C++中CDatum::IsNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ CDatum::IsNumber方法的具体用法?C++ CDatum::IsNumber怎么用?C++ CDatum::IsNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CDatum的用法示例。


在下文中一共展示了CDatum::IsNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: IsEqual

bool CDatum::IsEqual (CDatum dValue) const

//	IsEqual
//
//	Returns TRUE if the values are equal

	{
	switch (GetBasicType())
		{
		case typeNil:
			return dValue.IsNil();

		case typeTrue:
			return !dValue.IsNil();

		case typeInteger32:
		case typeInteger64:
		case typeIntegerIP:
		case typeDouble:
			return (dValue.IsNumber() && CNumberValue(*this).Compare(dValue) == 0);

		case typeString:
			return (dValue.GetBasicType() == typeString && strEquals(*this, dValue));

		case typeDateTime:
			return (dValue.GetBasicType() == typeDateTime && ((const CDateTime &)*this == (const CDateTime &)dValue));

		//	LATER
		case typeArray:
		case typeBinary:
		case typeStruct:
		case typeSymbol:
			return false;

		default:
			ASSERT(false);
			return false;
		}
	}
开发者ID:gmoromisato,项目名称:Hexarc,代码行数:39,代码来源:CDatum.cpp

示例2: DefaultCompare


//.........这里部分代码省略.........
						if (iItemCompare != 0)
							return iItemCompare;
						}

					return 0;
					}

			case CDatum::typeStruct:
				if (dKey1.GetCount() > dKey2.GetCount())
					return 1;
				else if (dKey1.GetCount() < dKey2.GetCount())
					return -1;
				else
					{
					for (i = 0; i < dKey1.GetCount(); i++)
						{
						CString sItemKey1 = dKey1.GetKey(i);
						CString sItemKey2 = dKey2.GetKey(i);
						int iKeyCompare = KeyCompare(sItemKey1, sItemKey2);
						if (iKeyCompare != 0)
							return iKeyCompare;

						CDatum dItem1 = dKey1.GetElement(i);
						CDatum dItem2 = dKey2.GetElement(i);
						int iItemCompare = CDatum::DefaultCompare(pCtx, dItem1, dItem2);
						if (iItemCompare != 0)
							return iItemCompare;
						}

					return 0;
					}

			//	LATER: Not yet supported

			default:
				return 0;
			}
		}

	//	If one of the types is nil, then compare

	else if (iType1 == CDatum::typeNil || iType2 == CDatum::typeNil)
		{
		CDatum dNonNil;
		int iResult;
		if (iType2 == CDatum::typeNil)
			{
			dNonNil = dKey1;
			Swap(iType1, iType2);
			iResult = 1;
			}
		else
			{
			dNonNil = dKey2;
			iResult = -1;
			}

		switch (iType2)
			{
			case CDatum::typeString:
				if (((const CString &)dNonNil).IsEmpty())
					return 0;
				else
					return iResult;

			case CDatum::typeArray:
			case CDatum::typeStruct:
				if (dNonNil.GetCount() == 0)
					return 0;
				else
					return iResult;

			default:
				//	nil is always less
				return iResult;
			}
		}

	//	If one of the types is a number, then compare as numbers

	else if (dKey1.IsNumber() || dKey2.IsNumber())
		{
		CNumberValue Number1(dKey1);
		CNumberValue Number2(dKey2);

		if (Number1.IsValidNumber() && Number2.IsValidNumber())
			return Number1.Compare(Number2);
		else if (Number1.IsValidNumber())
			return 1;
		else if (Number2.IsValidNumber())
			return -1;
		else
			return 0;
		}

	//	Otherwise, cannot compare

	else
		return 0;
	}
开发者ID:gmoromisato,项目名称:Hexarc,代码行数:101,代码来源:CDatum.cpp

示例3: GetNumberType

CDatum::Types CDatum::GetNumberType (int *retiValue, CDatum *retdConverted) const

//	GetNumberType
//
//	Returns the most appropriate number type for the datum and optimistically
//	returns the value if the type is integer.
//
//	The number type is the best number type that the datum can be cast
//	to without loss of data, following this order (from most preferable to
//	least):
//
//	typeInteger32
//	typeDouble
//	typeIntegerIP
//
//	If the original datum is a string then we try to parse it and return the
//	best number type. retdConverted will be a datum representing the parsed
//	number.
//
//	If the value cannot be converted to a number we return typeUnknown.

	{
	//	Pre-init

	if (retdConverted)
		*retdConverted = *this;

	switch (m_dwData & AEON_TYPE_MASK)
		{
		case AEON_TYPE_STRING:
			{
			if (m_dwData == 0)
				{
				if (retiValue)
					*retiValue = 0;
				return typeInteger32;
				}
			else
				{
				CDatum dNumberValue;
				if (!CDatum::CreateFromStringValue(*this, &dNumberValue)
						|| !dNumberValue.IsNumber())
					return typeUnknown;

				if (retdConverted)
					*retdConverted = dNumberValue;

				return dNumberValue.GetNumberType(retiValue);
				}
			}

		case AEON_TYPE_NUMBER:
			switch (m_dwData & AEON_NUMBER_TYPE_MASK)
				{
				case AEON_NUMBER_CONSTANT:
					{
					switch (m_dwData)
						{
						case constTrue:
							if (retiValue)
								*retiValue = 1;
							return typeInteger32;

						default:
							ASSERT(false);
							return typeUnknown;
						}
					}

				case AEON_NUMBER_28BIT:
					if (retiValue)
						*retiValue = ((int)(m_dwData & AEON_NUMBER_MASK) >> 4);
					return typeInteger32;

				case AEON_NUMBER_32BIT:
					if (retiValue)
						*retiValue = (int)g_IntAlloc.Get(GetNumberIndex());
					return typeInteger32;

				case AEON_NUMBER_DOUBLE:
					return typeDouble;

				default:
					ASSERT(false);
					return typeUnknown;
				}

		case AEON_TYPE_COMPLEX:
			return raw_GetComplex()->GetNumberType(retiValue);

		default:
			ASSERT(false);
			return typeUnknown;
		}
	}
开发者ID:gmoromisato,项目名称:Hexarc,代码行数:95,代码来源:CDatum.cpp


注:本文中的CDatum::IsNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。