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


C++ DynamicArray::get_length方法代码示例

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


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

示例1: CallMethod

/** Call a method of a VCL object or a constructor of a VCL type.
 *  The methods are considered in order and the first that matches the arguments
 *  will be used.
 *  \param Type: The type to construct if the method is a constructor; NULL otherwise.
 *  \param Instance: The VCL object of the method; NULL if it is a constructor
 *  \param Methods: The methods to consider
 *  \param Args: Arguments that will be passed to the method.
 *  \return The result of the called method or the newly constructed object if it
 *  is a constructor.
 */
TValue CallMethod(TRttiType *Type, TObject *Instance, DynamicArray<TRttiMethod*> &Methods, PyObject *Args)
{
	unsigned MethodCount = Methods.get_length();
	TRttiType *Parent = Methods[0]->Parent;
	for(unsigned I = 0; I < MethodCount; I++)
	{
		TRttiMethod *Method = Methods[I];
		if(Instance == NULL) //If looking for constructor
			if(Method->Parent != Parent)
			  break; //Only look for constructors defined in the last class with constructors

		DynamicArray<TRttiParameter*> ParameterTypes = Method->GetParameters();
		std::vector<TValue> Parameters;
		int ParamCount = PyTuple_Size(Args);
		if(ParamCount != ParameterTypes.Length)
			if(MethodCount == 1)
				throw EPyVclError(Method->Name + "() takes exactly " + ParameterTypes.get_length() + " arguments (" + ParamCount + " given)");
			else
				continue;
		try
		{
			TupleToValues(Args, Parameters, ParameterTypes);
		}
		catch(Exception &E)
		{
			if(MethodCount == 1)
				throw;
			continue;
		}

		if(Method->IsConstructor)
		{
			if(Type == NULL)
				throw EPyVclError("Cannot call constructor");
			return Method->Invoke(Type->AsInstance->MetaclassType, Parameters.size() == 0 ? NULL : &Parameters[0], Parameters.size()-1);
		}
		else if(Method->IsClassMethod || Method->IsStatic)
			return Method->Invoke(Instance->ClassType(), Parameters.size() == 0 ? NULL : &Parameters[0], Parameters.size()-1);
		else
			return Method->Invoke(Instance, Parameters.size() == 0 ? NULL : &Parameters[0], Parameters.size()-1);
	}

	throw EPyVclError("No suitable overload found for the function " + Methods[0]->Name);
}
开发者ID:q2apro,项目名称:graph-padowan,代码行数:54,代码来源:PyVclMethod.cpp


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