Teuchos - Trilinos Tools Package  Version of the Day
Teuchos_StandardParameterEntryValidators.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 #include "Teuchos_StandardParameterEntryValidators.hpp"
43 #include "Teuchos_as.hpp"
44 
45 
46 std::string Teuchos::getVerbosityLevelParameterValueName(
47  const EVerbosityLevel verbLevel
48  )
49 {
50  switch (verbLevel) {
51  case VERB_DEFAULT:
52  return "default";
53  case VERB_NONE:
54  return "none";
55  case VERB_LOW:
56  return "low";
57  case VERB_MEDIUM:
58  return "medium";
59  case VERB_HIGH:
60  return "high";
61  case VERB_EXTREME:
62  return "extreme";
63  default:
65  true, std::invalid_argument, "Teuchos::getVerbosityLevelParameterValue"
66  "Name(const Teuchos::EVerbosityLevel): Input argument " << verbLevel <<
67  " has an invalid value. Valid values are VERB_DEFAULT=" << VERB_DEFAULT
68  << ", VERB_NONE=" << VERB_NONE << ", VERB_LOW=" << VERB_LOW << ", "
69  "VERB_MEDIUM=" << VERB_MEDIUM << ", VERB_HIGH=" << VERB_HIGH << ", AND "
70  "VERB_EXTREME=" << VERB_EXTREME << ".");
71  }
72 
73  // NOTE (mfh 15 Sep 2014): Most compilers have figured out that the
74  // return statement below is unreachable. Some older compilers
75  // might not realize this. That's why the return statement was put
76  // there, so that those compilers don't warn that this function
77  // doesn't return a value. If it's a choice between one warning and
78  // another, I would prefer the choice that produces less code and
79  // doesn't have unreachable code (which never gets tested).
80 
81  //return ""; // Never get here!
82 }
83 
84 
87  >
88 Teuchos::verbosityLevelParameterEntryValidator(
89  std::string const& defaultParameterName
90  )
91 {
92  return rcp(
93  new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
94  tuple<std::string>(
95  getVerbosityLevelParameterValueName(VERB_DEFAULT),
96  getVerbosityLevelParameterValueName(VERB_NONE),
97  getVerbosityLevelParameterValueName(VERB_LOW),
98  getVerbosityLevelParameterValueName(VERB_MEDIUM),
99  getVerbosityLevelParameterValueName(VERB_HIGH),
100  getVerbosityLevelParameterValueName(VERB_EXTREME)
101  ),
102  tuple<std::string>(
103  "Use level set in code",
104  "Produce no output",
105  "Produce minimal output",
106  "Produce a little more output",
107  "Produce a higher level of output",
108  "Produce the highest level of output"
109  ),
110  tuple<EVerbosityLevel>(
111  VERB_DEFAULT,
112  VERB_NONE,
113  VERB_LOW,
114  VERB_MEDIUM,
115  VERB_HIGH,
117  ),
118  defaultParameterName
119  )
120  );
121 }
122 
123 
124 namespace Teuchos {
125 
126 
127 //
128 // AnyNumberParameterEntryValidator
129 //
130 
131 
132 // Constructors
133 
134 
136  : preferredType_(PREFER_DOUBLE), acceptedTypes_(AcceptedTypes())
137 {
138  finishInitialization();
139 }
140 
141 
143  EPreferredType const preferredType, AcceptedTypes const& acceptedTypes
144  )
145  : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
146 {
147  finishInitialization();
148 }
149 
150 
151 // Local non-virtual validated lookup functions
152 
153 
155  const ParameterEntry &entry, const std::string &paramName,
156  const std::string &sublistName, const bool activeQuery
157  ) const
158 {
159  const any &anyValue = entry.getAny(activeQuery);
160  if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
161  return any_cast<int>(anyValue);
162  if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
163  return as<int>(any_cast<double>(anyValue));
164  if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
165  return std::atoi(any_cast<std::string>(anyValue).c_str());
166  throwTypeError(entry,paramName,sublistName);
167  return 0; // Will never get here!
168 }
169 
170 
172  const ParameterEntry &entry, const std::string &paramName,
173  const std::string &sublistName, const bool activeQuery
174  ) const
175 {
176  const any &anyValue = entry.getAny(activeQuery);
177  if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
178  return as<double>(any_cast<int>(anyValue));
179  if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
180  return any_cast<double>(anyValue);
181  if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
182  return std::atof(any_cast<std::string>(anyValue).c_str());
183  throwTypeError(entry,paramName,sublistName);
184  return 0.0; // Will never get here!
185 }
186 
187 
189  const ParameterEntry &entry, const std::string &paramName,
190  const std::string &sublistName, const bool activeQuery
191  ) const
192 {
193  const any &anyValue = entry.getAny(activeQuery);
194  if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
195  return Utils::toString(any_cast<int>(anyValue));
196  if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
197  return Utils::toString(any_cast<double>(anyValue));
198  if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
199  return any_cast<std::string>(anyValue);
200  throwTypeError(entry,paramName,sublistName);
201  return ""; // Will never get here!
202 }
203 
204 
206  ParameterList &paramList, const std::string &paramName,
207  const int defaultValue
208  ) const
209 {
210  const ParameterEntry *entry = paramList.getEntryPtr(paramName);
211  if(entry) return getInt(*entry,paramName,paramList.name(),true);
212  return paramList.get(paramName,defaultValue);
213 }
214 
215 
217  ParameterList &paramList, const std::string &paramName,
218  const double defaultValue
219  ) const
220 {
221  const ParameterEntry *entry = paramList.getEntryPtr(paramName);
222  if(entry) return getDouble(*entry,paramName,paramList.name(),true);
223  return paramList.get(paramName,defaultValue);
224 }
225 
226 
228  ParameterList &paramList, const std::string &paramName,
229  const std::string &defaultValue
230  ) const
231 {
232  const ParameterEntry *entry = paramList.getEntryPtr(paramName);
233  if(entry) return getString(*entry,paramName,paramList.name(),true);
234  return paramList.get(paramName,defaultValue);
235 }
236 
237 
239 {
240  return acceptedTypes_.allowDouble();
241 }
242 
243 
245 {
246  return acceptedTypes_.allowInt();
247 }
248 
249 
251 {
252  return acceptedTypes_.allowString();
253 }
254 
255 
258 {
259  return preferredType_;
260 }
261 
262 
263 // Overridden from ParameterEntryValidator
264 
265 
267 {
268  return "anynumberValidator";
269 }
270 
271 
273  std::string const & docString,
274  std::ostream & out
275  ) const
276 {
277  StrUtils::printLines(out,"# ",docString);
278  out << "# Accepted types: " << acceptedTypesString_ << ".\n";
279 }
280 
281 
284 {
285  return null;
286 }
287 
288 
290  ParameterEntry const& entry,
291  std::string const& paramName,
292  std::string const& sublistName
293  ) const
294 {
295  // Validate that the parameter exists and can be converted to a double.
296  // NOTE: Even if the target type will be an 'int', we don't know that here
297  // so it will be better to assert that a 'double' can be created. The type
298  // 'double' has a very large exponent range and, subject to digit
299  // truncation, a 'double' can represent every 'int' value.
300  getDouble(entry, paramName, sublistName, false);
301 }
302 
303 
305  std::string const& paramName,
306  std::string const& sublistName,
307  ParameterEntry * entry
308  ) const
309 {
310  TEUCHOS_TEST_FOR_EXCEPT(0==entry);
311  switch(preferredType_) {
312  case PREFER_INT:
313  entry->setValue(
314  getInt(*entry,paramName,sublistName,false),
315  false // isDefault
316  );
317  break;
318  case PREFER_DOUBLE:
319  entry->setValue(
320  getDouble(*entry,paramName,sublistName,false),
321  false // isDefault
322  );
323  break;
324  case PREFER_STRING:
325  entry->setValue(
326  getString(*entry,paramName,sublistName,false),
327  false // isDefault
328  );
329  break;
330  default:
331  TEUCHOS_TEST_FOR_EXCEPT("Error, Invalid EPreferredType value!");
332  }
333 }
334 
335 
336 // private
337 
338 
339 void AnyNumberParameterEntryValidator::finishInitialization()
340 {
341 
342  std::ostringstream oss;
343  bool addedType = false;
344  if(acceptedTypes_.allowInt()) {
345  oss << "\"int\"";
346  addedType = true;
347  }
348  if(acceptedTypes_.allowDouble()) {
349  if(addedType) oss << ", ";
350  oss << "\"double\"";
351  addedType = true;
352  }
353  if(acceptedTypes_.allowString()) {
354  if(addedType) oss << ", ";
355  oss << "\"string\"";
356  addedType = true;
357  }
358  acceptedTypesString_ = oss.str();
359 }
360 
361 
362 void AnyNumberParameterEntryValidator::throwTypeError(
363  ParameterEntry const& entry,
364  std::string const& paramName,
365  std::string const& sublistName
366  ) const
367 {
368  const std::string &entryName = entry.getAny(false).typeName();
371  ,"Error, the parameter {paramName=\""<<paramName<<"\""
372  ",type=\""<<entryName<<"\"}"
373  << "\nin the sublist \"" << sublistName << "\""
374  << "\nhas the wrong type."
375  << "\n\nThe accepted types are: " << acceptedTypesString_ << "!";
376  );
377 }
378 
379 
382 {
384  AnyNumberParameterEntryValidator::PREFER_INT,
386 }
387 
388 
390  : ParameterEntryValidator(), mustAlreadyExist_(mustAlreadyExist),
391  EmptyNameOK_(false)
392 {}
393 
394 
396 {
397  return mustAlreadyExist_;
398 }
399 
401 {
402  return EmptyNameOK_;
403 }
404 
405 bool FileNameValidator::setFileMustExist(bool shouldFileExist)
406 {
407  this->mustAlreadyExist_ = shouldFileExist;
408  return mustAlreadyExist_;
409 }
410 
412 {
413  this->EmptyNameOK_ = isEmptyNameOK;
414  return EmptyNameOK_;
415 }
416 
419 {
420  return null;
421 }
422 
423 
424 void FileNameValidator::validate(ParameterEntry const &entry, std::string const &paramName,
425  std::string const &sublistName) const
426 {
427  const std::string &entryName = entry.getAny(false).typeName();
428  any anyValue = entry.getAny(true);
429  TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string) ),
431  "The \"" << paramName << "\"" <<
432  " parameter in the \"" << sublistName <<
433  "\" sublist is has an error." << std::endl << std::endl <<
434  "Error: The value that you entered was the wrong type." << std::endl <<
435  "Parameter: " << paramName << std::endl <<
436  "Type specified: " << entryName << std::endl <<
437  "Type accepted: " << typeid(std::string).name() <<
438  std::endl << std::endl);
439  if(mustAlreadyExist_ && !EmptyNameOK_){
440  std::string fileName = getValue<std::string>(entry);
441  TEUCHOS_TEST_FOR_EXCEPTION(!std::ifstream(fileName.c_str()),
443  "The \"" << paramName << "\"" <<
444  " parameter in the \"" << sublistName <<
445  "\" sublist is has an error." << std::endl << std::endl <<
446  "Error: The file must already exists. The value you entered does " <<
447  "not corresspond to an existing file name." << std::endl <<
448  "Parameter: " << paramName << std::endl <<
449  "File name specified: " << fileName << std::endl << std::endl);
450  }
451 }
452 
453 
454 const std::string FileNameValidator::getXMLTypeName() const
455 {
456  return "FilenameValidator";
457 }
458 
459 
461  std::string const &docString, std::ostream &out) const
462 {
463  StrUtils::printLines(out,"# ",docString);
464  out << "# Validator Used: " << std::endl;
465  out << "# FileName Validator" << std::endl;
466 }
467 
468 
470  return rcp(new FileNameValidator(true));
471 }
472 
473 
475  : ParameterEntryValidator(), validStrings_(NULL)
476 {}
477 
478 
481  validStrings_(rcp(new Array<std::string>(validStrings)))
482 {}
483 
484 
487 {
488  validStrings_ = rcp(new Array<std::string>(validStrings));
489  return validStrings_;
490 }
491 
492 
495 {
496  return validStrings_;
497 }
498 
499 
501  ParameterEntry const &entry, std::string const &paramName,
502  std::string const &sublistName) const
503 {
504  any anyValue = entry.getAny(true);
505  const std::string &entryName = entry.getAny(false).typeName();
506  TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string)) ,
508  "The \"" << paramName << "\"" <<
509  " parameter in the \"" << sublistName <<
510  "\" sublist is has an error." << std::endl << std::endl <<
511  "Error: The value that you entered was the wrong type." <<
512  "Parameter: " << paramName << std::endl <<
513  "Type specified: " << entryName << std::endl <<
514  "Type accepted: " << Teuchos::TypeNameTraits<std::string>::name() <<
515  std::endl);
516  if(!validStrings_.is_null()){
518  it = std::find(validStrings_->begin(),
519  validStrings_->end(), getValue<std::string>(entry));
520  TEUCHOS_TEST_FOR_EXCEPTION(it == validStrings_->end(),
522  "The \"" << paramName << "\"" <<
523  " parameter in the \"" << sublistName <<
524  "\" sublist is has an error." << std::endl << std::endl <<
525  "Error: The value that was entered doesn't fall with in "
526  "the range set by the validator." <<
527  "Parameter: " << paramName << std::endl <<
528  "Acceptable Values: " << *validStrings_ << std::endl <<
529  "Value entered: " << getValue<std::string>(entry) << std::endl <<
530  std::endl);
531  }
532 }
533 
534 
535 const std::string StringValidator::getXMLTypeName() const
536 {
537  return "StringValidator";
538 }
539 
540 
541 void StringValidator::printDoc(std::string const &docString,
542  std::ostream &out) const
543 {
544  Teuchos::StrUtils::printLines(out,"# ",docString);
545  out << "# Validator Used: " << std::endl;
546  out << "# String Validator" << std::endl;
547  if (validStrings_.get() && validStrings_->size()){
548  out << "# Acceptable Values: " << *validStrings_ << std::endl;
549  }
550 }
551 
552 
554  return rcp(new StringValidator(tuple<std::string>("")));
555 }
556 
557 
558 } // namespace Teuchos
559 
560 
561 // Nonmmeber helper functions
562 
563 
565 Teuchos::anyNumberParameterEntryValidator()
566 {
568 }
569 
570 
572 Teuchos::anyNumberParameterEntryValidator(
575  )
576 {
577  return rcp(
579  preferredType, acceptedTypes
580  )
581  );
582 }
583 
584 void Teuchos::setIntParameter(
585  std::string const& paramName,
586  int const value, std::string const& docString,
587  ParameterList *paramList,
589  )
590 {
591  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
592  const RCP<const ParameterEntryValidator> paramEntryValidator =
593  anyNumberParameterEntryValidator(
594  AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
595  );
596  paramList->set(paramName, value, docString, paramEntryValidator);
597 }
598 
599 
600 void Teuchos::setDoubleParameter(
601  std::string const& paramName,
602  double const& value, std::string const& docString,
603  ParameterList *paramList,
605  )
606 {
607  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
608  const RCP<const ParameterEntryValidator> paramEntryValidator =
609  anyNumberParameterEntryValidator(
610  AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
611  );
612  paramList->set(paramName, value, docString, paramEntryValidator);
613 }
614 
615 
616 void Teuchos::setNumericStringParameter(
617  std::string const& paramName,
618  std::string const& value, std::string const& docString,
619  ParameterList *paramList,
621  )
622 {
623  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
624  const RCP<const ParameterEntryValidator> paramEntryValidator =
625  anyNumberParameterEntryValidator(
626  AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
627  );
628  paramList->set(paramName, value, docString, paramEntryValidator);
629 }
630 
631 
632 int Teuchos::getIntParameter(
633  ParameterList const& paramList,
634  std::string const& paramName
635  )
636 {
637  const ParameterEntry &entry = paramList.getEntry(paramName);
639  anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
640  entry.validator()
641  );
642  if ( !is_null(anyNumValidator) )
643  return anyNumValidator->getInt(entry,paramName,paramList.name());
644  if ( typeid(int) == entry.getAny().type() )
645  return any_cast<int>(entry.getAny());
646  // Try the do the conversion which might fail!
647  const AnyNumberParameterEntryValidator myAnyNumValidator;
648  return myAnyNumValidator.getInt(entry,paramName,paramList.name());
649 }
650 
651 
652 double Teuchos::getDoubleParameter(
653  ParameterList const& paramList,
654  std::string const& paramName
655  )
656 {
657  const ParameterEntry &entry = paramList.getEntry(paramName);
659  anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
660  entry.validator()
661  );
662  if ( !is_null(anyNumValidator) )
663  return anyNumValidator->getDouble(entry,paramName,paramList.name());
664  if ( typeid(double) == entry.getAny().type() )
665  return any_cast<double>(entry.getAny());
666  // Try the do the conversion which might fail!
667  const AnyNumberParameterEntryValidator myAnyNumValidator;
668  return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
669 }
670 
671 
672 std::string Teuchos::getNumericStringParameter(
673  ParameterList const& paramList,
674  std::string const& paramName
675  )
676 {
677  const ParameterEntry &entry = paramList.getEntry(paramName);
679  anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
680  entry.validator()
681  );
682  if ( !is_null(anyNumValidator) )
683  return anyNumValidator->getString(entry,paramName,paramList.name());
684  if ( typeid(std::string) == entry.getAny().type() )
685  return any_cast<std::string>(entry.getAny());
686  // Try the do the conversion which might fail!
687  const AnyNumberParameterEntryValidator myAnyNumValidator;
688  return myAnyNumValidator.getString(entry,paramName,paramList.name());
689 }
ValidStringsList setValidStrings(const Teuchos::Array< std::string > &validStrings)
Sets the Array of valid strings and returns what the current array of valid string now is...
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
void printDoc(std::string const &docString, std::ostream &out) const
const std::string & name() const
The name of this ParameterList.
Generate output as defined by the object.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
bool setFileMustExist(bool shouldFileExist)
Sets whether or not the validator requires the file to already exist.
void setValue(T value, bool isDefault=false, const std::string &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method that uses the input value type to determine the type of parameter.
FileNameValidator(bool mustAlreadyExist=mustAlreadyExistDefault())
Constructs a FileNameValidator.
Generate only a minimal amount of output.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
Generate no output.
EPreferredType
Determines what type is the preferred type.
T & get(const std::string &name, T def_value)
Return the parameter&#39;s value, or the default value if it is not there.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
This object is held as the "value" in the Teuchos::ParameterList std::map.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool fileEmptyNameOK() const
Gets the variable describing whether or not this validator is OK with file name being empty (even if ...
Generate the most output possible.
Standard implementation of a ParameterEntryValidator that maps from a list of strings to an enum or i...
AcceptedTypes & allowString(bool _allowString)
Set allow an std::string value or not.
std::string getString(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a std::string value from a parameter entry.
T * get() const
Get the raw C++ pointer to the underlying object.
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
EVerbosityLevel
Verbosity level.
Modified boost::any class, which is a container for a templated value.
Definition: Teuchos_any.hpp:86
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
AcceptedTypes & allowInt(bool _allowInt)
Set allow an int value or not.
static std::string toString(const double &x)
Write a double as a std::string.
Generate more output.
ParameterEntry * getEntryPtr(const std::string &name)
Retrieves the pointer for an entry with the name name if it exists.
EPreferredType getPreferredType() const
Lookup the preferred type.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Generate a high level of output.
double getDouble(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a double value from a parameter entry.
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
bool setFileEmptyNameOK(bool isEmptyNameOK)
Sets whether or not the validator is OK with empty file name (even if fileMustExist() returns true) ...
A list of parameters of arbitrary type.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT RCP< AnyNumberParameterEntryValidator > anyNumberParameterEntryValidator()
Nonmember constructor AnyNumberParameterEntryValidator.
AnyNumberParameterEntryValidator()
Construct with a preferrded type of double and accept all types.
Abstract interface for an object that can validate a ParameterEntry&#39;s value.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
int getInt(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get an integer value from a parameter entry.
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
bool isDoubleAllowed() const
Lookup whether or not Doubles are allowed.
void printDoc(std::string const &docString, std::ostream &out) const
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
std::string typeName() const
Return the name of the type.
AcceptedTypes & allowDouble(bool _allowDouble)
Set allow a double value or not.
Smart reference counting pointer class for automatic garbage collection.
bool fileMustExist() const
Gets the variable describing whether or not this validator wants the file that is specified to alread...
const std::type_info & type() const
Return the type of value being stored.
void validateAndModify(std::string const &paramName, std::string const &sublistName, ParameterEntry *entry) const
bool isStringAllowed() const
Lookup whether or not strings are allowed.
Standard implementation of a ParameterEntryValidator that accepts numbers from a number of different ...
void printDoc(std::string const &docString, std::ostream &out) const
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
bool isIntAllowed() const
Lookup whether or not ints are allowed.
Definition of Teuchos::as, for conversions between types.
#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...
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool is_null() const
Returns true if the underlying pointer is null.