예제 #1
0
파일: daoValue.c 프로젝트: wherby/dao
DaoFloat* DaoProcess_NewFloat( DaoProcess *self, float v )
{
	DaoFloat *res = DaoFloat_New( v );
	DaoProcess_CacheValue( self, (DaoValue*) res );
	return res;
}
예제 #2
0
파일: daoValue.c 프로젝트: wherby/dao
/*
// Assumming the value "self" is compatible to the type "tp", if it is not null.
*/
DaoValue* DaoValue_SimpleCopyWithTypeX( DaoValue *self, DaoType *tp, DaoDataCache *cache )
{
	DaoEnum *e;
	daoint i, n;

	if( self == NULL ) return dao_none_value;
	if( (tp == NULL || tp->tid == self->type) && self->type < DAO_ENUM ){
		if( cache ){
			DaoValue *value = DaoDataCache_MakeValue( cache, self->type );
			switch( self->type ){
			case DAO_NONE : return self;
			case DAO_INTEGER : value->xInteger.value = self->xInteger.value; break;
			case DAO_FLOAT   : value->xFloat.value   = self->xFloat.value;   break;
			case DAO_DOUBLE  : value->xDouble.value  = self->xDouble.value;  break;
			case DAO_COMPLEX : value->xComplex.value = self->xComplex.value; break;
#ifdef DAO_WITH_LONGINT
			case DAO_LONG    : DLong_Move( value->xLong.value, self->xLong.value ); break;
#endif
			case DAO_STRING  : DString_Assign( value->xString.data, self->xString.data ); break;
			}
			return value;
		}else{
			switch( self->type ){
			case DAO_NONE : return self;
			case DAO_INTEGER : return (DaoValue*) DaoInteger_New( self->xInteger.value );
			case DAO_FLOAT   : return (DaoValue*) DaoFloat_New( self->xFloat.value );
			case DAO_DOUBLE  : return (DaoValue*) DaoDouble_New( self->xDouble.value );
			case DAO_COMPLEX : return (DaoValue*) DaoComplex_New( self->xComplex.value );
			case DAO_LONG    : return (DaoValue*) DaoLong_Copy( & self->xLong );
			case DAO_STRING  : return (DaoValue*) DaoString_Copy( & self->xString );
			}
		}
		return self; /* unreachable; */
	}else if( self->type == DAO_ENUM ){
		return (DaoValue*) DaoEnum_Copy( & self->xEnum, tp );
	}else if( tp && tp->tid >= DAO_INTEGER && tp->tid <= DAO_DOUBLE ){
		DaoValue *value = cache ? DaoDataCache_MakeValue( cache, tp->tid ) : NULL;
		switch( value == NULL ? tp->tid : 0 ){
		case DAO_INTEGER : value = (DaoValue*) DaoInteger_New(0); break;
		case DAO_FLOAT   : value = (DaoValue*) DaoFloat_New(0);   break;
		case DAO_DOUBLE  : value = (DaoValue*) DaoDouble_New(0);  break;
		}
		switch( tp->tid ){
		case DAO_INTEGER : value->xInteger.value = DaoValue_GetInteger( self ); break;
		case DAO_FLOAT   : value->xFloat.value   = DaoValue_GetFloat( self );   break;
		case DAO_DOUBLE  : value->xDouble.value  = DaoValue_GetDouble( self );  break;
		}
		return value;
	}
#ifdef DAO_WITH_NUMARRAY
	if( self->type == DAO_ARRAY && self->xArray.original ){
		DaoArray_Sliced( (DaoArray*)self );
		return self;
	}else
#endif
	if( self->type == DAO_CSTRUCT || self->type == DAO_CDATA ){
		FuncPtrSliced sliced = self->xCstruct.ctype->kernel->Sliced;
		if( sliced ) (*sliced)( self );
		return self;
	}
	if( self->xBase.trait & DAO_VALUE_NOCOPY ) return self;
	if( (self->xBase.trait & DAO_VALUE_CONST) == 0 ) return self;
	switch( self->type ){
	case DAO_LIST  : return (DaoValue*) DaoList_Copy( (DaoList*) self, tp );
	case DAO_MAP   : return (DaoValue*) DaoMap_Copy( (DaoMap*) self, tp );
	case DAO_TUPLE : return (DaoValue*) DaoTuple_Copy( (DaoTuple*) self, tp );
#ifdef DAO_WITH_NUMARRAY
	case DAO_ARRAY : return (DaoValue*) DaoArray_CopyX( (DaoArray*) self, tp );
#endif
	default : break;
	}
	return self;
}
예제 #3
0
파일: daoValue.c 프로젝트: daokoder/dao
/*
// Assumming the value "self" is compatible to the type "tp", if it is not null.
*/
DaoValue* DaoValue_SimpleCopyWithTypeX( DaoValue *self, DaoType *tp, DaoType *cst )
{
	if( self == NULL ) return dao_none_value;
	if( self->type < DAO_ENUM && (tp == NULL || tp->tid == self->type) ){
		/*
		// The following optimization is safe theoretically.
		// But it is not practically safe for DaoProcess_PutChars() etc.,
		// which often uses shallow wraps of "const char*" as the source value,
		// and expects it to be copied at the destination as a primitive value.
		*/
		/* if( cst && cst->invar ) return self; */
		switch( self->type ){
		case DAO_NONE : return self;
		case DAO_BOOLEAN : return (DaoValue*) DaoBoolean_New( self->xBoolean.value );
		case DAO_INTEGER : return (DaoValue*) DaoInteger_New( self->xInteger.value );
		case DAO_FLOAT   : return (DaoValue*) DaoFloat_New( self->xFloat.value );
		case DAO_COMPLEX : return (DaoValue*) DaoComplex_New( self->xComplex.value );
		case DAO_STRING  : return (DaoValue*) DaoString_Copy( & self->xString );
		}
		return self; /* unreachable; */
	}else if( tp && tp->tid >= DAO_BOOLEAN && tp->tid <= DAO_FLOAT ){
		DaoValue *va = NULL;
		switch( tp->tid ){
		case DAO_BOOLEAN : va = (DaoValue*) DaoBoolean_New( DaoValue_GetInteger(self) ); break;
		case DAO_INTEGER : va = (DaoValue*) DaoInteger_New( DaoValue_GetInteger(self) ); break;
		case DAO_FLOAT   : va = (DaoValue*) DaoFloat_New( DaoValue_GetFloat(self) );   break;
		}
		return va;
	}else if( self->type == DAO_ENUM ){
		switch( tp ? tp->tid : 0 ){
		case DAO_ENUM :
			if( tp->subtid == DAO_ENUM_ANY ) tp = NULL;
			return (DaoValue*) DaoEnum_Copy( & self->xEnum, tp );
		case DAO_BOOLEAN : return (DaoValue*) DaoBoolean_New( self->xEnum.value );
		case DAO_INTEGER : return (DaoValue*) DaoInteger_New( self->xEnum.value );
		case DAO_FLOAT   : return (DaoValue*) DaoFloat_New( self->xEnum.value );
		}
		return (DaoValue*) DaoEnum_Copy( & self->xEnum, NULL );
	}else if( tp && tp->tid == DAO_ENUM ){
		switch( self->type ){
		case DAO_BOOLEAN :
		case DAO_INTEGER : return (DaoValue*) DaoEnum_New( tp, self->xInteger.value );
		case DAO_FLOAT   : return (DaoValue*) DaoEnum_New( tp, self->xFloat.value );
		}
	}else if( self->type == DAO_CINVALUE ){
		return (DaoValue*) DaoCinValue_Copy( (DaoCinValue*) self );
	}
	if( tp != NULL ){
		assert( tp->tid == 0 || tp->tid > DAO_ENUM );
		assert( self->type == 0 || self->type > DAO_ENUM );
	}

#ifdef DAO_WITH_NUMARRAY
	if( self->type == DAO_ARRAY && self->xArray.original ){
		DaoArray_Sliced( (DaoArray*)self );
		return self;
	}else
#endif
	if( self->type == DAO_CSTRUCT || self->type == DAO_CDATA ){
		if( self->xCstruct.ctype->core->Slice ) self->xCstruct.ctype->core->Slice( self );
		return self;
	}
	if( tp == NULL ){
		switch( self->type ){
		case DAO_LIST  : if( self->xList.ctype->empty ) tp = self->xList.ctype; break;
		case DAO_MAP   : if( self->xMap.ctype->empty  ) tp = self->xMap.ctype; break;
		default : break;
		}
	}
	if( self->xBase.trait & DAO_VALUE_NOCOPY ) return self;
	if( (self->xBase.trait & DAO_VALUE_CONST) == 0 ) return self;
	if( cst != NULL && cst->invar != 0 ) return self;
	if( tp ) tp = DaoType_GetBaseType( tp );
	return DaoValue_CopyContainer( self, tp );
}