Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
Teuchos_AbstractFactoryStd.hpp
1
// @HEADER
2
// *****************************************************************************
3
// Teuchos: Common Tools Package
4
//
5
// Copyright 2004 NTESS and the Teuchos contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef TEUCHOS_ABSTRACT_FACTORY_STD_HPP
11
#define TEUCHOS_ABSTRACT_FACTORY_STD_HPP
12
13
#include "Teuchos_AbstractFactory.hpp"
14
15
namespace
Teuchos
{
16
20
template
<
class
T_impl>
21
class
PostModNothing
{
22
public
:
24
void
initialize
(T_impl*
/* p */
)
const
{}
// required!
25
};
26
30
template
<
class
T_impl>
31
class
AllocatorNew
{
32
public
:
34
typedef
Teuchos::RCP<T_impl>
ptr_t
;
// required!
36
const
ptr_t
allocate
()
const
{
return
Teuchos::rcp
(
new
T_impl()); }
// required!
37
};
38
106
template
<
class
T_itfc,
class
T_impl
107
,
class
T_PostMod = PostModNothing<T_impl>
108
,
class
T_Allocator = AllocatorNew<T_impl>
109
>
110
class
AbstractFactoryStd
:
public
AbstractFactory
<T_itfc> {
111
public
:
112
113
typedef
typename
Teuchos::AbstractFactory<T_itfc>::obj_ptr_t
obj_ptr_t;
// RAB: 20030916: G++ 3.2 complains without this
114
116
AbstractFactoryStd
(
const
T_PostMod& post_mod = T_PostMod(),
const
T_Allocator& alloc = T_Allocator() );
117
120
121
obj_ptr_t
create
()
const
;
123
124
private
:
125
T_PostMod post_mod_;
126
T_Allocator alloc_;
127
128
};
129
130
135
template
<
class
T_itfc,
class
T_impl>
136
RCP<const AbstractFactory<T_itfc>
>
137
abstractFactoryStd
()
138
{
139
return
rcp
(
140
new
AbstractFactoryStd
<T_itfc,T_impl,
PostModNothing<T_impl>
,
AllocatorNew<T_impl>
>()
141
);
142
}
143
144
149
template
<
class
T_itfc,
class
T_impl,
class
T_Allocator>
150
RCP<const AbstractFactory<T_itfc>
>
151
abstractFactoryStd
(
const
T_Allocator& alloc = T_Allocator() )
152
{
153
return
rcp
(
154
new
AbstractFactoryStd
<T_itfc,T_impl,
PostModNothing<T_impl>
,T_Allocator>(
155
PostModNothing<T_impl>
(), alloc
156
)
157
);
158
}
159
160
161
// ///////////////////////////////////////////////////////
162
// Template member definitions
163
164
template
<
class
T_itfc,
class
T_impl,
class
T_PostMod,
class
T_Allocator>
165
inline
166
AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::AbstractFactoryStd
(
167
const
T_PostMod& post_mod,
const
T_Allocator& alloc
168
)
169
:post_mod_(post_mod)
170
,alloc_(alloc)
171
{}
172
173
template
<
class
T_itfc,
class
T_impl,
class
T_PostMod,
class
T_Allocator>
174
inline
175
typename
AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::obj_ptr_t
176
AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::create
()
const
177
{
178
typename
T_Allocator::ptr_t
179
ptr
= alloc_.allocate();
180
post_mod_.initialize(
ptr
.get());
181
return
ptr
;
182
}
183
184
}
// end Teuchos
185
186
#endif
// TEUCHOS_ABSTRACT_FACTORY_STD_HPP
Teuchos::AbstractFactory
Simple, universal "Abstract Factory" interface for the dynamic creation of objects.
Definition
Teuchos_AbstractFactory.hpp:29
Teuchos::AbstractFactoryStd::abstractFactoryStd
RCP< const AbstractFactory< T_itfc > > abstractFactoryStd()
Nonmember constructor for an standar abstract factory object.
Definition
Teuchos_AbstractFactoryStd.hpp:137
Teuchos::AbstractFactoryStd::create
obj_ptr_t create() const
Definition
Teuchos_AbstractFactoryStd.hpp:176
Teuchos::AbstractFactoryStd::AbstractFactoryStd
AbstractFactoryStd(const T_PostMod &post_mod=T_PostMod(), const T_Allocator &alloc=T_Allocator())
Definition
Teuchos_AbstractFactoryStd.hpp:166
Teuchos::AbstractFactoryStd::abstractFactoryStd
RCP< const AbstractFactory< T_itfc > > abstractFactoryStd(const T_Allocator &alloc=T_Allocator())
Nonmember constructor for an standar abstract factory object.
Definition
Teuchos_AbstractFactoryStd.hpp:151
Teuchos::AllocatorNew
Default allocation policy class for AbstractFactoryStd which returns new T_impl().
Definition
Teuchos_AbstractFactoryStd.hpp:31
Teuchos::AllocatorNew::ptr_t
Teuchos::RCP< T_impl > ptr_t
Definition
Teuchos_AbstractFactoryStd.hpp:34
Teuchos::AllocatorNew::allocate
const ptr_t allocate() const
Definition
Teuchos_AbstractFactoryStd.hpp:36
Teuchos::PostModNothing
Default post-modification policy class for AbstractFactorStd which does nothing!
Definition
Teuchos_AbstractFactoryStd.hpp:21
Teuchos::PostModNothing::initialize
void initialize(T_impl *) const
Definition
Teuchos_AbstractFactoryStd.hpp:24
Teuchos::Ptr::ptr
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
Definition
Teuchos_PtrDecl.hpp:296
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:397
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Definition
Teuchos_RCPDecl.hpp:1234
Generated by
1.17.0