Пример #1
0
/**	Fetches the property requested and uses the appropriate op on the value.
	@return boolean value
**/
static int compare_property_alt(OBJECT *obj, char *propname, FINDOP op, void *value){
	complex *complex_target = NULL;
	char *char_target = NULL;
	int16 *int16_target = NULL;
	int32 *int32_target = NULL;
	int64 *int64_target = NULL;
	PROPERTY *prop = object_get_property(obj, propname);

	if(prop == NULL){
		/* property not found in object ~ normal operation */
		return 0;
	}

	switch(prop->ptype){
		case PT_void:
			return 0;	/* no comparsion to be made */
		case PT_double:
			break;
		case PT_complex:
			complex_target = object_get_complex(obj, prop);
			if(complex_target == NULL)
				return 0; /* error value */
			break;
		case PT_enumeration:
		case PT_set:
			break;		/* not 100% sure how to make these cooperate yet */
		case PT_int16:
			int16_target = (int16 *)object_get_int16(obj, prop);
			if(int16_target == NULL)
				return 0;
			return compare_int16(*int16_target, op, *(int64 *)value);
		case PT_int32:
			int32_target = (int32 *)object_get_int32(obj, prop);
			return compare_int32(*int32_target, op, *(int64 *)value);
			break;
		case PT_int64:
			int64_target = (int64 *)object_get_int64(obj, prop);
			return compare_int64(*int64_target, op, *(int64 *)value);
			break;
		case PT_char8:
		case PT_char32:
		case PT_char256:
		case PT_char1024:
			char_target = (char *)object_get_string(obj, prop);
			if(char_target == NULL)
				return 0;
			return compare_string(char_target, op, value);
			break;
		case PT_object:

			break;
		case PT_bool:
			break;
		case PT_timestamp:
		case PT_double_array:
		case PT_complex_array:
			break;
#ifdef USE_TRIPLETS
		case PT_triple:
		case PT_triplex:
			break;
#endif
		default:
			output_error("comparison operators not supported for property type %s", class_get_property_typename(prop->ptype));
			/* TROUBLESHOOT
				This error is caused when an object find procedure uses a comparison operator
			that isn't allowed on a that type of property.  Make sure the property type
			and the comparison operator are compatible and try again.  If your GLM file
			isn't the cause of the problem, try reducing the complexity of the GLM file 
			you are using to isolate which module is causing the error and file a report 
			with the GLM file attached.
			 */
			return 0;
	}
}
Пример #2
0
static mxArray *get_object_data(OBJECT *obj)
{
	mxArray *plhs[1];

	/* set the standard info */
#define ERROR "(error)"
#define NONE "(none)"
	char *fnames[1024] = {"id","class","parent","rank","clock","latitude","longitude","in_svc","out_svc","flags",NULL}; // };
	int nFields = 0;
	int nData = 0;
	char value[1024];
	PROPERTY *prop;
	mxArray *pId = mxCreateString(convert_from_object(value,sizeof(value),&obj,NULL)?value:ERROR);
	mxArray *pClass = mxCreateString(obj->oclass->name);
	mxArray *pParent = mxCreateString(obj->parent!=NULL&&convert_from_object(value,sizeof(value),&(obj->parent),NULL)?value:NONE);
	mxArray *pRank = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL);
	mxArray *pClock = mxCreateString(convert_from_timestamp(obj->clock,value,sizeof(value))?value:ERROR);
	mxArray *pLatitude = mxCreateString(convert_from_latitude(obj->latitude,value,sizeof(value))?value:NONE);
	mxArray *pLongitude = mxCreateString(convert_from_longitude(obj->longitude,value,sizeof(value))?value:NONE);
	mxArray *pInSvc = mxCreateString(convert_from_timestamp(obj->in_svc,value,sizeof(value))?value:ERROR);
	mxArray *pOutSvc = mxCreateString(convert_from_timestamp(obj->out_svc,value,sizeof(value))?value:ERROR);
	mxArray *pFlags = mxCreateString(convert_from_set(value,sizeof(value),(void*)&obj->flags,object_flag_property())?value:ERROR);

	*(OBJECTRANK*)mxGetPr(pRank) = obj->rank;

	/* count the number of header items */
	while (fnames[nFields]!=NULL) nFields++;

	/* count the number of object properties and assign the field names */
	for (prop=class_get_first_property(obj->oclass);  prop!=NULL; prop=class_get_next_property(prop))
		/** @todo don't damage the original fieldname when making it safe for Matlab */
		fnames[nFields+nData++] = make_fieldname(prop->name);

	/* construct the return value */
	plhs[0] = mxCreateStructMatrix(1,1,nFields+nData,fnames);

	/* construct the header fields */
	mxSetFieldByNumber(plhs[0],0,0,pId);
	mxSetFieldByNumber(plhs[0],0,1,pClass);
	mxSetFieldByNumber(plhs[0],0,2,pParent);
	mxSetFieldByNumber(plhs[0],0,3,pRank);
	mxSetFieldByNumber(plhs[0],0,4,pClock);
	mxSetFieldByNumber(plhs[0],0,5,pLatitude);
	mxSetFieldByNumber(plhs[0],0,6,pLongitude);
	mxSetFieldByNumber(plhs[0],0,7,pInSvc);
	mxSetFieldByNumber(plhs[0],0,8,pOutSvc);
	mxSetFieldByNumber(plhs[0],0,9,pFlags);

	/* construct the data fields */
	for (prop=class_get_first_property(obj->oclass);  prop!=NULL; nFields++,prop=class_get_next_property(prop))
	{
		mxArray *pValue;
		if (prop->ptype==PT_double)
		{
			pValue = mxCreateDoubleMatrix(1,1,mxREAL);
			*(double*)mxGetPr(pValue) = *object_get_double(obj,prop);
		}
		else if (prop->ptype==PT_int32)
		{
			pValue = mxCreateDoubleMatrix(1,1,mxREAL);
			*(double*)mxGetPr(pValue) = (double)*object_get_int32(obj,prop);
		}
		else if (prop->ptype==PT_complex)
		{
			complex *pData = object_get_complex(obj,prop);
			pValue = mxCreateDoubleMatrix(1,1,mxCOMPLEX);
			*(double*)mxGetPr(pValue) = pData->r;
			*(double*)mxGetPi(pValue) = pData->i;
		}
		else 
		{
			pValue = mxCreateString(object_get_value_by_name(obj,prop->name,value,sizeof(value))?value:ERROR);
		}
		mxSetFieldByNumber(plhs[0],0,nFields,pValue);
	}
	return plhs[0];
}