/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */


#ifndef NMM_OBJECT_FACTORY_HPP
#define NMM_OBJECT_FACTORY_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/utils/Singleton.hpp"

#include <string>
#include <map>

namespace NMM {

  class NMMObject;
  class ObjectFactoryObject;

  /** A factory that creates NMM objects.
   */
  class ObjectFactory
  {
    DECLARE_SINGLETON(ObjectFactory, CreateUsingNew, DefaultLifetime, MultiThreaded);
    friend class CreateUsingNew<ObjectFactory>;
  public:
    /** Register a factory object.
     *
     * @param object Reference to factory object to register, must not be destroyed before unregistered
     * @post object is registered for class name object.getclassName()
     */
    void registerFactoryObject(const ObjectFactoryObject& object);

    /** Unregister a factory object.
     *
     * @param object Reference to factory object to unregister
     * @post No object is registered for class name object.getclassName()
     */
    void unregisterFactoryObject(const ObjectFactoryObject& object);

    /** Create an object.
     *
     * @param class_name Class name of object to register
     * @return A pointer to the created object or a null pointer if no factory object is registered for @c class_name
     * @exception Any exception the object constructor throws
     */
    NMMObject* createObject(const std::string& class_name) const;

  private:
    typedef std::map<std::string, const ObjectFactoryObject*> FactoryMap;
    FactoryMap __factory_map;
  };

  /** Singleton wrapper for ObjectFactory. */
  typedef ObjectFactory::Singleton SObjectFactory;

}

#include "nmm/nmm_suffix.hpp"

#endif
