Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
parameterlist
src
Teuchos_ParameterEntryValidator.hpp
Go to the documentation of this file.
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
#ifndef TEUCHOS_PARAMETER_ENTRY_VALIDATOR_H
44
#define TEUCHOS_PARAMETER_ENTRY_VALIDATOR_H
45
46
#include "
Teuchos_RCP.hpp
"
47
#include "
Teuchos_Array.hpp
"
48
#include "
Teuchos_XMLObject.hpp
"
49
#include "
Teuchos_Describable.hpp
"
50
51
namespace
Teuchos
{
52
53
54
#ifndef DOXYGEN_SHOULD_SKIP_THIS
55
class
ParameterEntry
;
56
#endif
57
64
class
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
ParameterEntryValidator
:
public
Describable
65
{
66
public
:
67
70
72
typedef
unsigned
int
ValidatorID
;
73
75
typedef
RCP<const Array<std::string>
>
ValidStringsList
;
76
78
80
ParameterEntryValidator
() {}
81
88
virtual
const
std::string
getXMLTypeName
()
const
=0;
89
101
virtual
void
printDoc
(
102
std::string
const
& docString,
103
std::ostream &out
104
)
const
= 0;
105
114
virtual
ValidStringsList
validStringValues
()
const
= 0;
115
127
virtual
void
validate
(
128
ParameterEntry
const
& entry,
129
std::string
const
& paramName,
130
std::string
const
& sublistName
131
)
const
= 0;
132
146
virtual
void
validateAndModify
(
147
std::string
const
& paramName,
148
std::string
const
& sublistName,
149
ParameterEntry
* entry
150
)
const
151
{
152
TEUCHOS_TEST_FOR_EXCEPT
(0==entry);
153
this->
validate
(*entry,paramName,sublistName);
154
}
155
156
double
convertStringToDouble
(std::string str)
const
157
{
158
#ifdef HAVE_TEUCHOSCORE_CXX11
159
size_t
idx = 0;
160
double
result = std::stod(str, &idx);
// can throw std::invalid_argument
161
if
(idx != str.length()) {
// check for extra bad format characters
162
throw
std::invalid_argument(
"String: '"
+ str +
"' had bad formatting for converting to a double."
);
163
}
164
return
result;
165
#else
166
return
std::atof(str.c_str());
167
#endif
168
}
169
170
int
convertStringToInt
(std::string str)
const
171
{
172
#ifdef HAVE_TEUCHOSCORE_CXX11
173
size_t
idx = 0;
174
int
result = std::stoi(str, &idx);
// can throw std::invalid_argument
175
if
(idx != str.length()) {
// check for extra bad format characters
176
throw
std::invalid_argument(
"String: '"
+ str +
"' had bad formatting for converting to an int."
);
177
}
178
return
result;
179
#else
180
return
std::atoi(str.c_str());
181
#endif
182
}
183
184
int
convertStringToLongLong
(std::string str)
const
185
{
186
size_t
idx = 0;
187
long
long
result = std::stoll(str, &idx);
// can throw std::invalid_argument
188
if
(idx != str.length()) {
// check for extra bad format characters
189
throw
std::invalid_argument(
"String: '"
+ str +
"' had bad formatting for converting to a long long."
);
190
}
191
return
result;
192
}
193
194
};
195
196
197
}
// namespace Teuchos
198
199
200
#endif
// TEUCHOS_PARAMETER_ENTRY_VALIDATOR_H
Teuchos_Array.hpp
Templated array class derived from the STL std::vector.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
Definition
Teuchos_DLLExportMacro.h:29
Teuchos_Describable.hpp
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:76
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::convertStringToInt
int convertStringToInt(std::string str) const
Definition
Teuchos_ParameterEntryValidator.hpp:170
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:146
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:75
Teuchos::ParameterEntryValidator::convertStringToDouble
double convertStringToDouble(std::string str) const
Definition
Teuchos_ParameterEntryValidator.hpp:156
Teuchos::ParameterEntryValidator::ValidatorID
unsigned int ValidatorID
Definition
Teuchos_ParameterEntryValidator.hpp:72
Teuchos::ParameterEntryValidator::convertStringToLongLong
int convertStringToLongLong(std::string str) const
Definition
Teuchos_ParameterEntryValidator.hpp:184
Teuchos::ParameterEntryValidator::ParameterEntryValidator
ParameterEntryValidator()
Default Constructor.
Definition
Teuchos_ParameterEntryValidator.hpp:80
Teuchos::ParameterEntry
This object is held as the "value" in the Teuchos::ParameterList std::map.
Definition
Teuchos_ParameterEntry.hpp:67
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
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:317
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Generated by
1.17.0