CreatorInterface.h 2.55 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// 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.


20
21
22
23
24
25

/** \file CreatorInterface.h */

#ifndef AMDIS_CREATORINTERFACE_H
#define AMDIS_CREATORINTERFACE_H

26
27
#include "DOFMatrix.h"

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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:
46
    virtual ~CreatorInterface() {}
47
48
49
50
51
52
53

    /** \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
54
55
    virtual BaseClass* create(const DOFMatrix::base_matrix_type& A) 
    { 
56
57
      return 0; 
    }
58

59
    /// Can be implemented by sub classes.
60
    virtual void free(BaseClass *) {}
61

62
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
63
64
    virtual bool isNullCreator() 
    { 
65
      return false; 
66
    }
67
68
69
70
71
72
73
74
75
  };

  /** \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>
  {
76
    /// Creates no object.
Thomas Witkowski's avatar
Thomas Witkowski committed
77
78
    BaseClass* create() 
    {
79
      return NULL; 
80
    }
81

Praetorius, Simon's avatar
Praetorius, Simon committed
82
83
    virtual ~NullCreator() {}

84
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
85
86
    virtual bool isNullCreator() 
    { 
87
      return true; 
88
    }
89
90
91
92
93
  };

}

#endif