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 // BoolParameterEntryValidator
129 //
130 
131 
132 // Constructors
133 
134 
135 BoolParameterEntryValidator::BoolParameterEntryValidator()
136 {
137  finishInitialization();
138 }
139 
140 
141 // Local non-virtual validated lookup functions
142 
143 
145  const ParameterEntry &entry, const std::string &paramName,
146  const std::string &sublistName, const bool activeQuery
147  ) const
148 {
149  const any &anyValue = entry.getAny(activeQuery);
150  if( anyValue.type() == typeid(bool) )
151  return any_cast<bool>(anyValue);
152  if( anyValue.type() == typeid(std::string) ) {
153  std::string str = any_cast<std::string>(anyValue);
154 
155  // to fix - do we want to make this customizable?
156  if( str == "false" ) {
157  return false;
158  }
159  else if( str == "true" ) {
160  return true;
161  }
162 
163  }
164  throwTypeError(entry,paramName,sublistName);
165  return 0; // Will never get here!
166 }
167 
169  ParameterList &paramList, const std::string &paramName,
170  const int defaultValue
171  ) const
172 {
173  const ParameterEntry *entry = paramList.getEntryPtr(paramName);
174  if(entry) return getBool(*entry,paramName,paramList.name(),true);
175  return paramList.get(paramName,defaultValue);
176 }
177 
178 // Overridden from ParameterEntryValidator
179 
181 {
182  return "boolValidator";
183 }
184 
186  std::string const & docString,
187  std::ostream & out
188  ) const
189 {
190  StrUtils::printLines(out,"# ",docString);
191  out << "# Accepted types: " << acceptedTypesString_ << ".\n";
192 }
193 
194 
197 {
198  return null;
199 }
200 
201 
203  ParameterEntry const& entry,
204  std::string const& paramName,
205  std::string const& sublistName
206  ) const
207 {
208  // Validate that the parameter exists and can be converted to a bool.
209  getBool(entry, paramName, sublistName, false);
210 }
211 
212 
214  std::string const& paramName,
215  std::string const& sublistName,
216  ParameterEntry * entry
217  ) const
218 {
219  TEUCHOS_TEST_FOR_EXCEPT(0==entry);
220  entry->setValue(getBool(*entry,paramName,sublistName,false), false);
221 }
222 
223 
224 // private
225 
226 
227 void BoolParameterEntryValidator::finishInitialization()
228 {
229  std::ostringstream oss;
230  oss << "\"bool\"";
231  acceptedTypesString_ = oss.str();
232  oss << "\"string\"";
233  acceptedTypesString_ = oss.str();
234 }
235 
236 
237 void BoolParameterEntryValidator::throwTypeError(
238  ParameterEntry const& entry,
239  std::string const& paramName,
240  std::string const& sublistName
241  ) const
242 {
243  const std::string &entryName = entry.getAny(false).typeName();
246  ,"Error, the parameter {paramName=\""<<paramName<<"\""
247  ",type=\""<<entryName<<"\"}"
248  << "\nin the sublist \"" << sublistName << "\""
249  << "\nhas the wrong type."
250  << "\n\nThe accepted types are: " << acceptedTypesString_ << "!";
251  );
252 }
253 
254 //
255 // AnyNumberParameterEntryValidator
256 //
257 
258 
259 // Constructors
260 
261 
263  : preferredType_(PREFER_DOUBLE), acceptedTypes_(AcceptedTypes())
264 {
265  finishInitialization();
266 }
267 
268 
270  EPreferredType const preferredType, AcceptedTypes const& acceptedTypes
271  )
272  : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
273 {
274  finishInitialization();
275 }
276 
277 
278 // Local non-virtual validated lookup functions
279 
280 
282  const ParameterEntry &entry, const std::string &paramName,
283  const std::string &sublistName, const bool activeQuery
284  ) const
285 {
286  const any &anyValue = entry.getAny(activeQuery);
287  if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
288  return any_cast<int>(anyValue);
289  if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
290  return as<int>(any_cast<double>(anyValue));
291  if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
292  return convertStringToInt(any_cast<std::string>(anyValue));
293  throwTypeError(entry,paramName,sublistName);
294  return 0; // Will never get here!
295 }
296 
298  const ParameterEntry &entry, const std::string &paramName,
299  const std::string &sublistName, const bool activeQuery
300  ) const
301 {
302  const any &anyValue = entry.getAny(activeQuery);
303  if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
304  return as<double>(any_cast<int>(anyValue));
305  if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
306  return any_cast<double>(anyValue);
307  if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
308  return convertStringToDouble(any_cast<std::string>(anyValue));
309  throwTypeError(entry,paramName,sublistName);
310  return 0.0; // Will never get here!
311 }
312 
313 
315  const ParameterEntry &entry, const std::string &paramName,
316  const std::string &sublistName, const bool activeQuery
317  ) const
318 {
319  const any &anyValue = entry.getAny(activeQuery);
320  if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
321  return Utils::toString(any_cast<int>(anyValue));
322  if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
323  return Utils::toString(any_cast<double>(anyValue));
324  if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
325  return any_cast<std::string>(anyValue);
326  throwTypeError(entry,paramName,sublistName);
327  return ""; // Will never get here!
328 }
329 
330 
332  ParameterList &paramList, const std::string &paramName,
333  const int defaultValue
334  ) const
335 {
336  const ParameterEntry *entry = paramList.getEntryPtr(paramName);
337  if(entry) return getInt(*entry,paramName,paramList.name(),true);
338  return paramList.get(paramName,defaultValue);
339 }
340 
341 
343  ParameterList &paramList, const std::string &paramName,
344  const double defaultValue
345  ) const
346 {
347  const ParameterEntry *entry = paramList.getEntryPtr(paramName);
348  if(entry) return getDouble(*entry,paramName,paramList.name(),true);
349  return paramList.get(paramName,defaultValue);
350 }
351 
352 
354  ParameterList &paramList, const std::string &paramName,
355  const std::string &defaultValue
356  ) const
357 {
358  const ParameterEntry *entry = paramList.getEntryPtr(paramName);
359  if(entry) return getString(*entry,paramName,paramList.name(),true);
360  return paramList.get(paramName,defaultValue);
361 }
362 
363 
365 {
366  return acceptedTypes_.allowDouble();
367 }
368 
369 
371 {
372  return acceptedTypes_.allowInt();
373 }
374 
375 
377 {
378  return acceptedTypes_.allowString();
379 }
380 
381 
384 {
385  return preferredType_;
386 }
387 
388 
389 // Overridden from ParameterEntryValidator
390 
391 
393 {
394  return "anynumberValidator";
395 }
396 
397 
399  std::string const & docString,
400  std::ostream & out
401  ) const
402 {
403  StrUtils::printLines(out,"# ",docString);
404  out << "# Accepted types: " << acceptedTypesString_ << ".\n";
405 }
406 
407 
410 {
411  return null;
412 }
413 
414 
416  ParameterEntry const& entry,
417  std::string const& paramName,
418  std::string const& sublistName
419  ) const
420 {
421  // Validate that the parameter exists and can be converted to a double.
422  // NOTE: Even if the target type will be an 'int', we don't know that here
423  // so it will be better to assert that a 'double' can be created. The type
424  // 'double' has a very large exponent range and, subject to digit
425  // truncation, a 'double' can represent every 'int' value.
426  getDouble(entry, paramName, sublistName, false);
427 }
428 
429 
431  std::string const& paramName,
432  std::string const& sublistName,
433  ParameterEntry * entry
434  ) const
435 {
436  TEUCHOS_TEST_FOR_EXCEPT(0==entry);
437  switch(preferredType_) {
438  case PREFER_INT:
439  entry->setValue(
440  getInt(*entry,paramName,sublistName,false),
441  false // isDefault
442  );
443  break;
444  case PREFER_DOUBLE:
445  entry->setValue(
446  getDouble(*entry,paramName,sublistName,false),
447  false // isDefault
448  );
449  break;
450  case PREFER_STRING:
451  entry->setValue(
452  getString(*entry,paramName,sublistName,false),
453  false // isDefault
454  );
455  break;
456  default:
457  TEUCHOS_TEST_FOR_EXCEPT("Error, Invalid EPreferredType value!");
458  }
459 }
460 
461 
462 // private
463 
464 
465 void AnyNumberParameterEntryValidator::finishInitialization()
466 {
467 
468  std::ostringstream oss;
469  bool addedType = false;
470  if(acceptedTypes_.allowInt()) {
471  oss << "\"int\"";
472  addedType = true;
473  }
474  if(acceptedTypes_.allowDouble()) {
475  if(addedType) oss << ", ";
476  oss << "\"double\"";
477  addedType = true;
478  }
479  if(acceptedTypes_.allowString()) {
480  if(addedType) oss << ", ";
481  oss << "\"string\"";
482  addedType = true;
483  }
484  acceptedTypesString_ = oss.str();
485 }
486 
487 
488 void AnyNumberParameterEntryValidator::throwTypeError(
489  ParameterEntry const& entry,
490  std::string const& paramName,
491  std::string const& sublistName
492  ) const
493 {
494  const std::string &entryName = entry.getAny(false).typeName();
497  ,"Error, the parameter {paramName=\""<<paramName<<"\""
498  ",type=\""<<entryName<<"\"}"
499  << "\nin the sublist \"" << sublistName << "\""
500  << "\nhas the wrong type."
501  << "\n\nThe accepted types are: " << acceptedTypesString_ << "!";
502  );
503 }
504 
505 
508 {
510  AnyNumberParameterEntryValidator::PREFER_INT,
512 }
513 
514 
516  : ParameterEntryValidator(), mustAlreadyExist_(mustAlreadyExist),
517  EmptyNameOK_(false)
518 {}
519 
520 
522 {
523  return mustAlreadyExist_;
524 }
525 
527 {
528  return EmptyNameOK_;
529 }
530 
531 bool FileNameValidator::setFileMustExist(bool shouldFileExist)
532 {
533  this->mustAlreadyExist_ = shouldFileExist;
534  return mustAlreadyExist_;
535 }
536 
538 {
539  this->EmptyNameOK_ = isEmptyNameOK;
540  return EmptyNameOK_;
541 }
542 
545 {
546  return null;
547 }
548 
549 
550 void FileNameValidator::validate(ParameterEntry const &entry, std::string const &paramName,
551  std::string const &sublistName) const
552 {
553  const std::string &entryName = entry.getAny(false).typeName();
554  any anyValue = entry.getAny(true);
555  TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string) ),
557  "The \"" << paramName << "\"" <<
558  " parameter in the \"" << sublistName <<
559  "\" sublist is has an error." << std::endl << std::endl <<
560  "Error: The value that you entered was the wrong type." << std::endl <<
561  "Parameter: " << paramName << std::endl <<
562  "Type specified: " << entryName << std::endl <<
563  "Type accepted: " << typeid(std::string).name() <<
564  std::endl << std::endl);
565  if(mustAlreadyExist_ && !EmptyNameOK_){
566  std::string fileName = getValue<std::string>(entry);
567  TEUCHOS_TEST_FOR_EXCEPTION(!std::ifstream(fileName.c_str()),
569  "The \"" << paramName << "\"" <<
570  " parameter in the \"" << sublistName <<
571  "\" sublist is has an error." << std::endl << std::endl <<
572  "Error: The file must already exists. The value you entered does " <<
573  "not corresspond to an existing file name." << std::endl <<
574  "Parameter: " << paramName << std::endl <<
575  "File name specified: " << fileName << std::endl << std::endl);
576  }
577 }
578 
579 
580 const std::string FileNameValidator::getXMLTypeName() const
581 {
582  return "FilenameValidator";
583 }
584 
585 
587  std::string const &docString, std::ostream &out) const
588 {
589  StrUtils::printLines(out,"# ",docString);
590  out << "# Validator Used: " << std::endl;
591  out << "# FileName Validator" << std::endl;
592 }
593 
594 
596  return rcp(new FileNameValidator(true));
597 }
598 
599 
601  : ParameterEntryValidator(), validStrings_(NULL)
602 {}
603 
604 
607  validStrings_(rcp(new Array<std::string>(validStrings)))
608 {}
609 
610 
613 {
614  validStrings_ = rcp(new Array<std::string>(validStrings));
615  return validStrings_;
616 }
617 
618 
621 {
622  return validStrings_;
623 }
624 
625 
627  ParameterEntry const &entry, std::string const &paramName,
628  std::string const &sublistName) const
629 {
630  any anyValue = entry.getAny(true);
631  const std::string &entryName = entry.getAny(false).typeName();
632  TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string)) ,
634  "The \"" << paramName << "\"" <<
635  " parameter in the \"" << sublistName <<
636  "\" sublist is has an error." << std::endl << std::endl <<
637  "Error: The value that you entered was the wrong type." <<
638  "Parameter: " << paramName << std::endl <<
639  "Type specified: " << entryName << std::endl <<
640  "Type accepted: " << Teuchos::TypeNameTraits<std::string>::name() <<
641  std::endl);
642  if(!validStrings_.is_null()){
644  it = std::find(validStrings_->begin(),
645  validStrings_->end(), getValue<std::string>(entry));
646  TEUCHOS_TEST_FOR_EXCEPTION(it == validStrings_->end(),
648  "The \"" << paramName << "\"" <<
649  " parameter in the \"" << sublistName <<
650  "\" sublist is has an error." << std::endl << std::endl <<
651  "Error: The value that was entered doesn't fall with in "
652  "the range set by the validator." <<
653  "Parameter: " << paramName << std::endl <<
654  "Acceptable Values: " << *validStrings_ << std::endl <<
655  "Value entered: " << getValue<std::string>(entry) << std::endl <<
656  std::endl);
657  }
658 }
659 
660 
661 const std::string StringValidator::getXMLTypeName() const
662 {
663  return "StringValidator";
664 }
665 
666 
667 void StringValidator::printDoc(std::string const &docString,
668  std::ostream &out) const
669 {
670  Teuchos::StrUtils::printLines(out,"# ",docString);
671  out << "# Validator Used: " << std::endl;
672  out << "# String Validator" << std::endl;
673  if (validStrings_.get() && validStrings_->size()){
674  out << "# Acceptable Values: " << *validStrings_ << std::endl;
675  }
676 }
677 
678 
680  return rcp(new StringValidator(tuple<std::string>("")));
681 }
682 
683 
684 } // namespace Teuchos
685 
686 
687 // Nonmmeber helper functions
688 
690 Teuchos::boolParameterEntryValidator()
691 {
692  return rcp(new BoolParameterEntryValidator());
693 }
694 
696 Teuchos::anyNumberParameterEntryValidator()
697 {
699 }
700 
701 
703 Teuchos::anyNumberParameterEntryValidator(
706  )
707 {
708  return rcp(
710  preferredType, acceptedTypes
711  )
712  );
713 }
714 
715 void Teuchos::setIntParameter(
716  std::string const& paramName,
717  int const value, std::string const& docString,
718  ParameterList *paramList,
720  )
721 {
722  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
723  const RCP<const ParameterEntryValidator> paramEntryValidator =
724  anyNumberParameterEntryValidator(
725  AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
726  );
727  paramList->set(paramName, value, docString, paramEntryValidator);
728 }
729 
730 
731 void Teuchos::setDoubleParameter(
732  std::string const& paramName,
733  double const& value, std::string const& docString,
734  ParameterList *paramList,
736  )
737 {
738  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
739  const RCP<const ParameterEntryValidator> paramEntryValidator =
740  anyNumberParameterEntryValidator(
741  AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
742  );
743  paramList->set(paramName, value, docString, paramEntryValidator);
744 }
745 
746 
747 void Teuchos::setNumericStringParameter(
748  std::string const& paramName,
749  std::string const& value, std::string const& docString,
750  ParameterList *paramList,
752  )
753 {
754  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
755  const RCP<const ParameterEntryValidator> paramEntryValidator =
756  anyNumberParameterEntryValidator(
757  AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
758  );
759  paramList->set(paramName, value, docString, paramEntryValidator);
760 }
761 
762 
763 int Teuchos::getIntParameter(
764  ParameterList const& paramList,
765  std::string const& paramName
766  )
767 {
768  const ParameterEntry &entry = paramList.getEntry(paramName);
770  anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
771  entry.validator()
772  );
773  if ( !is_null(anyNumValidator) )
774  return anyNumValidator->getInt(entry,paramName,paramList.name());
775  if ( typeid(int) == entry.getAny().type() )
776  return any_cast<int>(entry.getAny());
777  // Try the do the conversion which might fail!
778  const AnyNumberParameterEntryValidator myAnyNumValidator;
779  return myAnyNumValidator.getInt(entry,paramName,paramList.name());
780 }
781 
782 
783 double Teuchos::getDoubleParameter(
784  ParameterList const& paramList,
785  std::string const& paramName
786  )
787 {
788  const ParameterEntry &entry = paramList.getEntry(paramName);
790  anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
791  entry.validator()
792  );
793  if ( !is_null(anyNumValidator) )
794  return anyNumValidator->getDouble(entry,paramName,paramList.name());
795  if ( typeid(double) == entry.getAny().type() )
796  return any_cast<double>(entry.getAny());
797  // Try the do the conversion which might fail!
798  const AnyNumberParameterEntryValidator myAnyNumValidator;
799  return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
800 }
801 
802 
803 std::string Teuchos::getNumericStringParameter(
804  ParameterList const& paramList,
805  std::string const& paramName
806  )
807 {
808  const ParameterEntry &entry = paramList.getEntry(paramName);
810  anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
811  entry.validator()
812  );
813  if ( !is_null(anyNumValidator) )
814  return anyNumValidator->getString(entry,paramName,paramList.name());
815  if ( typeid(std::string) == entry.getAny().type() )
816  return any_cast<std::string>(entry.getAny());
817  // Try the do the conversion which might fail!
818  const AnyNumberParameterEntryValidator myAnyNumValidator;
819  return myAnyNumValidator.getString(entry,paramName,paramList.name());
820 }
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.
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
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.
void validateAndModify(std::string const &paramName, std::string const &sublistName, ParameterEntry *entry) const
void printDoc(std::string const &docString, std::ostream &out) const
#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
Standard implementation of a BoolParameterEntryValidator that accepts bool values (true/false) or str...
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.
bool getBool(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get bool value from a parameter entry.
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. HAVE_TEUCHOSCORE_CXX11 will call std::stoi otherwise we ...
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.