- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Lang/FactorySupport.h

    00001
    00002 //
    00003 // Copyright (c) 2006           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #ifndef MERS_UTILS_LANG_FACTORYSUPPORT_H
    00012 #define MERS_UTILS_LANG_FACTORYSUPPORT_H
    00013
    00015
    00016 #include "Factory.h"
    00017
    00019
    00020 namespace Mers {
    00021 namespace Utils {
    00022 namespace Lang {
    00023
    00025
    00031 template< typename t_Factory, class t_Support >
    00032 class FactorySupport
    00033 {
    00034 public:
    00039         FactorySupport( const char * className ) : m_atLeastOneSupported( true )
    00040         {
    00041                 support< t_Support >( t_Factory::getSingleton(), className );
    00042         }
    00043
    00049         FactorySupport() : m_atLeastOneSupported( true )
    00050         {
    00051                 support< t_Support >( t_Factory::getSingleton(),
    00052                         t_Support::getClassTypeName() );
    00053         }
    00054
    00059         FactorySupport( const char * classNames[] )
    00060         {
    00061                 // Record if we will register at least once.
    00062                 m_atLeastOneSupported = (classNames[0] != NULL);
    00063                 // Get our Factory< t_Base >
    00064                 t_Factory &factory( t_Factory::getSingleton() );
    00065                 // Register under all the names.
    00066                 for( const char ** names = classNames; *names != NULL; ++names )
    00067                 {
    00068                         support< t_Support >( factory, *names );
    00069                 }
    00070         }
    00071
    00075         ~FactorySupport()
    00076         {
    00077                 if( m_atLeastOneSupported )
    00078                         unsupport< t_Support >( t_Factory::getSingleton() );
    00079         }
    00080
    00081 protected:
    00082         // True if we have at least one name registered.
    00083         bool m_atLeastOneSupported;
    00084
    00085 private:
    00092         template< class t_Obj >
    00093         void support( t_Factory &factory, const char * name )
    00094         {
    00095                 factory.support< t_Obj >( name );
    00096         }
    00097
    00104         template< class t_Obj >
    00105         void unsupport( t_Factory &factory )
    00106         {
    00107                 factory.unsupport< t_Obj >();
    00108         }
    00109 };
    00110
    00112
    00113 } // Lang
    00114 } // Utils
    00115 } // Mers
    00116
    00118
    00119 #endif