Replacing RESTORE() macro with template functions.

Simon Hausmann hausmann at kde.org
Mon Dec 2 12:59:24 GMT 2002


On Mon, Dec 02, 2002 at 01:36:54PM +0100, Marc Mutz wrote:
Content-Description: signed data
> Hi!
> 
> RESTORE() has the drawback that it can only be used with a single type 
> of mainwindow. ATM, I'm not sure if you can overload cpp macros w.r.t. 
> the number of arguments, but even if you could, they'd still be 
> _macros_ (bah! :-).
> 
> It also has the drawback that it fails for namespaced mainwindows:
> 
> #include "mainwindow.h"
> using myApp::MainWindow;
> 
> int main( int, char** ) {
>   //...
>   if ( kapp->isRestored() )
>     RESTORE(MainWindow); // fails
>   else
>     // ...
>   // ...
> }
> 
> Here's an alternative that should be BC and SC and with which the above 
> should work:
> 
> #define RESTORE(type) kRestoreMainWindows<type>();
> 
> template <typename T1>
> static inline kRestoreMainWindows() {
>   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n )
>     if ( T1::staticMetaObject()->className()
>          == KMainWindow::classNameOfTopLevel( n ) )
>       (new T1)->restore( n );
[...]

Excellent idea, I'm all for it :)

Just two things I wonder about:

1) why static? :)

2) might be worth caching the result of classNameOfTopLevel in the
   loop maybe (would increase readability IMHO)

Simon




More information about the kde-core-devel mailing list