ProxyFactory.h

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile$
00027  * Date modified: $Date: 2005-03-03 19:09:14 -0600 (Thu, 03 Mar 2005) $
00028  * Version:       $Revision: 16957 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #ifndef _GADGET_PROXY_FACTORY_H_
00034 #define _GADGET_PROXY_FACTORY_H_
00035 //#pragma once
00036 
00037 #include <gadget/gadgetConfig.h>
00038 #include <vector>
00039 #include <gadget/Type/Proxy.h>
00040 #include <jccl/Config/ConfigElementPtr.h>
00041 #include <vpr/Util/Singleton.h>
00042 #include <jccl/RTRC/DependencyManager.h>
00043 
00044 
00045 namespace gadget
00046 {
00047 
00054 class ProxyConstructorBase
00055 {
00056 public:
00061    ProxyConstructorBase()
00062    {;}
00063 
00064    virtual ~ProxyConstructorBase()
00065    {;}
00066 
00071    virtual Proxy* createProxy(jccl::ConfigElementPtr element) const = 0;
00072 
00074    virtual std::string getElementType() const = 0;
00075 };
00076 
00077 
00082 template <class PROXY>
00083 class ProxyConstructor : public ProxyConstructorBase
00084 {
00085 public:
00086    ProxyConstructor();
00087 
00092    Proxy* createProxy(jccl::ConfigElementPtr element) const
00093    {
00094       PROXY* new_proxy = new PROXY;             // Create new proxy
00095       bool success = new_proxy->config(element);  // Attempt to configure it
00096                                                   // config calls inputmgr registrator
00097 
00098       if(success)          // Configured succesfully
00099       {
00100          return new_proxy;
00101       }
00102       else                 // Failed
00103       {
00104   //XXX//       delete new_proxy;
00105          return NULL;
00106       }
00107    }
00108 
00109    std::string getElementType() const
00110    {
00111       return PROXY::getElementType();
00112    }
00113 };
00114 
00115 
00121 class ProxyFactory
00122 {
00123 private:
00125    ProxyFactory() {;}
00126 
00131    void loadKnownProxies();
00132 
00133 public:
00134    void registerProxy(ProxyConstructorBase* constructor);
00135 
00143    bool recognizeProxy(jccl::ConfigElementPtr element);
00144 
00153    Proxy* loadProxy(jccl::ConfigElementPtr element);
00154 
00155 private:
00156 
00162    int findConstructor(jccl::ConfigElementPtr element);
00163 
00164 private:
00165    std::vector<ProxyConstructorBase*> mConstructors;   
00168    vprSingletonHeaderWithInitFunc(ProxyFactory,loadKnownProxies);
00169 };
00170 
00171 } // end namespace
00172 
00173 #endif

Generated on Thu Jan 4 10:41:56 2007 for Gadgeteer by  doxygen 1.5.1