Changeset 53

Show
Ignore:
Timestamp:
06/26/08 18:20:14 (2 months ago)
Author:
baxissimo
Message:

Implemented the real->double conversion for load/save.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doost/util/serializer/archive/BinaryArchive.d

    r52 r53  
    284284     **************************************************************************/ 
    285285    bool loadNumber(VALUE)(ref VALUE value) { 
    286         // TODO: real.sizeof can vary platform-to-platform! (also creal,ireal) 
    287         value = decode!(VALUE)(storage.get(VALUE.sizeof)); 
     286        static if( is(VALUE==real) || is(VALUE==creal) || is(VALUE==ireal)) { 
     287            // TODO: implement platform independent multi-precision float  
     288            // to handle any platform-specific 'real' type. 
     289 
     290            // But for now (v1.1 binary format), reals are treated as doubles 
     291            static if(is(VALUE==real)) { alias double DVALUE; } 
     292            else static if(is(VALUE==creal)) { alias cdouble DVALUE; } 
     293            else static if(is(VALUE==ireal)) { alias idouble DVALUE; } 
     294            DVALUE dvalue; 
     295            if (!loadNumber!(DVALUE)(dvalue)) 
     296                return false; 
     297            value = dvalue; 
     298            return true; 
     299        } 
     300        else { 
     301            value = decode!(VALUE)(storage.get(VALUE.sizeof)); 
     302        } 
    288303        return true; 
    289304    } 
     
    292307     **************************************************************************/ 
    293308    bool dumpNumber(VALUE)(ref VALUE value) { 
    294         // TODO: real.sizeof can vary platform-to-platform! (also creal,ireal) 
    295         storage.put(encode(value)); 
     309        static if( is(VALUE==real) || is(VALUE==creal) || is(VALUE==ireal)) { 
     310            // TODO: implement platform independent multi-precision float  
     311            // to handle any platform-specific 'real' type. 
     312 
     313            // But for now (v1.1 binary format), reals are treated as doubles 
     314            static if(is(VALUE==real)) { alias double DVALUE; } 
     315            else static if(is(VALUE==creal)) { alias cdouble DVALUE; } 
     316            else static if(is(VALUE==ireal)) { alias idouble DVALUE; } 
     317            DVALUE dvalue = value; 
     318            if (!dumpNumber!(DVALUE)(dvalue)) 
     319                return false; 
     320        } 
     321        else { 
     322            storage.put(encode(value)); 
     323        } 
    296324        return true; 
    297325    }