Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
parameterlist
src
Teuchos_ParameterEntry.cpp
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
#include "
Teuchos_ParameterEntry.hpp
"
// class definition
11
#include "
Teuchos_ParameterList.hpp
"
// for sublists
12
#include "
Teuchos_TwoDArray.hpp
"
13
14
15
namespace
Teuchos
{
16
17
18
ParameterEntry::ParameterEntry
() :
19
isUsed_(false),
20
isDefault_(false)
21
{}
22
23
24
ParameterEntry::ParameterEntry
(
const
ParameterEntry
& source)
25
{
26
operator=
(source);
27
}
28
29
30
ParameterEntry
&
ParameterEntry::operator=
(
const
ParameterEntry
& source)
31
{
32
if
(&source ==
this
)
33
return
*
this
;
34
35
val_ = source.val_;
36
isUsed_ = source.isUsed_;
37
isDefault_ = source.isDefault_;
38
docString_ = source.docString_;
39
validator_ = source.validator_;
40
41
return
*
this
;
42
}
43
44
ParameterEntry::ParameterEntry
(
ParameterEntry
&& other)
45
: val_(std::move(other.val_)),
46
isUsed_(other.isUsed_),
47
isDefault_(other.isDefault_),
48
docString_(std::move(other.docString_)),
49
validator_(std::move(other.validator_))
50
{}
51
52
ParameterEntry
&
ParameterEntry::operator=
(
ParameterEntry
&& other)
53
{
54
if
(
this
!= &other)
55
{
56
this->val_ = std::move(other.val_);
57
this->isUsed_ = other.isUsed_;
58
this->isDefault_ = other.isDefault_;
59
this->docString_ = std::move(other.docString_);
60
this->validator_ = std::move(other.validator_);
61
}
62
return
*
this
;
63
}
64
65
void
ParameterEntry::setAnyValue
(
66
const
any
&value_in,
bool
isDefault_in
67
)
68
{
69
val_ = value_in;
70
isDefault_ = isDefault_in;
71
validator_ = null;
72
isUsed_ =
false
;
73
docString_ =
""
;
74
}
75
76
77
void
ParameterEntry::setValidator
(
78
RCP<const ParameterEntryValidator>
const
& validator_in
79
)
80
{
81
validator_ = validator_in;
82
}
83
84
85
void
ParameterEntry::setDocString
(
const
std::string &docString_in)
86
{
87
docString_ = docString_in;
88
}
89
90
91
ParameterList
&
ParameterEntry::setList
(
92
bool
isDefault_in,
const
std::string &docString_in
93
)
94
{
95
val_ =
ParameterList
();
96
isDefault_ = isDefault_in;
97
isUsed_ =
true
;
98
docString_ = docString_in;
99
return
any_cast<ParameterList>
( val_ );
100
}
101
102
103
bool
ParameterEntry::isList
()
const
104
{
105
return
( !val_.has_value() ?
false
: val_.type() ==
typeid
(
ParameterList
) );
106
}
107
108
std::ostream&
ParameterEntry::leftshift
(std::ostream& os,
bool
printFlags)
const
109
{
110
if
( !this->
isList
() ) os << val_;
111
112
if
(printFlags) {
113
if
(isDefault_)
114
os <<
" [default]"
;
115
else
if
(!isUsed_)
116
os <<
" [unused]"
;
117
}
118
119
return
os;
120
}
121
122
bool
ParameterEntry::isTwoDArray
()
const
{
123
std::string formatString =
getTwoDArrayTypeNameTraitsFormat
();
124
size_t
starPos = formatString.find(
"*"
);
125
std::string prefix = formatString.substr(0,starPos);
126
std::string postfix = formatString.substr(starPos+1);
127
std::string valueTypeName = val_.typeName();
128
size_t
prePos = valueTypeName.find(prefix);
129
size_t
postPos = valueTypeName.find(postfix);
130
return
(prePos != std::string::npos) && (prePos==0)
131
&& (postPos != std::string::npos) && (prePos < postPos);
132
}
133
134
bool
ParameterEntry::isArray
()
const
{
135
std::string formatString =
getArrayTypeNameTraitsFormat
();
136
size_t
starPos = formatString.find(
"*"
);
137
std::string prefix = formatString.substr(0,starPos);
138
std::string postfix = formatString.substr(starPos+1);
139
std::string valueTypeName = val_.typeName();
140
size_t
prePos = valueTypeName.find(prefix);
141
size_t
postPos = valueTypeName.find(postfix);
142
return
(prePos != std::string::npos) && (prePos==0)
143
&& (postPos != std::string::npos) && (prePos < postPos);
144
}
145
146
147
// private
148
149
150
void
ParameterEntry::reset()
151
{
152
//delete val_;
153
isUsed_ =
false
;
154
isDefault_ =
false
;
155
}
156
157
158
}
// namespace Teuchos
159
160
Teuchos_ParameterEntry.hpp
Object held as the "value" in the Teuchos::ParameterList std::map.
Teuchos_ParameterList.hpp
Templated Parameter List class.
Teuchos_TwoDArray.hpp
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
Teuchos::Array::getArrayTypeNameTraitsFormat
std::string getArrayTypeNameTraitsFormat()
Get the format that is used for the specialization of the TypeName traits class for Array.
Definition
Teuchos_Array.hpp:719
Teuchos::ParameterEntry::setValidator
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
Definition
Teuchos_ParameterEntry.cpp:77
Teuchos::ParameterEntry::setList
ParameterList & setList(bool isDefault=false, const std::string &docString="")
Create a parameter entry that is an empty list.
Definition
Teuchos_ParameterEntry.cpp:91
Teuchos::ParameterEntry::operator=
ParameterEntry & operator=(const ParameterEntry &source)
Replace the current parameter entry with source.
Definition
Teuchos_ParameterEntry.cpp:30
Teuchos::ParameterEntry::ParameterEntry
ParameterEntry()
Default Constructor.
Definition
Teuchos_ParameterEntry.cpp:18
Teuchos::ParameterEntry::isTwoDArray
bool isTwoDArray() const
Test if the type of data being contained is a Teuchos::TwoDArray.
Definition
Teuchos_ParameterEntry.cpp:122
Teuchos::ParameterEntry::isArray
bool isArray() const
Test if the type of data being contained is a Teuchos::Array.
Definition
Teuchos_ParameterEntry.cpp:134
Teuchos::ParameterEntry::leftshift
std::ostream & leftshift(std::ostream &os, bool printFlags=true) const
Output a non-list parameter to the given output stream.
Definition
Teuchos_ParameterEntry.cpp:108
Teuchos::ParameterEntry::setDocString
void setDocString(const std::string &docString)
Set the documentation std::string.
Definition
Teuchos_ParameterEntry.cpp:85
Teuchos::ParameterEntry::isList
bool isList() const
Return whether or not the value itself is a list.
Definition
Teuchos_ParameterEntry.cpp:103
Teuchos::ParameterEntry::setAnyValue
void setAnyValue(const any &value, bool isDefault=false)
Set the value as an any object.
Definition
Teuchos_ParameterEntry.cpp:65
Teuchos::ParameterList
A list of parameters of arbitrary type.
Definition
Teuchos_ParameterList.hpp:101
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:397
Teuchos::TwoDArray::getTwoDArrayTypeNameTraitsFormat
std::string getTwoDArrayTypeNameTraitsFormat()
Get the format that is used for the specialization of the TypeName traits class for TwoDArray.
Definition
Teuchos_TwoDArray.hpp:410
Teuchos::any
Modified boost::any class, which is a container for a templated value.
Definition
Teuchos_any.hpp:123
Teuchos::any::any_cast
ValueType & any_cast(any &operand)
Used to extract the templated value held in Teuchos::any to a given value type.
Definition
Teuchos_any.hpp:327
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Generated by
1.17.0