[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: Portable Code (am I dreaming? :))
From:       shaheed <srhaque () iee ! org>
Date:       2002-01-23 2:39:44
[Download RAW message or body]

Clarence,

> The problem is this: the mswrite import filter is sort of separate from the
> MSWriteLib library and this modularity enables me to write other filters
> for mswrite, instead of just KWord (e.g. mswrite->HTML).  MSWriteLib is
> written purely in standard C++ and I don't want to "contaminate" it with
> QT.  Does anyone have a way around this?

Apart from my ignorance of QDatastream, this was also the original design goal 
of the word stuff. The way i would do it now is as follows:

1. Write all your code in terms of Q_{U,}INT{8,16,32} to maximise portability 
on all Qt supported platforms. In your header file, do something like this:

#ifndef Q_UINT8

...as many platform-specific defs enclose in platform #ifdef guards

#endif

to maximise portability on non Qt supported platforms. Or vice versa.

2. Use functions (and/or macros) as Nicolas suggested for reading 8, 16, 32 
bit signed/unsigneds.

3. Don't worry about the direction of bit shifts for the reason Nicolas gave, 
and don't worry about the performance of bit shifts since the compiler will 
almost certainly put the original value in a register. The current msword 
code does some of this, and a typical routine looks like this:

unsigned MsWordGenerated::read(const U8 *in, __UNAL SHD *out, unsigned count)
{
    U32 shifterU32;
    U16 shifterU16;
    U8 shifterU8;
    U8 *ptr;
    unsigned bytes = 0;

    ptr = (U8 *)out;
    shifterU32 = shifterU16 = shifterU8 = 0;
    for (unsigned i = 0; i < count; i++)
    {
        bytes += read(in + bytes, &shifterU16);
        out->icoFore = shifterU16;
        shifterU16 >>= 5;
        out->icoBack = shifterU16;
        shifterU16 >>= 5;
        out->ipat = shifterU16;
        shifterU16 >>= 6;
        out++;
    }
    return bytes;
} // SHD

Note that the _UNAL will disappear as soon as I get round to eliminating a few 
sizeof()s used by the current code. In the example, I have an overloaded 
read() function for the different primitive types.

Finally, if you can, I heartily recommend a code generator...that way, if you 
get the implementation wrong, you can at least change it.

Thanks, Shaheed
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic