Code Search for Developers
 
 
  

registry.h from osgDesigner at Krugle


Show registry.h syntax highlighted

#ifndef __GEN_PROG_PLUGIN_REGISTRY_H__
#define __GEN_PROG_PLUGIN_REGISTRY_H__ 1



// ** standart include
#include <memory>
#include <vector>
#include <iterator>
#include <map>

// ** thread include
#include <boost/thread/recursive_mutex.hpp>


#include <osg/ref_ptr>
#include <gen_prog/plugin/detail/thread_locker.h>
#include <gen_prog/plugin/proxy.h>


namespace gen_prog
{   
    namespace plugin
    {
//        template < typename Deriv, typename R > class proxy;
        /* The registry template containe the data which the proxy registre and unregitre 
         *      @\param D : the data to registre
         *      @\param DC : the data pointer container
         *      @\param T : the thread_locker, it must be recursive 
         */
        template < typename D,
                   typename T = detail::thread_locker< boost::recursive_mutex, boost::recursive_mutex::scoped_lock > >
        class registry : public T
        {
            public:
                
                typedef registry< D, T >                                    self_type;
                
                typedef D                                                   plugin_type;
                typedef T                                                   thread_locker_type;

                typedef typename plugin_type::instance_type                 plugin_instance_type;                
                typedef typename plugin_type::key_type                      key_type;
                typedef typename std::vector< key_type >                    key_list;
                typedef typename std::map< key_type, osg::ref_ptr< plugin_type > >    container_type;
                
                typedef typename thread_locker_type::scoped_lock_type       scoped_lock_type;
                
            public:
                
                registry()
                {}
                
                plugin_type * get(const key_type & key) 
                {
                    scoped_lock_type lock(this->toMutex());
                    
                    typename container_type::iterator it = _container.find(key);
                    if (it != _container.end())
                        return (it->second.get());
                    else
                        return (NULL);
                }
                
                std::size_t getAvailable(key_list & keyList) const
                {
                    scoped_lock_type lock(this->toMutex());
                    
                    return (keyList.size());
                }
            
           // protected:
                 
                // ** proxy interface
                void reg(plugin_type * plugin_)
                {
                    scoped_lock_type lock(this->toMutex());
                    
                    _container[plugin_->key()] = plugin_;
                }
                void unreg(plugin_type * plugin_)
                {
                    scoped_lock_type lock(this->toMutex());
                    
                    _container.erase(plugin_->key());
                }
            
                //! allow access of reg and unreg to the proxy
//                template < typename Deriv >
//                friend class proxy<Deriv, self_type>;
            
            private:
            
                container_type _container;
        };
    }
}
#endif // ** __GEN_PROG_PLUGIN_REGISTRY_H__ ** //




See more files for this project here

osgDesigner

osgDesigner is a graphical tool used to modify an OpenSceneGraph (OSG) scene using the osgIntrospection framework. OpenSceneGraph developpers will be able to extend osgDesigner at need using (editor | render | osgIntrospection wrapper) plugin system.

Project homepage: http://sourceforge.net/projects/osgdesigner
Programming language(s): C++,Shell Script
License: other

  detail/
    dynamic_library_identifier.h
    singleton.h
    thread_locker.h
    tracker.h
  dynamic_library.h
  dynamic_library_manager.h
  dynamic_library_manager_traits.h
  plugin_manager.h
  proxy.h
  registry.h