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
//
4
// Teuchos: Common Tools Package
5
// Copyright (2004) Sandia Corporation
6
//
7
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8
// license for use of this work by or on behalf of the U.S. Government.
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are
12
// met:
13
//
14
// 1. Redistributions of source code must retain the above copyright
15
// notice, this list of conditions and the following disclaimer.
16
//
17
// 2. Redistributions in binary form must reproduce the above copyright
18
// notice, this list of conditions and the following disclaimer in the
19
// documentation and/or other materials provided with the distribution.
20
//
21
// 3. Neither the name of the Corporation nor the names of the
22
// contributors may be used to endorse or promote products derived from
23
// this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38
//
39
// ***********************************************************************
40
// @HEADER
41
42
43
#include "
Teuchos_ParameterEntry.hpp
"
// class definition
44
#include "
Teuchos_ParameterList.hpp
"
// for sublists
45
#include "
Teuchos_TwoDArray.hpp
"
46
47
48
namespace
Teuchos
{
49
50
51
ParameterEntry::ParameterEntry
() :
52
isUsed_(false),
53
isDefault_(false)
54
{}
55
56
57
ParameterEntry::ParameterEntry
(
const
ParameterEntry
& source)
58
{
59
operator=
(source);
60
}
61
62
63
ParameterEntry
&
ParameterEntry::operator=
(
const
ParameterEntry
& source)
64
{
65
if
(&source ==
this
)
66
return
*
this
;
67
68
val_ = source.val_;
69
isUsed_ = source.isUsed_;
70
isDefault_ = source.isDefault_;
71
docString_ = source.docString_;
72
validator_ = source.validator_;
73
74
return
*
this
;
75
}
76
77
ParameterEntry::ParameterEntry
(
ParameterEntry
&& other)
78
: val_(std::move(other.val_)),
79
isUsed_(other.isUsed_),
80
isDefault_(other.isDefault_),
81
docString_(std::move(other.docString_)),
82
validator_(std::move(other.validator_))
83
{}
84
85
ParameterEntry
&
ParameterEntry::operator=
(
ParameterEntry
&& other)
86
{
87
if
(
this
!= &other)
88
{
89
this->val_ = std::move(other.val_);
90
this->isUsed_ = other.isUsed_;
91
this->isDefault_ = other.isDefault_;
92
this->docString_ = std::move(other.docString_);
93
this->validator_ = std::move(other.validator_);
94
}
95
return
*
this
;
96
}
97
98
void
ParameterEntry::setAnyValue
(
99
const
any
&value_in,
bool
isDefault_in
100
)
101
{
102
val_ = value_in;
103
isDefault_ = isDefault_in;
104
validator_ = null;
105
isUsed_ =
false
;
106
docString_ =
""
;
107
}
108
109
110
void
ParameterEntry::setValidator
(
111
RCP<const ParameterEntryValidator>
const
& validator_in
112
)
113
{
114
validator_ = validator_in;
115
}
116
117
118
void
ParameterEntry::setDocString
(
const
std::string &docString_in)
119
{
120
docString_ = docString_in;
121
}
122
123
124
ParameterList
&
ParameterEntry::setList
(
125
bool
isDefault_in,
const
std::string &docString_in
126
)
127
{
128
val_ =
ParameterList
();
129
isDefault_ = isDefault_in;
130
isUsed_ =
true
;
131
docString_ = docString_in;
132
return
any_cast<ParameterList>
( val_ );
133
}
134
135
136
bool
ParameterEntry::isList
()
const
137
{
138
return
( !val_.has_value() ?
false
: val_.type() ==
typeid
(
ParameterList
) );
139
}
140
141
std::ostream&
ParameterEntry::leftshift
(std::ostream& os,
bool
printFlags)
const
142
{
143
if
( !this->
isList
() ) os << val_;
144
145
if
(printFlags) {
146
if
(isDefault_)
147
os <<
" [default]"
;
148
else
if
(!isUsed_)
149
os <<
" [unused]"
;
150
}
151
152
return
os;
153
}
154
155
bool
ParameterEntry::isTwoDArray
()
const
{
156
std::string formatString =
getTwoDArrayTypeNameTraitsFormat
();
157
size_t
starPos = formatString.find(
"*"
);
158
std::string prefix = formatString.substr(0,starPos);
159
std::string postfix = formatString.substr(starPos+1);
160
std::string valueTypeName = val_.typeName();
161
size_t
prePos = valueTypeName.find(prefix);
162
size_t
postPos = valueTypeName.find(postfix);
163
return
(prePos != std::string::npos) && (prePos==0)
164
&& (postPos != std::string::npos) && (prePos < postPos);
165
}
166
167
bool
ParameterEntry::isArray
()
const
{
168
std::string formatString =
getArrayTypeNameTraitsFormat
();
169
size_t
starPos = formatString.find(
"*"
);
170
std::string prefix = formatString.substr(0,starPos);
171
std::string postfix = formatString.substr(starPos+1);
172
std::string valueTypeName = val_.typeName();
173
size_t
prePos = valueTypeName.find(prefix);
174
size_t
postPos = valueTypeName.find(postfix);
175
return
(prePos != std::string::npos) && (prePos==0)
176
&& (postPos != std::string::npos) && (prePos < postPos);
177
}
178
179
180
// private
181
182
183
void
ParameterEntry::reset()
184
{
185
//delete val_;
186
isUsed_ =
false
;
187
isDefault_ =
false
;
188
}
189
190
191
}
// namespace Teuchos
192
193
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:748
Teuchos::ParameterEntry::setValidator
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
Definition
Teuchos_ParameterEntry.cpp:110
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:124
Teuchos::ParameterEntry::operator=
ParameterEntry & operator=(const ParameterEntry &source)
Replace the current parameter entry with source.
Definition
Teuchos_ParameterEntry.cpp:63
Teuchos::ParameterEntry::ParameterEntry
ParameterEntry()
Default Constructor.
Definition
Teuchos_ParameterEntry.cpp:51
Teuchos::ParameterEntry::isTwoDArray
bool isTwoDArray() const
Test if the type of data being contained is a Teuchos::TwoDArray.
Definition
Teuchos_ParameterEntry.cpp:155
Teuchos::ParameterEntry::isArray
bool isArray() const
Test if the type of data being contained is a Teuchos::Array.
Definition
Teuchos_ParameterEntry.cpp:167
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:141
Teuchos::ParameterEntry::setDocString
void setDocString(const std::string &docString)
Set the documentation std::string.
Definition
Teuchos_ParameterEntry.cpp:118
Teuchos::ParameterEntry::isList
bool isList() const
Return whether or not the value itself is a list.
Definition
Teuchos_ParameterEntry.cpp:136
Teuchos::ParameterEntry::setAnyValue
void setAnyValue(const any &value, bool isDefault=false)
Set the value as an any object.
Definition
Teuchos_ParameterEntry.cpp:98
Teuchos::ParameterList
A list of parameters of arbitrary type.
Definition
Teuchos_ParameterList.hpp:133
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
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:442
Teuchos::any
Modified boost::any class, which is a container for a templated value.
Definition
Teuchos_any.hpp:155
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:359
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Generated by
1.17.0