TAG

首都機能移轉 (2) 歌詞 (2) 靠北文 (40) 戲言 (30) 糟糕 (7) ACG (23) Assembly (2) Boost (2) C (31) C++ (69) CMake (4) CSIE (67) Debian (34) Design_Pattern (2) Django (1) Eclipse (1) en_US (13) FFmpeg (3) FoolproofProject (26) FreeBSD (2) Git (4) GNU_Linux (65) IDE (5) Java (11) JavaScript (19) KDE (15) Khopper (16) KomiX (3) Kubuntu (18) Life (1) Lighttpd (2) Mac_OS_X (2) Opera (1) PHP (2) PicKing (2) Programing (21) Prolog (1) Python (7) QSnapshot (2) Qt (30) Qt_Jambi (1) Regular_Expression (1) Shell_Script (7) Talk (98) VirtualBox (7) Visual_Studio (13) Windows (18) zh_TW (36)

2009年4月2日 星期四

太嫩了

這是上星期我改的某個程式片段:
template< typename ProductCreator >
class CreatorLoader {
public:
    CreatorLoader( const std::string & plugin ) : plugin_( plugin ) {}
    ProductCreator * operator()() {
        plugin::PluginContext pc;
        ProductCreator * c = qobject_cast< ProductCreator * >( pc.load( this->plugin_.c_str() ) );
        if( !c ) {
            throw Error< RunTime >( "Invalid plugin!" );
        }
        return c;
    }
private:
    std::string plugin_;
};

template< typename Product, typename CreatorFactory >
bool registerProduct( const std::string & key, const std::string & plugin ) {
    return CreatorFactory::Instance().Register( key, CreatorLoader< Creator< Product > >( plugin ) );
}

template< typename Product, typename CreatorFactory >
std::tr1::shared_ptr< Product > createProduct( const std::string & key ) {
    Creator< Product > * tmp = NULL;
    try {
        tmp = CreatorFactory::Instance().CreateObject( key );
    } catch( std::exception & e ) {
        tmp = CreatorFactory::Instance().CreateObject( "*" );
    }
    return tmp->create();
}
現在看就需要點思考時間 ... = =,還是補點註解好了。

沒有留言:

張貼留言