Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardParameterEntryValidators.cpp
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#include "Teuchos_StandardParameterEntryValidators.hpp"
11#include "Teuchos_as.hpp"
12#include <fstream>
13
15 const EVerbosityLevel verbLevel
16 )
17{
18 switch (verbLevel) {
19 case VERB_DEFAULT:
20 return "default";
21 case VERB_NONE:
22 return "none";
23 case VERB_LOW:
24 return "low";
25 case VERB_MEDIUM:
26 return "medium";
27 case VERB_HIGH:
28 return "high";
29 case VERB_EXTREME:
30 return "extreme";
31 default:
33 true, std::invalid_argument, "Teuchos::getVerbosityLevelParameterValue"
34 "Name(const Teuchos::EVerbosityLevel): Input argument " << verbLevel <<
35 " has an invalid value. Valid values are VERB_DEFAULT=" << VERB_DEFAULT
36 << ", VERB_NONE=" << VERB_NONE << ", VERB_LOW=" << VERB_LOW << ", "
37 "VERB_MEDIUM=" << VERB_MEDIUM << ", VERB_HIGH=" << VERB_HIGH << ", AND "
38 "VERB_EXTREME=" << VERB_EXTREME << ".");
39 }
40
41 // NOTE (mfh 15 Sep 2014): Most compilers have figured out that the
42 // return statement below is unreachable. Some older compilers
43 // might not realize this. That's why the return statement was put
44 // there, so that those compilers don't warn that this function
45 // doesn't return a value. If it's a choice between one warning and
46 // another, I would prefer the choice that produces less code and
47 // doesn't have unreachable code (which never gets tested).
48
49 //return ""; // Never get here!
50}
51
52
55 >
57 std::string const& defaultParameterName
58 )
59{
60 return rcp(
61 new StringToIntegralParameterEntryValidator<EVerbosityLevel>(
62 tuple<std::string>(
63 getVerbosityLevelParameterValueName(VERB_DEFAULT),
64 getVerbosityLevelParameterValueName(VERB_NONE),
65 getVerbosityLevelParameterValueName(VERB_LOW),
66 getVerbosityLevelParameterValueName(VERB_MEDIUM),
67 getVerbosityLevelParameterValueName(VERB_HIGH),
68 getVerbosityLevelParameterValueName(VERB_EXTREME)
69 ),
70 tuple<std::string>(
71 "Use level set in code",
72 "Produce no output",
73 "Produce minimal output",
74 "Produce a little more output",
75 "Produce a higher level of output",
76 "Produce the highest level of output"
77 ),
78 tuple<EVerbosityLevel>(
79 VERB_DEFAULT,
80 VERB_NONE,
81 VERB_LOW,
82 VERB_MEDIUM,
83 VERB_HIGH,
84 VERB_EXTREME
85 ),
86 defaultParameterName
87 )
88 );
89}
90
91
92namespace Teuchos {
93
94
95//
96// BoolParameterEntryValidator
97//
98
99
100// Constructors
101
102
103BoolParameterEntryValidator::BoolParameterEntryValidator()
104{
105 finishInitialization();
106}
107
108
109// Local non-virtual validated lookup functions
110
111
113 const ParameterEntry &entry, const std::string &paramName,
114 const std::string &sublistName, const bool activeQuery
115 ) const
116{
117 const any &anyValue = entry.getAny(activeQuery);
118 if( anyValue.type() == typeid(bool) )
119 return any_cast<bool>(anyValue);
120 if( anyValue.type() == typeid(std::string) ) {
121 std::string str = any_cast<std::string>(anyValue);
122
123 // to fix - do we want to make this customizable?
124 if( str == "false" ) {
125 return false;
126 }
127 else if( str == "true" ) {
128 return true;
129 }
130
131 }
132 throwTypeError(entry,paramName,sublistName);
133 return 0; // Will never get here!
134}
135
137 ParameterList &paramList, const std::string &paramName,
138 const int defaultValue
139 ) const
140{
141 const ParameterEntry *entry = paramList.getEntryPtr(paramName);
142 if(entry) return getBool(*entry,paramName,paramList.name(),true);
144}
145
146// Overridden from ParameterEntryValidator
147
149{
150 return "boolValidator";
151}
152
154 std::string const & docString,
155 std::ostream & out
156 ) const
157{
158 StrUtils::printLines(out,"# ",docString);
159 out << "# Accepted types: " << acceptedTypesString_ << ".\n";
160}
161
162
165{
166 return null;
167}
168
169
171 ParameterEntry const& entry,
172 std::string const& paramName,
173 std::string const& sublistName
174 ) const
175{
176 // Validate that the parameter exists and can be converted to a bool.
177 getBool(entry, paramName, sublistName, false);
178}
179
180
182 std::string const& paramName,
183 std::string const& sublistName,
184 ParameterEntry * entry
185 ) const
186{
187 TEUCHOS_TEST_FOR_EXCEPT(0==entry);
188 entry->setValue(getBool(*entry,paramName,sublistName,false), false);
189}
190
191
192// private
193
194
195void BoolParameterEntryValidator::finishInitialization()
196{
197 std::ostringstream oss;
198 oss << "\"bool\"";
199 acceptedTypesString_ = oss.str();
200 oss << "\"string\"";
201 acceptedTypesString_ = oss.str();
202}
203
204
205void BoolParameterEntryValidator::throwTypeError(
206 ParameterEntry const& entry,
207 std::string const& paramName,
208 std::string const& sublistName
209 ) const
210{
211 const std::string &entryName = entry.getAny(false).typeName();
213 true, Exceptions::InvalidParameterType
214 ,"Error, the parameter {paramName=\""<<paramName<<"\""
215 ",type=\""<<entryName<<"\"}"
216 << "\nin the sublist \"" << sublistName << "\""
217 << "\nhas the wrong type."
218 << "\n\nThe accepted types are: " << acceptedTypesString_ << "!";
219 );
220}
221
222//
223// AnyNumberParameterEntryValidator
224//
225
226
227// Constructors
228
229
231 : preferredType_(PREFER_DOUBLE), acceptedTypes_(AcceptedTypes())
232{
233 finishInitialization();
234}
235
236
239 )
240 : preferredType_(preferredType), acceptedTypes_(acceptedTypes)
241{
242 finishInitialization();
243}
244
245
246// Local non-virtual validated lookup functions
247
248
250 const ParameterEntry &entry, const std::string &paramName,
251 const std::string &sublistName, const bool activeQuery
252 ) const
253{
254 const any &anyValue = entry.getAny(activeQuery);
255 if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
256 return any_cast<int>(anyValue);
257 if( acceptedTypes_.allowLongLong() && anyValue.type() == typeid(long long) )
259 if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
261 if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
262 return convertStringToInt(any_cast<std::string>(anyValue));
263 throwTypeError(entry,paramName,sublistName);
264 return 0; // Will never get here!
265}
266
268 const ParameterEntry &entry, const std::string &paramName,
269 const std::string &sublistName, const bool activeQuery
270 ) const
271{
272 const any &anyValue = entry.getAny(activeQuery);
273 if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
275 if( acceptedTypes_.allowLongLong() && anyValue.type() == typeid(long long) )
277 if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
279 if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
280 return convertStringToLongLong(any_cast<std::string>(anyValue));
281 throwTypeError(entry,paramName,sublistName);
282 return 0; // Will never get here!
283}
284
286 const ParameterEntry &entry, const std::string &paramName,
287 const std::string &sublistName, const bool activeQuery
288 ) const
289{
290 const any &anyValue = entry.getAny(activeQuery);
291 if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
293 if( acceptedTypes_.allowLongLong() && anyValue.type() == typeid(long long) )
295 if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
297 if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
298 return convertStringToDouble(any_cast<std::string>(anyValue));
299 throwTypeError(entry,paramName,sublistName);
300 return 0.0; // Will never get here!
301}
302
303
305 const ParameterEntry &entry, const std::string &paramName,
306 const std::string &sublistName, const bool activeQuery
307 ) const
308{
309 const any &anyValue = entry.getAny(activeQuery);
310 if( acceptedTypes_.allowInt() && anyValue.type() == typeid(int) )
312 if( acceptedTypes_.allowLongLong() && anyValue.type() == typeid(long long) )
314 if( acceptedTypes_.allowDouble() && anyValue.type() == typeid(double) )
316 if( acceptedTypes_.allowString() && anyValue.type() == typeid(std::string) )
318 throwTypeError(entry,paramName,sublistName);
319 return ""; // Will never get here!
320}
321
322
324 ParameterList &paramList, const std::string &paramName,
325 const int defaultValue
326 ) const
327{
328 const ParameterEntry *entry = paramList.getEntryPtr(paramName);
329 if(entry) return getInt(*entry,paramName,paramList.name(),true);
331}
332
334 ParameterList &paramList, const std::string &paramName,
335 const long long defaultValue
336 ) const
337{
338 const ParameterEntry *entry = paramList.getEntryPtr(paramName);
339 if(entry) return getLongLong(*entry,paramName,paramList.name(),true);
341}
342
344 ParameterList &paramList, const std::string &paramName,
345 const double defaultValue
346 ) const
347{
348 const ParameterEntry *entry = paramList.getEntryPtr(paramName);
349 if(entry) return getDouble(*entry,paramName,paramList.name(),true);
351}
352
353
355 ParameterList &paramList, const std::string &paramName,
356 const std::string &defaultValue
357 ) const
358{
359 const ParameterEntry *entry = paramList.getEntryPtr(paramName);
360 if(entry) return getString(*entry,paramName,paramList.name(),true);
362}
363
365{
366 return acceptedTypes_.allowInt();
367}
368
370{
371 return acceptedTypes_.allowLongLong();
372}
373
375{
376 return acceptedTypes_.allowDouble();
377}
378
380{
381 return acceptedTypes_.allowString();
382}
383
384
387{
388 return preferredType_;
389}
390
391
392// Overridden from ParameterEntryValidator
393
394
396{
397 return "anynumberValidator";
398}
399
400
402 std::string const & docString,
403 std::ostream & out
404 ) const
405{
406 StrUtils::printLines(out,"# ",docString);
407 out << "# Accepted types: " << acceptedTypesString_ << ".\n";
408}
409
410
416
417
419 ParameterEntry const& entry,
420 std::string const& paramName,
421 std::string const& sublistName
422 ) const
423{
424 // Validate that the parameter exists and can be converted to a double.
425 // NOTE: Even if the target type will be an 'int', we don't know that here
426 // so it will be better to assert that a 'double' can be created. The type
427 // 'double' has a very large exponent range and, subject to digit
428 // truncation, a 'double' can represent every 'int' value.
429 getDouble(entry, paramName, sublistName, false);
430}
431
432
434 std::string const& paramName,
435 std::string const& sublistName,
436 ParameterEntry * entry
437 ) const
438{
439 TEUCHOS_TEST_FOR_EXCEPT(0==entry);
440 switch(preferredType_) {
441 case PREFER_INT:
442 entry->setValue(
443 getInt(*entry,paramName,sublistName,false),
444 false // isDefault
445 );
446 break;
447 case PREFER_LONG_LONG:
448 entry->setValue(
449 getLongLong(*entry,paramName,sublistName,false),
450 false // isDefault
451 );
452 break;
453 case PREFER_DOUBLE:
454 entry->setValue(
455 getDouble(*entry,paramName,sublistName,false),
456 false // isDefault
457 );
458 break;
459 case PREFER_STRING:
460 entry->setValue(
461 getString(*entry,paramName,sublistName,false),
462 false // isDefault
463 );
464 break;
465 default:
466 TEUCHOS_TEST_FOR_EXCEPT("Error, Invalid EPreferredType value!");
467 }
468}
469
470
471// private
472
473
474void AnyNumberParameterEntryValidator::finishInitialization()
475{
476
477 std::ostringstream oss;
478 bool addedType = false;
479 if(acceptedTypes_.allowInt()) {
480 oss << "\"int\"";
481 addedType = true;
482 }
483 if(acceptedTypes_.allowLongLong()) {
484 oss << "\"long long\"";
485 addedType = true;
486 }
487 if(acceptedTypes_.allowDouble()) {
488 if(addedType) oss << ", ";
489 oss << "\"double\"";
490 addedType = true;
491 }
492 if(acceptedTypes_.allowString()) {
493 if(addedType) oss << ", ";
494 oss << "\"string\"";
495 addedType = true;
496 }
497 acceptedTypesString_ = oss.str();
498}
499
500
501void AnyNumberParameterEntryValidator::throwTypeError(
502 ParameterEntry const& entry,
503 std::string const& paramName,
504 std::string const& sublistName
505 ) const
506{
507 const std::string &entryName = entry.getAny(false).typeName();
509 true, Exceptions::InvalidParameterType
510 ,"Error, the parameter {paramName=\""<<paramName<<"\""
511 ",type=\""<<entryName<<"\"}"
512 << "\nin the sublist \"" << sublistName << "\""
513 << "\nhas the wrong type."
514 << "\n\nThe accepted types are: " << acceptedTypesString_ << "!";
515 );
516}
517
518
519RCP<AnyNumberParameterEntryValidator>
521{
522 return anyNumberParameterEntryValidator(
523 AnyNumberParameterEntryValidator::PREFER_INT,
525}
526
527
532
533
535{
536 return mustAlreadyExist_;
537}
538
540{
541 return EmptyNameOK_;
542}
543
545{
546 this->mustAlreadyExist_ = shouldFileExist;
547 return mustAlreadyExist_;
548}
549
551{
552 this->EmptyNameOK_ = isEmptyNameOK;
553 return EmptyNameOK_;
554}
555
558{
559 return null;
560}
561
562
563void FileNameValidator::validate(ParameterEntry const &entry, std::string const &paramName,
564 std::string const &sublistName) const
565{
566 const std::string &entryName = entry.getAny(false).typeName();
567 any anyValue = entry.getAny(true);
568 TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string) ),
570 "The \"" << paramName << "\"" <<
571 " parameter in the \"" << sublistName <<
572 "\" sublist is has an error." << std::endl << std::endl <<
573 "Error: The value that you entered was the wrong type." << std::endl <<
574 "Parameter: " << paramName << std::endl <<
575 "Type specified: " << entryName << std::endl <<
576 "Type accepted: " << typeid(std::string).name() <<
577 std::endl << std::endl);
578 if(mustAlreadyExist_ && !EmptyNameOK_){
579 std::string fileName = getValue<std::string>(entry);
580 TEUCHOS_TEST_FOR_EXCEPTION(!std::ifstream(fileName.c_str()),
582 "The \"" << paramName << "\"" <<
583 " parameter in the \"" << sublistName <<
584 "\" sublist is has an error." << std::endl << std::endl <<
585 "Error: The file must already exists. The value you entered does " <<
586 "not corresspond to an existing file name." << std::endl <<
587 "Parameter: " << paramName << std::endl <<
588 "File name specified: " << fileName << std::endl << std::endl);
589 }
590}
591
592
593const std::string FileNameValidator::getXMLTypeName() const
594{
595 return "FilenameValidator";
596}
597
598
600 std::string const &docString, std::ostream &out) const
601{
602 StrUtils::printLines(out,"# ",docString);
603 out << "# Validator Used: " << std::endl;
604 out << "# FileName Validator" << std::endl;
605}
606
607
611
612
616
617
620 caseSensitive_(caseSensitive)
621{
622 if (!caseSensitive_) {
624 size_t k = 0;
625 for (auto it = validStrings.begin(); it != validStrings.end(); ++it) {
626 upperCaseValidStrings[k] = upperCase(*it);
627 ++k;
628 }
629 validStrings_ = rcp(new Array<std::string>(upperCaseValidStrings));
630 }
631 else
632 validStrings_ = rcp(new Array<std::string>(validStrings));
633}
634
635
638{
639 validStrings_ = rcp(new Array<std::string>(validStrings));
640 return validStrings_;
641}
642
643
646{
647 return validStrings_;
648}
649
650
652 ParameterEntry const &entry, std::string const &paramName,
653 std::string const &sublistName) const
654{
655 any anyValue = entry.getAny(true);
656 const std::string &entryName = entry.getAny(false).typeName();
657 TEUCHOS_TEST_FOR_EXCEPTION(!(anyValue.type() == typeid(std::string)) ,
659 "The \"" << paramName << "\"" <<
660 " parameter in the \"" << sublistName <<
661 "\" sublist is has an error." << std::endl << std::endl <<
662 "Error: The value that you entered was the wrong type." <<
663 "Parameter: " << paramName << std::endl <<
664 "Type specified: " << entryName << std::endl <<
665 "Type accepted: " << Teuchos::TypeNameTraits<std::string>::name() <<
666 std::endl);
667 if(!validStrings_.is_null()){
668 auto value = getValue<std::string>(entry);
669 if (!caseSensitive_)
670 value = upperCase(value);
672 it = std::find(validStrings_->begin(),
673 validStrings_->end(), value);
674 TEUCHOS_TEST_FOR_EXCEPTION(it == validStrings_->end(),
676 "The \"" << paramName << "\"" <<
677 " parameter in the \"" << sublistName <<
678 "\" sublist is has an error." << std::endl << std::endl <<
679 "Error: The value that was entered doesn't fall with in "
680 "the range set by the validator." <<
681 "Parameter: " << paramName << std::endl <<
682 "Acceptable Values: " << *validStrings_ << std::endl <<
683 "Value entered: " << getValue<std::string>(entry) << std::endl <<
684 std::endl);
685 }
686}
687
688
689const std::string StringValidator::getXMLTypeName() const
690{
691 return "StringValidator";
692}
693
694
695void StringValidator::printDoc(std::string const &docString,
696 std::ostream &out) const
697{
698 Teuchos::StrUtils::printLines(out,"# ",docString);
699 out << "# Validator Used: " << std::endl;
700 out << "# String Validator" << std::endl;
701 if (validStrings_.get() && validStrings_->size()){
702 out << "# Acceptable Values: " << *validStrings_ << std::endl;
703 }
704}
705
706
710
711
712} // namespace Teuchos
713
714
715// Nonmember helper functions
716
718Teuchos::boolParameterEntryValidator()
719{
720 return rcp(new BoolParameterEntryValidator());
721}
722
724Teuchos::anyNumberParameterEntryValidator()
725{
726 return rcp(new AnyNumberParameterEntryValidator());
727}
728
729
731Teuchos::anyNumberParameterEntryValidator(
732 AnyNumberParameterEntryValidator::EPreferredType const preferredType,
733 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
734 )
735{
736 return rcp(
737 new AnyNumberParameterEntryValidator(
738 preferredType, acceptedTypes
739 )
740 );
741}
742
743void Teuchos::setIntParameter(
744 std::string const& paramName,
745 int const value, std::string const& docString,
746 ParameterList *paramList,
747 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
748 )
749{
750 TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
751 const RCP<const ParameterEntryValidator> paramEntryValidator =
752 anyNumberParameterEntryValidator(
753 AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes
754 );
755 paramList->set(paramName, value, docString, paramEntryValidator);
756}
757
758
759void Teuchos::setLongLongParameter(
760 std::string const& paramName,
761 long long const value, std::string const& docString,
762 ParameterList *paramList,
763 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
764 )
765{
766 TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
767 const RCP<const ParameterEntryValidator> paramEntryValidator =
768 anyNumberParameterEntryValidator(
769 AnyNumberParameterEntryValidator::PREFER_LONG_LONG, acceptedTypes
770 );
771 paramList->set(paramName, value, docString, paramEntryValidator);
772}
773
774
775void Teuchos::setDoubleParameter(
776 std::string const& paramName,
777 double const& value, std::string const& docString,
778 ParameterList *paramList,
779 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
780 )
781{
782 TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
783 const RCP<const ParameterEntryValidator> paramEntryValidator =
784 anyNumberParameterEntryValidator(
785 AnyNumberParameterEntryValidator::PREFER_DOUBLE, acceptedTypes
786 );
787 paramList->set(paramName, value, docString, paramEntryValidator);
788}
789
790
791void Teuchos::setNumericStringParameter(
792 std::string const& paramName,
793 std::string const& value, std::string const& docString,
794 ParameterList *paramList,
795 AnyNumberParameterEntryValidator::AcceptedTypes const& acceptedTypes
796 )
797{
798 TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
799 const RCP<const ParameterEntryValidator> paramEntryValidator =
800 anyNumberParameterEntryValidator(
801 AnyNumberParameterEntryValidator::PREFER_STRING, acceptedTypes
802 );
803 paramList->set(paramName, value, docString, paramEntryValidator);
804}
805
806
807int Teuchos::getIntParameter(
808 ParameterList const& paramList,
809 std::string const& paramName
810 )
811{
812 const ParameterEntry &entry = paramList.getEntry(paramName);
813 RCP<const AnyNumberParameterEntryValidator>
814 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
815 entry.validator()
816 );
817 if ( !is_null(anyNumValidator) )
818 return anyNumValidator->getInt(entry,paramName,paramList.name());
819 if ( typeid(int) == entry.getAny().type() )
820 return any_cast<int>(entry.getAny());
821 // Try the do the conversion which might fail!
822 const AnyNumberParameterEntryValidator myAnyNumValidator;
823 return myAnyNumValidator.getInt(entry,paramName,paramList.name());
824}
825
826
827long long Teuchos::getLongLongParameter(
828 ParameterList const& paramList,
829 std::string const& paramName
830 )
831{
832 const ParameterEntry &entry = paramList.getEntry(paramName);
833 RCP<const AnyNumberParameterEntryValidator>
834 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
835 entry.validator()
836 );
837 if ( !is_null(anyNumValidator) )
838 return anyNumValidator->getLongLong(entry,paramName,paramList.name());
839 if ( typeid(long long) == entry.getAny().type() )
840 return any_cast<long long>(entry.getAny());
841 // Try the do the conversion which might fail!
842 const AnyNumberParameterEntryValidator myAnyNumValidator;
843 return myAnyNumValidator.getLongLong(entry,paramName,paramList.name());
844}
845
846
847double Teuchos::getDoubleParameter(
848 ParameterList const& paramList,
849 std::string const& paramName
850 )
851{
852 const ParameterEntry &entry = paramList.getEntry(paramName);
853 RCP<const AnyNumberParameterEntryValidator>
854 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
855 entry.validator()
856 );
857 if ( !is_null(anyNumValidator) )
858 return anyNumValidator->getDouble(entry,paramName,paramList.name());
859 if ( typeid(double) == entry.getAny().type() )
860 return any_cast<double>(entry.getAny());
861 // Try the do the conversion which might fail!
862 const AnyNumberParameterEntryValidator myAnyNumValidator;
863 return myAnyNumValidator.getDouble(entry,paramName,paramList.name());
864}
865
866
867std::string Teuchos::getNumericStringParameter(
868 ParameterList const& paramList,
869 std::string const& paramName
870 )
871{
872 const ParameterEntry &entry = paramList.getEntry(paramName);
873 RCP<const AnyNumberParameterEntryValidator>
874 anyNumValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>(
875 entry.validator()
876 );
877 if ( !is_null(anyNumValidator) )
878 return anyNumValidator->getString(entry,paramName,paramList.name());
879 if ( typeid(std::string) == entry.getAny().type() )
880 return any_cast<std::string>(entry.getAny());
881 // Try the do the conversion which might fail!
882 const AnyNumberParameterEntryValidator myAnyNumValidator;
883 return myAnyNumValidator.getString(entry,paramName,paramList.name());
884}
Definition of Teuchos::as, for conversions between types.
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
void printDoc(std::string const &docString, std::ostream &out) const
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. will call std::stod.
long long getLongLong(const ParameterEntry &entry, const std::string &paramName="", const std::string &sublistName="", const bool activeQuery=true) const
Get a long long value from a parameter entry. will call std::stoll Note that std::stoll throws on bad...
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.
AnyNumberParameterEntryValidator()
Construct with a preferrded type of double and accept all types.
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. will call std::stoi Note that std::stoi throws on badly ...
bool isLongLongAllowed() const
Lookup whether or not long longs are allowed.
void validateAndModify(std::string const &paramName, std::string const &sublistName, ParameterEntry *entry) const
bool isStringAllowed() const
Lookup whether or not strings are allowed.
bool isDoubleAllowed() const
Lookup whether or not doubles are allowed.
EPreferredType getPreferredType() const
Lookup the preferred type.
bool isIntAllowed() const
Lookup whether or not ints are allowed.
std::vector< T >::const_iterator const_iterator
The type of a const forward iterator.
void validateAndModify(std::string const &paramName, std::string const &sublistName, ParameterEntry *entry) const
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
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.
void printDoc(std::string const &docString, std::ostream &out) const
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
bool fileEmptyNameOK() const
Gets the variable describing whether or not this validator is OK with file name being empty (even if ...
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)
bool fileMustExist() const
Gets the variable describing whether or not this validator wants the file that is specified to alread...
FileNameValidator(bool mustAlreadyExist=mustAlreadyExistDefault())
Constructs a FileNameValidator.
bool setFileMustExist(bool shouldFileExist)
Sets whether or not the validator requires the file to already exist.
void printDoc(std::string const &docString, std::ostream &out) const
Abstract interface for an object that can validate a ParameterEntry's value.
This object is held as the "value" in the Teuchos::ParameterList std::map.
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
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.
A list of parameters of arbitrary type.
Smart reference counting pointer class for automatic garbage collection.
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.
bool is_null() const
Returns true if the underlying pointer is null.
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.
A simple validator that only allows certain string values to be choosen or simply enforces that a par...
void validate(ParameterEntry const &entry, std::string const &paramName, std::string const &sublistName) const
void printDoc(std::string const &docString, std::ostream &out) const
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.
Default traits class that just returns typeid(T).name().
static std::string toString(const double &x)
Write a double as a std::string.
Modified boost::any class, which is a container for a templated value.
std::string typeName() const
Return the name of the type.
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#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(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
@ VERB_MEDIUM
Generate more output.
@ VERB_HIGH
Generate a high level of output.
@ VERB_EXTREME
Generate the most output possible.
@ VERB_NONE
Generate no output.
@ VERB_DEFAULT
Generate output as defined by the object.
@ VERB_LOW
Generate only a minimal amount of output.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.