/* 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_T_CONSTRUCTOR_HPP
#define NMM_T_CONSTRUCTOR_HPP NMM_T_CONSTRUCTOR_HPP

#include "nmm/nmm_prefix.hpp"

#include "TValueConstructor.hpp"
#include "visibility.hpp"

namespace NMM {

  /** Constructor for a Value type.
   * This class is a template factory object for the ValueFactory.
   * It creates objects of a type which is a subclass of TValue.
   *
   * A value constructor is created as a global object. It automatically registers and unregisters
   * itself at the ValueFactory. Example:
   * @code
   * static TConstructor<INode> __INode_constructor("INode", "NMM");
   * @endcode
   */
  template<class T>
  class /*DLLEXPORT*/ TConstructor : public ValueConstructor {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Constructor.
     * This constructor registers the object at the ValueFactory.
     *
     * @param type_name Type name of type of objects this factory object creates
     * @param ns Type namespace of type of objects this factory object creates
     */
    TConstructor(const string& type_name, const string& ns)
      : ValueConstructor(TypeInfo(type_name, ns))
    {}

    /** Constructor.
     * This constructor registers the object at the ValueFactory.
     *
     * @param ti Type information of type of objects this factory object creates
     */
    TConstructor(const TypeInfo& ti)
      : ValueConstructor(ti)
    {}

    /** Virtual copy constructor.
     * This copy constructor is used by the ValueFactory.
     *
     * @return A copy of this object which has the same type
     */
    virtual ValueConstructor* copy()  const    { return new TConstructor<T>(*this); }
    //@}

    /** @name Factory method
     */
    //@{
    /** Create a value.
     * This method creates a new object. It must be implemented in a subclass.
     * The caller of this method is responsible for deleting the object.
     *
     * This method creates a value object of type T.
     *
     * @return Pointer to the created object
     */
    virtual Value*          createValue()           const {return new T();}

    /** Create a wrapped value.
     * This method creates a new object. It must be implemented in a subclass.
     * The caller of this method is responsible for deleting the object.
     *
     * This method creates a wrapped value object of type TValue<T>.
     *
     * @return Pointer to the created object
     */
    virtual Value*          createTValue()          const {return new TValue<T>();}

    /** Create a wrapped pointer value.
     * This method creates a new object. It must be implemented in a subclass.
     * The caller of this method is responsible for deleting the object.
     *
     * This method creates a wrapped value pointer object of type TValue<T*>.
     *
     * @return Pointer to the created object
     */
    virtual Value*          createTPointerValue()   const {return new TValue<T*>();}
    //@}
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif
