Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
parameterlist
src
Teuchos_ParameterEntryValidator.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_PARAMETER_ENTRY_VALIDATOR_H
11
#define TEUCHOS_PARAMETER_ENTRY_VALIDATOR_H
12
13
#include "
Teuchos_RCP.hpp
"
14
#include "
Teuchos_Array.hpp
"
15
#include "
Teuchos_XMLObject.hpp
"
16
#include "Teuchos_Describable.hpp"
17
18
namespace
Teuchos
{
19
20
21
#ifndef DOXYGEN_SHOULD_SKIP_THIS
22
class
ParameterEntry
;
23
#endif
24
31
class
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
ParameterEntryValidator
:
public
Describable
32
{
33
public
:
34
37
39
typedef
unsigned
int
ValidatorID
;
40
42
typedef
RCP<const Array<std::string>
>
ValidStringsList
;
43
45
47
ParameterEntryValidator
() {}
48
55
virtual
const
std::string
getXMLTypeName
()
const
=0;
56
68
virtual
void
printDoc
(
69
std::string
const
& docString,
70
std::ostream &out
71
)
const
= 0;
72
81
virtual
ValidStringsList
validStringValues
()
const
= 0;
82
94
virtual
void
validate
(
95
ParameterEntry
const
& entry,
96
std::string
const
& paramName,
97
std::string
const
& sublistName
98
)
const
= 0;
99
113
virtual
void
validateAndModify
(
114
std::string
const
& paramName,
115
std::string
const
& sublistName,
116
ParameterEntry
* entry
117
)
const
118
{
119
TEUCHOS_TEST_FOR_EXCEPT
(0==entry);
120
this->
validate
(*entry,paramName,sublistName);
121
}
122
123
double
convertStringToDouble(std::string str)
const
124
{
125
#ifdef HAVE_TEUCHOSCORE_CXX11
126
size_t
idx = 0;
127
double
result = std::stod(str, &idx);
// can throw std::invalid_argument
128
if
(idx != str.length()) {
// check for extra bad format characters
129
throw
std::invalid_argument(
"String: '"
+ str +
"' had bad formatting for converting to a double."
);
130
}
131
return
result;
132
#else
133
return
std::atof(str.c_str());
134
#endif
135
}
136
137
int
convertStringToInt(std::string str)
const
138
{
139
#ifdef HAVE_TEUCHOSCORE_CXX11
140
size_t
idx = 0;
141
int
result = std::stoi(str, &idx);
// can throw std::invalid_argument
142
if
(idx != str.length()) {
// check for extra bad format characters
143
throw
std::invalid_argument(
"String: '"
+ str +
"' had bad formatting for converting to an int."
);
144
}
145
return
result;
146
#else
147
return
std::atoi(str.c_str());
148
#endif
149
}
150
151
int
convertStringToLongLong(std::string str)
const
152
{
153
size_t
idx = 0;
154
long
long
result = std::stoll(str, &idx);
// can throw std::invalid_argument
155
if
(idx != str.length()) {
// check for extra bad format characters
156
throw
std::invalid_argument(
"String: '"
+ str +
"' had bad formatting for converting to a long long."
);
157
}
158
return
result;
159
}
160
161
};
162
163
164
}
// namespace Teuchos
165
166
167
#endif
// TEUCHOS_PARAMETER_ENTRY_VALIDATOR_H
Teuchos_Array.hpp
Templated array class derived from the STL std::vector.
Teuchos_RCP.hpp
Reference-counted pointer class and non-member templated function implementations.
Teuchos_XMLObject.hpp
An object representation of a subset of XML data.
Teuchos::Describable
Base class for all objects that can describe themselves.
Definition
Teuchos_Describable.hpp:44
Teuchos::ParameterEntry
This object is held as the "value" in the Teuchos::ParameterList std::map.
Definition
Teuchos_ParameterEntry.hpp:34
Teuchos::ParameterEntryValidator::printDoc
virtual void printDoc(std::string const &docString, std::ostream &out) const =0
Print documentation for this parameter.
Teuchos::ParameterEntryValidator::validStringValues
virtual ValidStringsList validStringValues() const =0
Return an array of strings of valid values if applicable.
Teuchos::ParameterEntryValidator::validate
virtual void validate(ParameterEntry const &entry, std::string const ¶mName, std::string const &sublistName) const =0
Validate a parameter entry value and throw std::exception (with a great error message) if validation ...
Teuchos::ParameterEntryValidator::validateAndModify
virtual void validateAndModify(std::string const ¶mName, std::string const &sublistName, ParameterEntry *entry) const
Validate and perhaps modify a parameter entry's value.
Definition
Teuchos_ParameterEntryValidator.hpp:113
Teuchos::ParameterEntryValidator::getXMLTypeName
virtual const std::string getXMLTypeName() const =0
Get a string that should be used as a value of the type attribute when serializing it to XML.
Teuchos::ParameterEntryValidator::ValidStringsList
RCP< const Array< std::string > > ValidStringsList
Definition
Teuchos_ParameterEntryValidator.hpp:42
Teuchos::ParameterEntryValidator::ValidatorID
unsigned int ValidatorID
Definition
Teuchos_ParameterEntryValidator.hpp:39
Teuchos::ParameterEntryValidator::ParameterEntryValidator
ParameterEntryValidator()
Default Constructor.
Definition
Teuchos_ParameterEntryValidator.hpp:47
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:397
TEUCHOS_TEST_FOR_EXCEPT
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call.
Definition
Teuchos_TestForException.hpp:285
Teuchos
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Generated by
1.17.0