Teko Version of the Day
Loading...
Searching...
No Matches
Teko_CloneFactory.hpp
1// @HEADER
2// *****************************************************************************
3// Teko: A package for block and physics based preconditioning
4//
5// Copyright 2010 NTESS and the Teko contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef __Teko_CloneFactory_hpp__
11#define __Teko_CloneFactory_hpp__
12
13#include "Teuchos_RCP.hpp"
14
15namespace Teko {
16
18class Cloneable {
19 public:
20 virtual ~Cloneable() {}
21
29 virtual Teuchos::RCP<Cloneable> clone() const = 0;
30};
31
36
55template <class CloneType, class BaseType = AutoCloneDummy>
56class AutoClone : public Cloneable, public BaseType {
57 public:
58 virtual ~AutoClone() {}
59
63 AutoClone() : BaseType() {}
64
72 virtual Teuchos::RCP<Cloneable> clone() const {
73 return Teuchos::rcp(new AutoClone<CloneType, CloneType>());
74 }
75
76 private:
77 // hidden
79};
80
90template <class CloneBaseType>
92 public:
95
98
99 virtual ~CloneFactory() {}
100
115 virtual Teuchos::RCP<CloneBaseType> build(const std::string& str) const {
116 std::map<std::string, Teuchos::RCP<const Cloneable> >::const_iterator itr =
117 parentClones_.find(str);
118 if (itr == parentClones_.end()) return Teuchos::null;
119 return Teuchos::rcp_dynamic_cast<CloneBaseType>(itr->second->clone(), true);
120 }
121
131 virtual void addClone(const std::string& str, const Teuchos::RCP<Cloneable>& clone) {
132 parentClones_[str] = clone;
133 }
134
136 virtual int cloneCount() const { return parentClones_.size(); }
137
142 void getCloneNames(std::vector<std::string>& names) const {
143 std::map<std::string, Teuchos::RCP<const Cloneable> >::const_iterator itr;
144 for (itr = parentClones_.begin(); itr != parentClones_.end(); ++itr)
145 names.push_back(itr->first);
146 }
147
148 protected:
150 std::map<std::string, Teuchos::RCP<const Cloneable> > parentClones_;
151};
152
153} // namespace Teko
154
155#endif
virtual Teuchos::RCP< Cloneable > clone() const
CloneFactory()
Default constructor.
virtual void addClone(const std::string &str, const Teuchos::RCP< Cloneable > &clone)
void getCloneNames(std::vector< std::string > &names) const
std::map< std::string, Teuchos::RCP< const Cloneable > > parentClones_
stores the clonable objects
virtual int cloneCount() const
Return the number of clones stored in this factory.
virtual Teuchos::RCP< CloneBaseType > build(const std::string &str) const
CloneFactory(const CloneFactory< CloneBaseType > &cf)
Copy constructor.
virtual Teuchos::RCP< Cloneable > clone() const =0