DaoEnum* DaoProcess_NewEnum( DaoProcess *self, DaoType *type, int value ) { DaoEnum *res = DaoEnum_New( type, value ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
/* // 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 ); }