Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StandardDependencies.hpp
Go to the documentation of this file.
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_STANDARDDEPENDCIES_HPP_
11#define TEUCHOS_STANDARDDEPENDCIES_HPP_
12
17#include "Teuchos_Dependency.hpp"
18#include "Teuchos_StandardParameterEntryValidators.hpp"
20#include "Teuchos_StandardFunctionObjects.hpp"
23
24
25namespace Teuchos{
26
27
38class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT VisualDependency : public Dependency{
39
40public:
41
43 static const bool& getShowIfDefaultValue(){
44 static const bool SHOW_IF_DEFAULT_VALUE = true;
46 }
47
48
51
63 bool showIf=getShowIfDefaultValue());
64
76 bool showIf=getShowIfDefaultValue());
77
89 bool showIf=getShowIfDefaultValue());
90
102 bool showIf=getShowIfDefaultValue());
103
105
107
108
115 virtual bool getDependeeState() const = 0;
116
120 bool isDependentVisible() const;
121
123 bool getShowIf() const;
124
126
129
131 void evaluate();
132
134
135private:
136
139
143 bool dependentVisible_;
144
149 bool showIf_;
150
152
153};
154
158class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ValidatorDependency : public Dependency{
159
160public:
161
164
174
184
186
189
191 virtual void evaluate() = 0;
192
194
195};
196
210class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringVisualDependency : public VisualDependency{
211
212public:
213
216
221
223
226
243 std::string value,
244 bool showIf=true);
245
262 const ValueList& values,
263 bool showIf=true);
264
281 const std::string& value,
282 bool showIf=true);
283
301 const ValueList& values,
302 bool showIf=true);
303
305
308
310 const ValueList& getValues() const;
311
313
316
318 bool getDependeeState() const;
319
321
324
326 std::string getTypeAttributeValue() const;
327
329
330protected:
331
334
336 void validateDep() const;
337
339
340private:
341
344
348 const ValueList values_;
349
351
352};
353
354
360template<>
361class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<StringVisualDependency>{
362
363public:
364
367
371 static RCP<StringVisualDependency> getDummyObject();
372
374
375};
376
377
391class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolVisualDependency : public VisualDependency{
392
393public:
394
397
410 bool showIf=true);
411
424 bool showIf=true);
425
427
430
432 bool getDependeeState() const;
433
435
438
440 std::string getTypeAttributeValue() const;
441
443
444protected:
445
448
450 void validateDep() const;
451
453
454};
455
456
462template<>
463class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<BoolVisualDependency>{
464
465public:
466
469
473 static RCP<BoolVisualDependency> getDummyObject();
474
476
477};
478
495class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ConditionVisualDependency : public VisualDependency{
496
497public:
498
501
516 bool showIf=true);
517
531 bool showIf=true);
532
534
537
539 RCP<const Condition> getCondition() const;
540
543
545 bool getDependeeState() const;
546
548
551
553 std::string getTypeAttributeValue() const;
554
556
557protected:
558
561
563 void validateDep() const {}
564
566
567
568private:
569
572
576 RCP<const Condition> condition_;
577
579
580};
581
582
588template<>
589class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<ConditionVisualDependency>{
590
591public:
592
595
598 static RCP<ConditionVisualDependency> getDummyObject();
599
601
602};
603
604
625template <class T>
627
628public:
629
632
656 bool showIf=true,
658
682 bool showIf=true,
684
686
689
690 bool getDependeeState() const;
691
693
696
698 std::string getTypeAttributeValue() const;
699
701
704
707
709
710protected:
711
714
716 void validateDep() const;
717
719
720private:
721
724
730
732 //
733};
734
735template<class T>
746
747template<class T>
758
759template<class T>
761 T value = getFirstDependeeValue<T>();
762 if(!func_.is_null()){
763 value = func_->runFunction(value);
764 }
765 return value > ScalarTraits<T>::zero() ? true : false;
766}
767
768template<class T>
770 return "NumberVisualDependency(" + TypeNameTraits<T>::name() + ")";
771}
772
773template<class T>
776{
777 return func_.getConst();
778}
779
780template<class T>
782 RCP<const ParameterEntry> dependee = getFirstDependee();
784 !dependee->isType<T>(),
786 "The dependee of a " <<
787 "Number Visual Dependency must the same type as the dependency's " <<
788 "template type!" << std::endl <<
789 "Type Encountered: " << dependee->getAny().typeName() << std::endl <<
790 "Template Type: " << TypeNameTraits<T>::name() << std::endl <<
791 std::endl);
792}
793
794
800template<class T>
802
803public:
804
807
812
814
815};
816
817template<class T>
825
830template<class DependeeType, class DependentType>
832public:
833
836
848
860
862
865
874 {
875 return func_;
876 }
877
879
882
884 virtual void evaluate();
885
886protected:
887
889 virtual void validateDep() const;
890
892
895
903 virtual void modifyArray(
906
914 virtual std::string getBadDependentValueErrorMessage() const=0;
915
917private:
918
921
926
927 //}
928};
929
930template<class DependeeType, class DependentType>
938
939template<class DependeeType, class DependentType>
947
948template<class DependeeType, class DependentType>
951 typeid(DependeeType) != getFirstDependee()->getAny().type(),
953 "Ay no! The dependee parameter types don't match." << std::endl <<
954 "Dependee Template Type: " << TypeNameTraits<DependeeType>::name() <<
955 std::endl <<
956 "Dependee Parameter Type: " << getFirstDependee()->getAny().typeName()
957 << std::endl << std::endl);
958}
959
960template<class DependeeType, class DependentType>
962 DependeeType newAmount = Dependency::getFirstDependeeValue<DependeeType>();
963 if(!this->getFunctionObject().is_null()){
964 newAmount = this->getFunctionObject()->runFunction(newAmount);
965 }
966
969 getBadDependentValueErrorMessage());
970
971 for(
972 Dependency::ParameterEntryList::iterator it = this->getDependents().begin();
973 it != this->getDependents().end();
974 ++it)
975 {
976 modifyArray(newAmount, *it);
977 }
978}
979
980
1003template<class DependeeType, class DependentType>
1005 public ArrayModifierDependency<DependeeType, DependentType>
1006{
1007
1008public:
1009
1012
1025
1038
1040
1043
1045 std::string getTypeAttributeValue() const;
1046
1048
1049protected:
1050
1053
1054 virtual void validateDep() const;
1055
1057 void modifyArray(
1059
1061 std::string getBadDependentValueErrorMessage() const;
1062
1064
1065};
1066
1067template<class DependeeType, class DependentType>
1076
1077template<class DependeeType, class DependentType>
1086
1087
1088template<class DependeeType, class DependentType>
1089std::string
1097
1098template <class DependeeType, class DependentType>
1099void
1118
1119template<class DependeeType, class DependentType>
1120std::string
1122 std::ostringstream os;
1123 os <<
1124 "Ruh Roh Shaggy! Looks like a dependency tried to set the length "
1125 "of the Array(s) to a negative number. Silly. You can't have "
1126 "an Array with a negative length!" << std::endl << std::endl <<
1127 "Error:" << std::endl <<
1128 "An attempt was made to set the length of an Array to a negative "
1129 "number by a NumberArrayLengthDependency" << std::endl << std::endl;
1130 return os.str();
1131}
1132
1133template<class DependeeType, class DependentType>
1134void
1136 const
1137{
1139 for(
1140 Dependency::ConstParameterEntryList::const_iterator it =
1141 this->getDependents().begin();
1142 it != this->getDependents().end();
1143 ++it)
1144 {
1146 typeid(Teuchos::Array<DependentType>) != (*it)->getAny().type(),
1148 "Ay no! The dependent parameter types don't match." << std::endl <<
1149 "Dependent Template Type: " <<
1150 TypeNameTraits<DependentType>::name() << std::endl <<
1151 "Dependent Parameter Type: " <<
1152 (*it)->getAny().typeName() << std::endl << std::endl);
1153 }
1154}
1155
1161template<class DependeeType, class DependentType>
1178
1179template<class DependeeType, class DependentType>
1188
1213class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringValidatorDependency : public ValidatorDependency{
1214
1215public:
1216
1219
1223 typedef std::map<std::string, RCP<const ParameterEntryValidator> >
1225
1229 typedef std::pair<std::string, RCP<const ParameterEntryValidator> >
1231
1233
1236
1255
1274
1276
1279
1282 const ValueToValidatorMap& getValuesAndValidators() const;
1283
1285 RCP<const ParameterEntryValidator> getDefaultValidator() const;
1286
1288
1291
1293 void evaluate();
1294
1296
1299
1301 std::string getTypeAttributeValue() const;
1302
1304
1305protected:
1306
1309
1310 void validateDep() const;
1311
1313
1314private:
1315
1318
1323 ValueToValidatorMap valuesAndValidators_;
1324
1330 RCP<ParameterEntryValidator> defaultValidator_;
1331
1333
1334};
1335
1336
1342template<>
1343class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<StringValidatorDependency>{
1344
1345public:
1346
1349
1352 static RCP<StringValidatorDependency > getDummyObject();
1353
1355
1356};
1357
1373class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolValidatorDependency : public ValidatorDependency{
1374
1375public:
1376
1379
1395
1411
1413
1416
1417 void evaluate();
1418
1420
1423
1425 RCP<const ParameterEntryValidator> getTrueValidator() const;
1426
1428 RCP<const ParameterEntryValidator> getFalseValidator() const;
1429
1431
1434
1436 std::string getTypeAttributeValue() const;
1437
1439
1440protected:
1441
1444
1445 void validateDep() const;
1446
1448
1449private:
1450
1453
1458 RCP<const ParameterEntryValidator> trueValidator_, falseValidator_;
1459
1461
1462};
1463
1469template<>
1470class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<BoolValidatorDependency>{
1471
1472public:
1473
1476
1478 static RCP<BoolValidatorDependency > getDummyObject();
1479
1481
1482};
1483
1513template<class T>
1515
1516public:
1517
1520
1524 typedef std::pair<T,T> Range;
1525
1529 typedef std::map<Range, RCP<const ParameterEntryValidator> >
1531
1535 typedef std::pair<Range, RCP<const ParameterEntryValidator> >
1537
1539
1542
1561
1580
1582
1585
1588 return rangesAndValidators_;
1589 }
1590
1593 return defaultValidator_;
1594 }
1595
1597
1600
1602 void evaluate();
1603
1605
1608
1610 std::string getTypeAttributeValue() const;
1611
1613
1614protected:
1615
1618
1620 void validateDep() const;
1621
1623
1624
1625private:
1626
1629
1633 RangeToValidatorMap rangesAndValidators_;
1634
1635 void setDependentsToValidator(RCP<const ParameterEntryValidator> toSet);
1636
1637 RCP<const ParameterEntryValidator> defaultValidator_;
1638
1640
1641};
1642
1643template<class T>
1655
1656template<class T>
1668
1669template<class T>
1671{
1672 return "RangeValidatorDependency(" + TypeNameTraits<T>::name() + ")";
1673}
1674
1675
1676template<class T>
1678 typename RangeToValidatorMap::const_iterator it;
1680 for(
1681 it = rangesAndValidators_.begin();
1682 it != rangesAndValidators_.end();
1683 ++it)
1684 {
1685 T min = it->first.first;
1686 T max = it->first.second;
1687 if(dependeeValue >= min && dependeeValue <max){
1688 setDependentsToValidator(it->second);
1689 return;
1690 }
1691 }
1692 setDependentsToValidator(defaultValidator_);
1693}
1694
1695template<class T>
1697 RCP<const ParameterEntry> dependee = getFirstDependee();
1698 TEUCHOS_TEST_FOR_EXCEPTION(dependee->getAny().type() != typeid(T),
1700 "The dependee of a RangeValidatorDependency must be the same type as " <<
1701 "The RangeValidatorDependency template type!" << std::endl <<
1702 "Dependee Type: " << dependee->getAny().typeName() << std::endl <<
1703 "Templated Type: " << TypeNameTraits<T>::name() << std::endl << std::endl);
1704
1706 rangesAndValidators_.size() < 1,
1708 "The rangesAndValidators map RangeValidatorDependency "
1709 "must have at least one entry!" << std::endl << std::endl);
1710
1711 typename RangeToValidatorMap::const_iterator it =
1712 rangesAndValidators_.begin();
1714 // getting the raw pointer avoids a Clang warning about side effects in typeid
1716 ++it;
1717 for(; it!=rangesAndValidators_.end(); ++it){
1718 TEUCHOS_TEST_FOR_EXCEPTION( typeid(*rawValidatorPtr) != typeid(*(it->second)),
1720 "Ay no! All of the validators in a RangeValidatorDependency "
1721 "must have the same type.");
1723 it->first.first > it->first.second,
1725 "The Range " << it->first.first << " to " << it->first.second <<
1726 " is invalid. The min can't be greater than the max, you silly goose!"
1727 );
1728 }
1729
1731 nonnull(defaultValidator_)
1732 &&
1733 typeid(*rawValidatorPtr) != typeid(*defaultValidator_),
1735 "Ay no! The default validator of a RangeValidatorDependency "
1736 "must have the same type as the validators in rangesAndValidators map."
1737 );
1738
1739}
1740
1741template<class T>
1744{
1745 typename ParameterEntryList::const_iterator it;
1746 for(
1747 it = getDependents().begin();
1748 it != getDependents().end();
1749 ++it)
1750 {
1751 (*it)->setValidator(toSet);
1752 }
1753}
1754
1760template<class T>
1762
1763public:
1764
1767
1772
1774
1775};
1776
1777template<class T>
1793
1798template<class DependeeType, class DependentType>
1800 public ArrayModifierDependency<DependeeType, DependentType>
1801{
1802
1803public:
1804
1807
1825
1826
1844
1846
1847protected:
1848
1851
1852 virtual void validateDep() const;
1853
1855
1856};
1857
1858template<class DependeeType, class DependentType>
1859void
1861 const
1862{
1864 for(
1865 Dependency::ConstParameterEntryList::const_iterator it =
1866 this->getDependents().begin();
1867 it != this->getDependents().end();
1868 ++it)
1869 {
1871 typeid(Teuchos::TwoDArray<DependentType>) != (*it)->getAny().type(),
1873 "Ay no! The dependent parameter types don't match." << std::endl <<
1874 "Dependent Template Type: " <<
1875 TypeNameTraits<DependentType>::name() << std::endl <<
1876 "Dependent Parameter Type: " <<
1877 (*it)->getAny().typeName() << std::endl << std::endl);
1878 }
1879}
1880
1881
1889template<class DependeeType, class DependentType>
1891 public TwoDArrayModifierDependency<DependeeType, DependentType>
1892{
1893
1894public:
1895
1898
1911
1912
1925
1927
1930
1932 std::string getTypeAttributeValue() const;
1933
1935
1936protected:
1937
1940
1942 void modifyArray(
1944
1946 std::string getBadDependentValueErrorMessage() const;
1948
1949};
1950
1951template<class DependeeType, class DependentType>
1961
1962template<class DependeeType, class DependentType>
1972
1973
1974template<class DependeeType, class DependentType>
1975std::string
1983
1984template <class DependeeType, class DependentType>
1985void
1996
1997template<class DependeeType, class DependentType>
1998std::string
2000 std::ostringstream os;
2001 os <<
2002 "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
2003 "rows in TwoDArray(s) to a negative number. Silly. You can't have "
2004 "a TwoDArray with a negative number of rows!" << std::endl << std::endl <<
2005 "Error:" << std::endl <<
2006 "An attempt was made to set the number of rows of a TwoDArray to a negative "
2007 "number by a TwoDRowDependency" << std::endl << std::endl;
2008 return os.str();
2009}
2010
2016template<class DependeeType, class DependentType>
2033
2034template<class DependeeType, class DependentType>
2043
2044
2052template<class DependeeType, class DependentType>
2054 public TwoDArrayModifierDependency<DependeeType, DependentType>
2055{
2056
2057public:
2058
2061
2074
2075
2088
2090
2093
2095 std::string getTypeAttributeValue() const;
2096
2098
2099protected:
2100
2103
2105 void modifyArray(
2107
2109 std::string getBadDependentValueErrorMessage() const;
2111
2112};
2113
2114template<class DependeeType, class DependentType>
2124
2125template<class DependeeType, class DependentType>
2135
2136
2137template<class DependeeType, class DependentType>
2138std::string
2146
2147template <class DependeeType, class DependentType>
2148void
2159
2160template<class DependeeType, class DependentType>
2161std::string
2163 std::ostringstream os;
2164 os <<
2165 "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
2166 "cols in TwoDArray(s) to a negative number. Silly. You can't have "
2167 "a TwoDArray with a negative number of cols!" << std::endl << std::endl <<
2168 "Error:" << std::endl <<
2169 "An attempt was made to set the number of columns of a TwoDArrayArray to a negative "
2170 "number by a TwoDColDependency" << std::endl << std::endl;
2171 return os.str();
2172}
2173
2179template<class DependeeType, class DependentType>
2196
2197template<class DependeeType, class DependentType>
2206
2207
2208
2209} //namespace Teuchos
2210#endif //TEUCHOS_STANDARDDEPENDCIES_HPP_
Defines basic traits for the ordinal field type.
Defines basic traits for the scalar field type.
Standard Conditions to be used.
An abstract base class for all dependencies which modify the dimensional attributes of an Array param...
ArrayModifierDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs an ArrayModifierDependency.
virtual void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)=0
Modifies a particular attribute of the array according to the specific semantics of the dependency.
virtual std::string getBadDependentValueErrorMessage() const =0
Returns the error message that should be displayed if the dependent has taken on a value that,...
RCP< const SimpleFunctionObject< DependeeType > > getFunctionObject() const
Retrieves the function being used to calculate the amount by which an arrays dimensional attribute sh...
A BoolValidatorDependency says the following about the relationship between two parameters: Dependeni...
A bool visual dependency says the following about the relationship between two elements in a Paramete...
A condition visual dependency says the following about the relationship between elements in a Paramet...
This class represents a depndency between elements in a Parameter List.
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
Class for retrieving a dummy object of type T.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
A NumberArrayLengthDependency says the following about the relationship between two parameters: The l...
NumberArrayLengthDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a NumberArrayLengthDependency.
void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)
.
A number visual dependency says the following about the relationship between two elements in a Parame...
bool getDependeeState() const
Get the state of the dependee in order to evaluate the dependency.
NumberVisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, bool showIf=true, RCP< SimpleFunctionObject< T > > func=null)
Constructs a NumberVisualDependency.
RCP< const SimpleFunctionObject< T > > getFunctionObject() const
Const version of function getter.
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.
Smart reference counting pointer class for automatic garbage collection.
RCP< const T > getConst() const
Return an RCP<const T> version of *this.
bool is_null() const
Returns true if the underlying pointer is null.
bool nonnull(const RCP< T > &p)
Returns true if p.get()!=NULL.
T * get() const
Get the raw C++ pointer to the underlying object.
A RangeValidatorDependency says the following about the relationship between two parameters: Dependen...
std::pair< Range, RCP< const ParameterEntryValidator > > RangeValidatorPair
Convenience typedef.
const RangeToValidatorMap & getRangeToValidatorMap() const
RangeValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RangeToValidatorMap rangesAndValidators, RCP< const ParameterEntryValidator > defaultValidator=null)
Constructs a RangeValidatorDependency.
RCP< const ParameterEntryValidator > getDefaultValidator() const
std::map< Range, RCP< const ParameterEntryValidator > > RangeToValidatorMap
Convenience typedef.
std::pair< T, T > Range
Convenience typedef.
A StringValidatorDependency says the following about the relationship between two parameters: Depende...
std::pair< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorPair
Conveniece typedef.
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
A string visual dependency says the following about the relationship between two elements in a Parame...
A dependency in which some attribute of a TwoDArray in a parameter depends on the value of another pa...
TwoDArrayModifierDependency(RCP< const ParameterEntry > dependee, Dependency::ParameterEntryList dependents, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDArrayModifierDependency.
TwoDArrayModifierDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDArrayModifierDependency.
A dependency in which the number of rows in a parameter with a TwoDArray depends on the value of anot...
TwoDColDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDColDependency.
void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)
A dependency in which the number of rows in a parameter with a TwoDArray depends on the value of anot...
void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)
TwoDRowDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDRowDependency.
Default traits class that just returns typeid(T).name().
An abstract base class for all validator dependencies.
An abstract parent class for all visual dependencies.
virtual bool getDependeeState() const =0
Get the state of the dependee in order to evaluate the dependency.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
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.
This structure defines some basic traits for the ordinal field type.
This structure defines some basic traits for a scalar field type.
static T zero()
Returns representation of zero for this scalar type.