Teko
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
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
15
namespace
Teko {
16
18
class
Cloneable
{
19
public
:
20
virtual
~Cloneable
() {}
21
29
virtual
Teuchos::RCP<Cloneable>
clone
()
const
= 0;
30
};
31
35
class
AutoCloneDummy
{};
36
55
template
<
class
CloneType,
class
BaseType = AutoCloneDummy>
56
class
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
78
AutoClone
(
const
AutoClone<BaseType>
&);
79
};
80
90
template
<
class
CloneBaseType>
91
class
CloneFactory
{
92
public
:
94
CloneFactory
() {}
95
97
CloneFactory
(
const
CloneFactory<CloneBaseType>
& cf) :
parentClones_
(cf.
parentClones_
) {}
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
Teko::AutoCloneDummy
Definition
Teko_CloneFactory.hpp:35
Teko::AutoClone
Definition
Teko_CloneFactory.hpp:56
Teko::AutoClone::AutoClone
AutoClone()
Definition
Teko_CloneFactory.hpp:63
Teko::AutoClone::clone
virtual Teuchos::RCP< Cloneable > clone() const
Definition
Teko_CloneFactory.hpp:72
Teko::CloneFactory
Definition
Teko_CloneFactory.hpp:91
Teko::CloneFactory::CloneFactory
CloneFactory()
Default constructor.
Definition
Teko_CloneFactory.hpp:94
Teko::CloneFactory::addClone
virtual void addClone(const std::string &str, const Teuchos::RCP< Cloneable > &clone)
Definition
Teko_CloneFactory.hpp:131
Teko::CloneFactory::getCloneNames
void getCloneNames(std::vector< std::string > &names) const
Definition
Teko_CloneFactory.hpp:142
Teko::CloneFactory::parentClones_
std::map< std::string, Teuchos::RCP< const Cloneable > > parentClones_
stores the clonable objects
Definition
Teko_CloneFactory.hpp:150
Teko::CloneFactory::cloneCount
virtual int cloneCount() const
Return the number of clones stored in this factory.
Definition
Teko_CloneFactory.hpp:136
Teko::CloneFactory::build
virtual Teuchos::RCP< CloneBaseType > build(const std::string &str) const
Definition
Teko_CloneFactory.hpp:115
Teko::CloneFactory::CloneFactory
CloneFactory(const CloneFactory< CloneBaseType > &cf)
Copy constructor.
Definition
Teko_CloneFactory.hpp:97
Teko::Cloneable
Definition
Teko_CloneFactory.hpp:18
Teko::Cloneable::clone
virtual Teuchos::RCP< Cloneable > clone() const =0
Generated by
1.17.0