Skip to content
Snippets Groups Projects
CreatorInterface.h 2.55 KiB
Newer Older
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==                                                                        ==
// ============================================================================
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.



/** \file CreatorInterface.h */

#ifndef AMDIS_CREATORINTERFACE_H
#define AMDIS_CREATORINTERFACE_H

namespace AMDiS {

  /** \ingroup Common
   * \brief
   * Interface for the implementation of the factory method pattern.
   * The creation of an object of a sub class of BaseClass is deligated
   * to a corresponding sub class of Creator<BaseClass>. So it is possible to
   * manage a CreatorMap, which can be extended at run-time. An example is
   * the OEMSolverMap: If you write your own OEMSolver sub class and a
   * corresponding Creator<OEMSolver<T> >, you can add the creator together
   * with a key string to the OEMSolverMap. Then you can create an OEMSolver
   * depending of a key string read from the init file, which can also be
   * your own new solver.
   */
  template<typename BaseClass>
  class CreatorInterface
  {
  public:
    virtual ~CreatorInterface() {}

    /** \brief
     * Must be implemented by sub classes of CreatorInterface.
     * Creates a new instance of the sub class of BaseClass.
     */
    virtual BaseClass* create() = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
    virtual BaseClass* create(const DOFMatrix::base_matrix_type& A) 
    { 
    /// Can be implemented by sub classes.
    virtual void free(BaseClass *) {}
Thomas Witkowski's avatar
Thomas Witkowski committed
    virtual bool isNullCreator() 
    { 
  };

  /** \brief
   * A Creator which creates no object abd returns NULL instead.
   * Used together with the key word 'no' in CreatorMap.
   */
  template<typename BaseClass>
  class NullCreator : public CreatorInterface<BaseClass>
  {
    /// Creates no object.
Thomas Witkowski's avatar
Thomas Witkowski committed
    BaseClass* create() 
    {
    virtual ~NullCreator() {}

Thomas Witkowski's avatar
Thomas Witkowski committed
    virtual bool isNullCreator() 
    {