# BasicPluginProxy.h

Go to the documentation of this file.

    00001 /*******************************************************************\
    00002
    00003               Copyright (C) 2003 Joseph Coffland
    00004
    00005     This program is free software; you can redistribute it and/or
    00006      modify it under the terms of the GNU General Public License
    00007     as published by the Free Software Foundation; either version 2
    00008         of the License, or (at your option) any later version.
    00009
    00010    This program is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013              GNU General Public License for more details.
    00014
    00015   You should have received a copy of the GNU General Public License
    00016      along with this program; if not, write to the Free Software
    00017       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    00018                            02111-1307, USA.
    00019
    00020             For information regarding this software email
    00021                    jcofflan@users.sourceforge.net
    00022
    00023 \*******************************************************************/
    00024
    00025 #ifndef BASICPLUGINPROXY_H
    00026 #define BASICPLUGINPROXY_H
    00027
    00028 #include <string>
    00029 #include <list>
    00030 #include <iostream>
    00031 #include <stdlib.h>
    00032
    00033 #include "BasicPluginManager.h"
    00034 #include "BasicPluginInfo.h"
    00035 #include "BasicException.h"
    00036 #include "BasicClassFactory.h"
    00037
    00038 template <class B, class T>
    00039 class BasicPluginProxy {
    00040 public:
    00041   BasicPluginProxy(const std::string name, const std::string description,
    00042                    BasicPluginManager<B> *manager)
    00043   {init(new BasicPluginInfo(name, description), manager);}
    00044
    00045   BasicPluginProxy(const std::string name, const std::string description,
    00046                    const unsigned int numDeps, const char *deps[],
    00047                    BasicPluginManager<B> *manager)
    00048   {init(new BasicPluginInfo(name, description, numDeps, deps), manager);}
    00049
    00050   BasicPluginProxy(const BasicPluginInfo &info, BasicPluginManager<B> *manager)
    00051   {init(new BasicPluginInfo(info), manager);}
    00052
    00053 protected:
    00060   virtual void init(BasicPluginInfo *info, BasicPluginManager<B> *manager) {
    00061     try {
    00062       if (!manager) {
    00063         std::cerr << "BasicPluginProxyBase() manager cannot be NULL!"
    00064                   << std::endl;
    00065         exit(1);
    00066       }
    00067
    00068       manager->registerPlugin(info, new BasicClassFactory<B, T>);
    00069
    00070     } catch (BasicException &e) {
    00071       manager->setPluginException(e);
    00072
    00073     } catch (...) {
    00074       manager->setPluginException
    00075         (BasicException("Unknown exception during registration!"));
    00076     }
    00077   }
    00078 };
    00079
    00080 #endif