Changeset 312 for trunk/thune/make.c

Show
Ignore:
Timestamp:
12/03/06 04:52:27 (2 years ago)
Author:
krobillard
Message:

Thune - Renamed array! to vector!. Added vector! make.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/make.c

    r310 r312  
    641641    str->ptr.c[ str->used ] = '\0'; 
    642642    return strN; 
     643} 
     644 
     645 
     646/*--------------------------------------------------------------------------*/ 
     647 
     648 
     649void _convertToDecimalVector( UArray* arr ) 
     650{ 
     651    int32_t* it  = arr->ptr.i; 
     652    int32_t* end = it + arr->used; 
     653 
     654    while( it != end ) 
     655    { 
     656        *((float*) it) = (float) *it; 
     657        ++it; 
     658    } 
     659} 
     660 
     661 
     662// Returns zero if make failed. 
     663UIndex ur_makeVector( const UCell* from, UCell* res )  
     664{ 
     665    UIndex binN = 0; 
     666    int vtype = UT_INT; 
     667 
     668    if( ur_is(from, UT_BLOCK) ) 
     669    { 
     670        UBinary* bin; 
     671        UBlock* blk; 
     672        UCell* it; 
     673        UCell* end; 
     674 
     675        blk = ur_block( from ); 
     676        UR_ITER_BLOCK( it, end, blk, from ) 
     677 
     678        binN = ur_makeBinary( (end - it) * sizeof(int32_t) ); 
     679        bin = ur_binPtr( binN ); 
     680 
     681        while( it != end ) 
     682        { 
     683            if( ur_is(it, UT_INT) ) 
     684            { 
     685                bin->ptr.i[ bin->used ] = ur_int(it); 
     686                ++bin->used; 
     687            } 
     688            else if( ur_is(it, UT_DECIMAL) ) 
     689            { 
     690                goto decimal; 
     691            } 
     692            ++it; 
     693        } 
     694        goto init; 
     695 
     696decimal: 
     697 
     698        vtype = UT_DECIMAL; 
     699        _convertToDecimalVector( bin ); 
     700 
     701        while( it != end ) 
     702        { 
     703            if( ur_is(it, UT_DECIMAL) ) 
     704            { 
     705                bin->ptr.f[ bin->used ] = (float) ur_decimal(it); 
     706                ++bin->used; 
     707            } 
     708            else if( ur_is(it, UT_INT) ) 
     709            { 
     710                bin->ptr.f[ bin->used ] = (float) ur_int(it); 
     711                ++bin->used; 
     712            } 
     713            ++it; 
     714        } 
     715    } 
     716    else if( ur_is(from, UT_INT) ) 
     717    { 
     718        binN = ur_makeBinary( ur_int(from) * sizeof(int32_t) ); 
     719    } 
     720 
     721    if( binN ) 
     722    { 
     723init: 
     724        ur_initType(res, UT_VECTOR); 
     725        ur_arrayDT(res) = vtype; 
     726        ur_setSeries(res, binN, 0); 
     727        return binN; 
     728    } 
     729 
     730    return 0; 
    643731} 
    644732 
     
    14391527            break; 
    14401528 
     1529        case UT_VECTOR: 
     1530        { 
     1531            // Make array before setting res in case GC is called. 
     1532            UIndex binN = ur_makeVector( tos, res ); 
     1533            if( ! binN ) 
     1534                goto error; 
     1535        } 
     1536            break; 
     1537 
    14411538        case UT_BITSET: 
    14421539        {