/* 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_TFACOTRY_OBJECT_HPP
#define NMM_TFACTORY_OBJECT_HPP NMM_TFACTORY_OBJECT_HPP

#include "nmm/nmm_prefix.hpp"

#include "FactoryObject.hpp"

namespace NMM {

class Node;

/** A factory object for a specific class.
 * This template class provides the implementation of FactoryObject for a specific class of node.
 * It implements the factory method by creating an instance of class T.
 */
template <class T>
class TFactoryObject : public FactoryObject {
public:
  /** @name Constructor & Destructor
    */
  //@{
  /** Create a new factory object.
   *
   * @param plugin_name Name of the plug-in which provides the node class
   * @param node_name Name of the node class
   */
  TFactoryObject(const string& plugin_name, const string& node_name) : FactoryObject(plugin_name, node_name) {};

  /** Virtual destructor.
   */
  virtual ~TFactoryObject(){};
  //@}

  /** @name Factory methods
   */
  //@{
  /** Create an instance of this node class.
   *
   * @return A pointer to the new node
   */
  virtual Node* createNode()                  { T* tmp_object = new T(); object_list.push_back(tmp_object); return tmp_object;}

  /** Release a node.
   *
   * @param node A node created by this factory object
   */
  virtual void  releaseNode(Node* node)       { object_list.remove(node); delete node; }

  /** Virtual copy constructor
   *
   * @return A pointer to a copy of this factory object
   */
  virtual FactoryObject* copy()         const { return new TFactoryObject<T>(*this); }
  //@}
private:
  list<Node*> object_list;    ///< List of created objects
};


} //end namespace
#include "nmm/nmm_suffix.hpp"

#endif
