Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StandardDependencies.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 
43 
44 #ifndef TEUCHOS_STANDARDDEPENDCIES_HPP_
45 #define TEUCHOS_STANDARDDEPENDCIES_HPP_
46 
51 #include "Teuchos_Dependency.hpp"
52 #include "Teuchos_StandardParameterEntryValidators.hpp"
54 #include "Teuchos_StandardFunctionObjects.hpp"
55 #include "Teuchos_ScalarTraits.hpp"
57 
58 
59 namespace Teuchos{
60 
61 
72 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT VisualDependency : public Dependency{
73 
74 public:
75 
77  static const bool& getShowIfDefaultValue(){
78  static const bool SHOW_IF_DEFAULT_VALUE = true;
79  return SHOW_IF_DEFAULT_VALUE;
80  }
81 
82 
85 
96  RCP<ParameterEntry> dependent,
97  bool showIf=getShowIfDefaultValue());
98 
108  RCP<const ParameterEntry> dependee,
109  ParameterEntryList dependents,
110  bool showIf=getShowIfDefaultValue());
111 
121  ConstParameterEntryList dependees,
122  RCP<ParameterEntry> dependent,
123  bool showIf=getShowIfDefaultValue());
124 
134  ConstParameterEntryList dependees,
135  ParameterEntryList dependents,
136  bool showIf=getShowIfDefaultValue());
137 
139 
141 
142 
149  virtual bool getDependeeState() const = 0;
150 
154  bool isDependentVisible() const;
155 
157  bool getShowIf() const;
158 
160 
163 
165  void evaluate();
166 
168 
169 private:
170 
173 
177  bool dependentVisible_;
178 
183  bool showIf_;
184 
186 
187 };
188 
192 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ValidatorDependency : public Dependency{
193 
194 public:
195 
198 
206  RCP<const ParameterEntry> dependee,
207  RCP<ParameterEntry> dependent);
208 
216  RCP<const ParameterEntry> dependee,
217  ParameterEntryList dependents);
218 
220 
223 
225  virtual void evaluate() = 0;
226 
228 
229 };
230 
244 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringVisualDependency : public VisualDependency{
245 
246 public:
247 
250 
255 
257 
260 
275  RCP<const ParameterEntry> dependee,
276  RCP<ParameterEntry> dependent,
277  std::string value,
278  bool showIf=true);
279 
294  RCP<const ParameterEntry> dependee,
295  RCP<ParameterEntry> dependent,
296  const ValueList& values,
297  bool showIf=true);
298 
313  RCP<const ParameterEntry> dependee,
315  const std::string& value,
316  bool showIf=true);
317 
333  RCP<const ParameterEntry> dependee,
335  const ValueList& values,
336  bool showIf=true);
337 
339 
342 
344  const ValueList& getValues() const;
345 
347 
350 
352  bool getDependeeState() const;
353 
355 
358 
360  std::string getTypeAttributeValue() const;
361 
363 
364 protected:
365 
368 
370  void validateDep() const;
371 
373 
374 private:
375 
378 
382  const ValueList values_;
383 
385 
386 };
387 
388 
394 template<>
395 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<StringVisualDependency>{
396 
397 public:
398 
401 
405  static RCP<StringVisualDependency> getDummyObject();
406 
408 
409 };
410 
411 
425 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolVisualDependency : public VisualDependency{
426 
427 public:
428 
431 
442  RCP<const ParameterEntry> dependee,
443  RCP<ParameterEntry> dependent,
444  bool showIf=true);
445 
456  RCP<const ParameterEntry> dependee,
458  bool showIf=true);
459 
461 
464 
466  bool getDependeeState() const;
467 
469 
472 
474  std::string getTypeAttributeValue() const;
475 
477 
478 protected:
479 
482 
484  void validateDep() const;
485 
487 
488 };
489 
490 
496 template<>
497 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<BoolVisualDependency>{
498 
499 public:
500 
503 
507  static RCP<BoolVisualDependency> getDummyObject();
508 
510 
511 };
512 
529 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ConditionVisualDependency : public VisualDependency{
530 
531 public:
532 
535 
548  RCP<const Condition> condition,
549  RCP<ParameterEntry> dependent,
550  bool showIf=true);
551 
563  RCP<const Condition> condition,
565  bool showIf=true);
566 
568 
571 
573  RCP<const Condition> getCondition() const;
574 
577 
579  bool getDependeeState() const;
580 
582 
585 
587  std::string getTypeAttributeValue() const;
588 
590 
591 protected:
592 
595 
597  void validateDep() const {}
598 
600 
601 
602 private:
603 
606 
610  RCP<const Condition> condition_;
611 
613 
614 };
615 
616 
622 template<>
623 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<ConditionVisualDependency>{
624 
625 public:
626 
629 
632  static RCP<ConditionVisualDependency> getDummyObject();
633 
635 
636 };
637 
638 
659 template <class T>
661 
662 public:
663 
666 
688  RCP<const ParameterEntry> dependee,
689  RCP<ParameterEntry> dependent,
690  bool showIf=true,
691  RCP<SimpleFunctionObject<T> > func=null);
692 
714  RCP<const ParameterEntry> dependee,
715  ParameterEntryList dependents,
716  bool showIf=true,
717  RCP<SimpleFunctionObject<T> > func=null);
718 
720 
723 
724  bool getDependeeState() const;
725 
727 
730 
732  std::string getTypeAttributeValue() const;
733 
735 
738 
741 
743 
744 protected:
745 
748 
750  void validateDep() const;
751 
753 
754 private:
755 
758 
764 
766  //
767 };
768 
769 template<class T>
771  RCP<const ParameterEntry> dependee,
772  RCP<ParameterEntry> dependent,
773  bool showIf,
775  :VisualDependency(dependee, dependent, showIf),
776  func_(func)
777 {
778  validateDep();
779 }
780 
781 template<class T>
783  RCP<const ParameterEntry> dependee,
784  ParameterEntryList dependents,
785  bool showIf,
787  :VisualDependency(dependee, dependents, showIf),
788  func_(func)
789 {
790  validateDep();
791 }
792 
793 template<class T>
795  T value = getFirstDependeeValue<T>();
796  if(!func_.is_null()){
797  value = func_->runFunction(value);
798  }
799  return value > ScalarTraits<T>::zero() ? true : false;
800 }
801 
802 template<class T>
804  return "NumberVisualDependency(" + TypeNameTraits<T>::name() + ")";
805 }
806 
807 template<class T>
810 {
811  return func_.getConst();
812 }
813 
814 template<class T>
816  RCP<const ParameterEntry> dependee = getFirstDependee();
818  !dependee->isType<T>(),
820  "The dependee of a " <<
821  "Number Visual Dependency must the same type as the dependency's " <<
822  "template type!" << std::endl <<
823  "Type Encountered: " << dependee->getAny().typeName() << std::endl <<
824  "Template Type: " << TypeNameTraits<T>::name() << std::endl <<
825  std::endl);
826 }
827 
828 
834 template<class T>
836 
837 public:
838 
841 
846 
848 
849 };
850 
851 template<class T>
854 {
855  return rcp(new NumberVisualDependency<T>(
858 }
859 
864 template<class DependeeType, class DependentType>
866 public:
867 
870 
879  RCP<const ParameterEntry> dependee,
880  RCP<ParameterEntry> dependent,
881  RCP<const SimpleFunctionObject<DependeeType> > func=null);
882 
891  RCP<const ParameterEntry> dependee,
892  ParameterEntryList dependents,
893  RCP<const SimpleFunctionObject<DependeeType> > func=null);
894 
896 
899 
908  {
909  return func_;
910  }
911 
913 
916 
918  virtual void evaluate();
919 
920 protected:
921 
923  virtual void validateDep() const;
924 
926 
929 
937  virtual void modifyArray(
938  DependeeType newAmount,
939  RCP<ParameterEntry> dependentToModify) = 0;
940 
948  virtual std::string getBadDependentValueErrorMessage() const=0;
949 
951 private:
952 
955 
960 
961  //}
962 };
963 
964 template<class DependeeType, class DependentType>
966  RCP<const ParameterEntry> dependee,
967  RCP<ParameterEntry> dependent,
969  Dependency(dependee, dependent),
970  func_(func)
971 {}
972 
973 template<class DependeeType, class DependentType>
975  RCP<const ParameterEntry> dependee,
976  ParameterEntryList dependents,
978  Dependency(dependee, dependents),
979  func_(func)
980 {}
981 
982 template<class DependeeType, class DependentType>
985  typeid(DependeeType) != getFirstDependee()->getAny().type(),
987  "Ay no! The dependee parameter types don't match." << std::endl <<
988  "Dependee Template Type: " << TypeNameTraits<DependeeType>::name() <<
989  std::endl <<
990  "Dependee Parameter Type: " << getFirstDependee()->getAny().typeName()
991  << std::endl << std::endl);
992 }
993 
994 template<class DependeeType, class DependentType>
996  DependeeType newAmount = Dependency::getFirstDependeeValue<DependeeType>();
997  if(!this->getFunctionObject().is_null()){
998  newAmount = this->getFunctionObject()->runFunction(newAmount);
999  }
1000 
1003  getBadDependentValueErrorMessage());
1004 
1005  for(
1006  Dependency::ParameterEntryList::iterator it = this->getDependents().begin();
1007  it != this->getDependents().end();
1008  ++it)
1009  {
1010  modifyArray(newAmount, *it);
1011  }
1012 }
1013 
1014 
1037 template<class DependeeType, class DependentType>
1039  public ArrayModifierDependency<DependeeType, DependentType>
1040 {
1041 
1042 public:
1043 
1046 
1056  RCP<const ParameterEntry> dependee,
1057  RCP<ParameterEntry> dependent,
1058  RCP<const SimpleFunctionObject<DependeeType> > func=null);
1059 
1069  RCP<const ParameterEntry> dependee,
1070  Dependency::ParameterEntryList dependents,
1071  RCP<const SimpleFunctionObject<DependeeType> > func=null);
1072 
1074 
1077 
1079  std::string getTypeAttributeValue() const;
1080 
1082 
1083 protected:
1084 
1087 
1088  virtual void validateDep() const;
1089 
1091  void modifyArray(
1092  DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
1093 
1095  std::string getBadDependentValueErrorMessage() const;
1096 
1098 
1099 };
1100 
1101 template<class DependeeType, class DependentType>
1103  RCP<const ParameterEntry> dependee,
1104  RCP<ParameterEntry> dependent,
1106  ArrayModifierDependency<DependeeType, DependentType>(dependee, dependent, func)
1107 {
1108  validateDep();
1109 }
1110 
1111 template<class DependeeType, class DependentType>
1113  RCP<const ParameterEntry> dependee,
1114  Dependency::ParameterEntryList dependents,
1116  ArrayModifierDependency<DependeeType, DependentType>(dependee, dependents, func)
1117 {
1118  validateDep();
1119 }
1120 
1121 
1122 template<class DependeeType, class DependentType>
1123 std::string
1125 const
1126 {
1127  return "NumberArrayLengthDependency(" +
1130 }
1131 
1132 template <class DependeeType, class DependentType>
1133 void
1135  DependeeType newAmount, RCP<ParameterEntry> dependentToModify)
1136 {
1137  const Array<DependentType> originalArray =
1138  any_cast<Array<DependentType> >(dependentToModify->getAny());
1139  Array<DependentType> newArray(newAmount);
1140  DependeeType i;
1141  for(
1143  i<originalArray.size() && i<newAmount;
1144  ++i)
1145  {
1146  newArray[i] = originalArray[i];
1147  }
1148 
1149  dependentToModify->setValue(newArray,
1150  false, dependentToModify->docString(), dependentToModify->validator());
1151 }
1152 
1153 template<class DependeeType, class DependentType>
1154 std::string
1156  std::ostringstream os;
1157  os <<
1158  "Ruh Roh Shaggy! Looks like a dependency tried to set the length "
1159  "of the Array(s) to a negative number. Silly. You can't have "
1160  "an Array with a negative length!" << std::endl << std::endl <<
1161  "Error:" << std::endl <<
1162  "An attempt was made to set the length of an Array to a negative "
1163  "number by a NumberArrayLengthDependency" << std::endl << std::endl;
1164  return os.str();
1165 }
1166 
1167 template<class DependeeType, class DependentType>
1168 void
1170  const
1171 {
1173  for(
1174  Dependency::ConstParameterEntryList::const_iterator it =
1175  this->getDependents().begin();
1176  it != this->getDependents().end();
1177  ++it)
1178  {
1180  typeid(Teuchos::Array<DependentType>) != (*it)->getAny().type(),
1182  "Ay no! The dependent parameter types don't match." << std::endl <<
1183  "Dependent Template Type: " <<
1184  TypeNameTraits<DependentType>::name() << std::endl <<
1185  "Dependent Parameter Type: " <<
1186  (*it)->getAny().typeName() << std::endl << std::endl);
1187  }
1188 }
1189 
1195 template<class DependeeType, class DependentType>
1196 class DummyObjectGetter<NumberArrayLengthDependency<DependeeType, DependentType> >{
1197 
1198 public:
1199 
1202 
1207  getDummyObject();
1208 
1210 
1211 };
1212 
1213 template<class DependeeType, class DependentType>
1216 {
1217  return rcp(
1221 }
1222 
1247 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringValidatorDependency : public ValidatorDependency{
1248 
1249 public:
1250 
1253 
1257  typedef std::map<std::string, RCP<const ParameterEntryValidator> >
1259 
1263  typedef std::pair<std::string, RCP<const ParameterEntryValidator> >
1265 
1267 
1270 
1285  RCP<const ParameterEntry> dependee,
1286  RCP<ParameterEntry> dependent,
1287  ValueToValidatorMap valuesAndValidators,
1288  RCP<ParameterEntryValidator> defaultValidator=null);
1289 
1304  RCP<const ParameterEntry> dependee,
1305  Dependency::ParameterEntryList dependents,
1306  ValueToValidatorMap valuesAndValidators,
1307  RCP<ParameterEntryValidator> defaultValidator = null);
1308 
1310 
1313 
1316  const ValueToValidatorMap& getValuesAndValidators() const;
1317 
1319  RCP<const ParameterEntryValidator> getDefaultValidator() const;
1320 
1322 
1325 
1327  void evaluate();
1328 
1330 
1333 
1335  std::string getTypeAttributeValue() const;
1336 
1338 
1339 protected:
1340 
1343 
1344  void validateDep() const;
1345 
1347 
1348 private:
1349 
1352 
1357  ValueToValidatorMap valuesAndValidators_;
1358 
1364  RCP<ParameterEntryValidator> defaultValidator_;
1365 
1367 
1368 };
1369 
1370 
1376 template<>
1377 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<StringValidatorDependency>{
1378 
1379 public:
1380 
1383 
1386  static RCP<StringValidatorDependency > getDummyObject();
1387 
1389 
1390 };
1391 
1407 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolValidatorDependency : public ValidatorDependency{
1408 
1409 public:
1410 
1413 
1425  RCP<const ParameterEntry> dependee,
1426  RCP<ParameterEntry> dependent,
1427  RCP<const ParameterEntryValidator> trueValidator,
1428  RCP<const ParameterEntryValidator> falseValidator=null);
1429 
1441  RCP<const ParameterEntry> dependee,
1442  Dependency::ParameterEntryList dependents,
1443  RCP<const ParameterEntryValidator> trueValidator,
1444  RCP<const ParameterEntryValidator> falseValidator=null);
1445 
1447 
1450 
1451  void evaluate();
1452 
1454 
1457 
1459  RCP<const ParameterEntryValidator> getTrueValidator() const;
1460 
1462  RCP<const ParameterEntryValidator> getFalseValidator() const;
1463 
1465 
1468 
1470  std::string getTypeAttributeValue() const;
1471 
1473 
1474 protected:
1475 
1478 
1479  void validateDep() const;
1480 
1482 
1483 private:
1484 
1487 
1492  RCP<const ParameterEntryValidator> trueValidator_, falseValidator_;
1493 
1495 
1496 };
1497 
1503 template<>
1504 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<BoolValidatorDependency>{
1505 
1506 public:
1507 
1510 
1512  static RCP<BoolValidatorDependency > getDummyObject();
1513 
1515 
1516 };
1517 
1547 template<class T>
1549 
1550 public:
1551 
1554 
1558  typedef std::pair<T,T> Range;
1559 
1563  typedef std::map<Range, RCP<const ParameterEntryValidator> >
1565 
1569  typedef std::pair<Range, RCP<const ParameterEntryValidator> >
1571 
1573 
1576 
1591  RCP<const ParameterEntry> dependee,
1592  RCP<ParameterEntry> dependent,
1593  RangeToValidatorMap rangesAndValidators,
1594  RCP<const ParameterEntryValidator> defaultValidator=null);
1595 
1610  RCP<const ParameterEntry> dependee,
1611  Dependency::ParameterEntryList dependents,
1612  RangeToValidatorMap rangesAndValidators,
1613  RCP<const ParameterEntryValidator> defaultValidator=null);
1614 
1616 
1619 
1622  return rangesAndValidators_;
1623  }
1624 
1627  return defaultValidator_;
1628  }
1629 
1631 
1634 
1636  void evaluate();
1637 
1639 
1642 
1644  std::string getTypeAttributeValue() const;
1645 
1647 
1648 protected:
1649 
1652 
1654  void validateDep() const;
1655 
1657 
1658 
1659 private:
1660 
1663 
1667  RangeToValidatorMap rangesAndValidators_;
1668 
1669  void setDependentsToValidator(RCP<const ParameterEntryValidator> toSet);
1670 
1671  RCP<const ParameterEntryValidator> defaultValidator_;
1672 
1674 
1675 };
1676 
1677 template<class T>
1679  RCP<const ParameterEntry> dependee,
1680  RCP<ParameterEntry> dependent,
1681  RangeToValidatorMap rangesAndValidators,
1682  RCP<const ParameterEntryValidator> defaultValidator)
1683  :ValidatorDependency(dependee, dependent),
1684  rangesAndValidators_(rangesAndValidators),
1685  defaultValidator_(defaultValidator)
1686 {
1687  validateDep();
1688 }
1689 
1690 template<class T>
1692  RCP<const ParameterEntry> dependee,
1693  Dependency::ParameterEntryList dependents,
1694  RangeToValidatorMap rangesAndValidators,
1695  RCP<const ParameterEntryValidator> defaultValidator)
1696  :ValidatorDependency(dependee, dependents),
1697  rangesAndValidators_(rangesAndValidators),
1698  defaultValidator_(defaultValidator)
1699 {
1700  validateDep();
1701 }
1702 
1703 template<class T>
1705 {
1706  return "RangeValidatorDependency(" + TypeNameTraits<T>::name() + ")";
1707 }
1708 
1709 
1710 template<class T>
1712  typename RangeToValidatorMap::const_iterator it;
1713  T dependeeValue = getFirstDependeeValue<T>();
1714  for(
1715  it = rangesAndValidators_.begin();
1716  it != rangesAndValidators_.end();
1717  ++it)
1718  {
1719  T min = it->first.first;
1720  T max = it->first.second;
1721  if(dependeeValue >= min && dependeeValue <max){
1722  setDependentsToValidator(it->second);
1723  return;
1724  }
1725  }
1726  setDependentsToValidator(defaultValidator_);
1727 }
1728 
1729 template<class T>
1731  RCP<const ParameterEntry> dependee = getFirstDependee();
1732  TEUCHOS_TEST_FOR_EXCEPTION(dependee->getAny().type() != typeid(T),
1734  "The dependee of a RangeValidatorDependency must be the same type as " <<
1735  "The RangeValidatorDependency template type!" << std::endl <<
1736  "Dependee Type: " << dependee->getAny().typeName() << std::endl <<
1737  "Templated Type: " << TypeNameTraits<T>::name() << std::endl << std::endl);
1738 
1740  rangesAndValidators_.size() < 1,
1742  "The rangesAndValidators map RangeValidatorDependency "
1743  "must have at least one entry!" << std::endl << std::endl);
1744 
1745  typename RangeToValidatorMap::const_iterator it =
1746  rangesAndValidators_.begin();
1747  RCP<const ParameterEntryValidator> firstValidator = it->second;
1748  // getting the raw pointer avoids a Clang warning about side effects in typeid
1749  const ParameterEntryValidator* rawValidatorPtr = firstValidator.get();
1750  ++it;
1751  for(; it!=rangesAndValidators_.end(); ++it){
1752  TEUCHOS_TEST_FOR_EXCEPTION( typeid(*rawValidatorPtr) != typeid(*(it->second)),
1754  "Ay no! All of the validators in a RangeValidatorDependency "
1755  "must have the same type.");
1757  it->first.first > it->first.second,
1759  "The Range " << it->first.first << " to " << it->first.second <<
1760  " is invalid. The min can't be greater than the max, you silly goose!"
1761  );
1762  }
1763 
1765  nonnull(defaultValidator_)
1766  &&
1767  typeid(*rawValidatorPtr) != typeid(*defaultValidator_),
1769  "Ay no! The default validator of a RangeValidatorDependency "
1770  "must have the same type as the validators in rangesAndValidators map."
1771  );
1772 
1773 }
1774 
1775 template<class T>
1778 {
1779  typename ParameterEntryList::const_iterator it;
1780  for(
1781  it = getDependents().begin();
1782  it != getDependents().end();
1783  ++it)
1784  {
1785  (*it)->setValidator(toSet);
1786  }
1787 }
1788 
1794 template<class T>
1796 
1797 public:
1798 
1801 
1806 
1808 
1809 };
1810 
1811 template<class T>
1814 {
1816  typename RangeValidatorDependency<T>::Range dummyRange(
1818  RCP<FileNameValidator> dummyValidator =
1820  dummyMap.insert(typename RangeValidatorDependency<T>::RangeValidatorPair(
1821  dummyRange, dummyValidator));
1822  return rcp(new RangeValidatorDependency<T>(
1825  dummyMap));
1826 }
1827 
1832 template<class DependeeType, class DependentType>
1834  public ArrayModifierDependency<DependeeType, DependentType>
1835 {
1836 
1837 public:
1838 
1841 
1851  RCP<const ParameterEntry> dependee,
1852  RCP<ParameterEntry> dependent,
1853  RCP<const SimpleFunctionObject<DependeeType> > func=null):
1854  ArrayModifierDependency<DependeeType, DependentType>(
1855  dependee,
1856  dependent,
1857  func)
1858  {}
1859 
1860 
1870  RCP<const ParameterEntry> dependee,
1871  Dependency::ParameterEntryList dependents,
1872  RCP<const SimpleFunctionObject<DependeeType> > func=null):
1873  ArrayModifierDependency<DependeeType, DependentType>(
1874  dependee,
1875  dependents,
1876  func)
1877  {}
1878 
1880 
1881 protected:
1882 
1885 
1886  virtual void validateDep() const;
1887 
1889 
1890 };
1891 
1892 template<class DependeeType, class DependentType>
1893 void
1895  const
1896 {
1898  for(
1899  Dependency::ConstParameterEntryList::const_iterator it =
1900  this->getDependents().begin();
1901  it != this->getDependents().end();
1902  ++it)
1903  {
1905  typeid(Teuchos::TwoDArray<DependentType>) != (*it)->getAny().type(),
1907  "Ay no! The dependent parameter types don't match." << std::endl <<
1908  "Dependent Template Type: " <<
1909  TypeNameTraits<DependentType>::name() << std::endl <<
1910  "Dependent Parameter Type: " <<
1911  (*it)->getAny().typeName() << std::endl << std::endl);
1912  }
1913 }
1914 
1915 
1923 template<class DependeeType, class DependentType>
1925  public TwoDArrayModifierDependency<DependeeType, DependentType>
1926 {
1927 
1928 public:
1929 
1932 
1942  RCP<const ParameterEntry> dependee,
1943  RCP<ParameterEntry> dependent,
1944  RCP<const SimpleFunctionObject<DependeeType> > func=null);
1945 
1946 
1956  RCP<const ParameterEntry> dependee,
1957  Dependency::ParameterEntryList dependents,
1958  RCP<const SimpleFunctionObject<DependeeType> > func=null);
1959 
1961 
1964 
1966  std::string getTypeAttributeValue() const;
1967 
1969 
1970 protected:
1971 
1974 
1976  void modifyArray(
1977  DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
1978 
1980  std::string getBadDependentValueErrorMessage() const;
1982 
1983 };
1984 
1985 template<class DependeeType, class DependentType>
1987  RCP<const ParameterEntry> dependee,
1988  RCP<ParameterEntry> dependent,
1990  TwoDArrayModifierDependency<DependeeType, DependentType>(
1991  dependee, dependent, func)
1992 {
1993  this->validateDep();
1994 }
1995 
1996 template<class DependeeType, class DependentType>
1998  RCP<const ParameterEntry> dependee,
1999  Dependency::ParameterEntryList dependents,
2001  TwoDArrayModifierDependency<DependeeType, DependentType>(
2002  dependee, dependents, func)
2003 {
2004  this->validateDep();
2005 }
2006 
2007 
2008 template<class DependeeType, class DependentType>
2009 std::string
2011 const
2012 {
2013  return "TwoDRowDependency(" +
2016 }
2017 
2018 template <class DependeeType, class DependentType>
2019 void
2021  DependeeType newAmount,
2022  RCP<ParameterEntry> dependentToModify)
2023 {
2024  TwoDArray<DependentType> originalArray =
2025  any_cast<TwoDArray<DependentType> >(dependentToModify->getAny());
2026  originalArray.resizeRows(newAmount);
2027  dependentToModify->setValue(originalArray,
2028  false, dependentToModify->docString(), dependentToModify->validator());
2029 }
2030 
2031 template<class DependeeType, class DependentType>
2032 std::string
2034  std::ostringstream os;
2035  os <<
2036  "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
2037  "rows in TwoDArray(s) to a negative number. Silly. You can't have "
2038  "a TwoDArray with a negative number of rows!" << std::endl << std::endl <<
2039  "Error:" << std::endl <<
2040  "An attempt was made to set the number of rows of a TwoDArray to a negative "
2041  "number by a TwoDRowDependency" << std::endl << std::endl;
2042  return os.str();
2043 }
2044 
2050 template<class DependeeType, class DependentType>
2051 class DummyObjectGetter<TwoDRowDependency<DependeeType, DependentType> >{
2052 
2053 public:
2054 
2057 
2062  getDummyObject();
2063 
2065 
2066 };
2067 
2068 template<class DependeeType, class DependentType>
2071 {
2072  return rcp(
2076 }
2077 
2078 
2086 template<class DependeeType, class DependentType>
2088  public TwoDArrayModifierDependency<DependeeType, DependentType>
2089 {
2090 
2091 public:
2092 
2095 
2105  RCP<const ParameterEntry> dependee,
2106  RCP<ParameterEntry> dependent,
2107  RCP<const SimpleFunctionObject<DependeeType> > func=null);
2108 
2109 
2119  RCP<const ParameterEntry> dependee,
2120  Dependency::ParameterEntryList dependents,
2121  RCP<const SimpleFunctionObject<DependeeType> > func=null);
2122 
2124 
2127 
2129  std::string getTypeAttributeValue() const;
2130 
2132 
2133 protected:
2134 
2137 
2139  void modifyArray(
2140  DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
2141 
2143  std::string getBadDependentValueErrorMessage() const;
2145 
2146 };
2147 
2148 template<class DependeeType, class DependentType>
2150  RCP<const ParameterEntry> dependee,
2151  RCP<ParameterEntry> dependent,
2153  TwoDArrayModifierDependency<DependeeType, DependentType>(
2154  dependee, dependent, func)
2155 {
2156  this->validateDep();
2157 }
2158 
2159 template<class DependeeType, class DependentType>
2161  RCP<const ParameterEntry> dependee,
2162  Dependency::ParameterEntryList dependents,
2164  TwoDArrayModifierDependency<DependeeType, DependentType>(
2165  dependee, dependents, func)
2166 {
2167  this->validateDep();
2168 }
2169 
2170 
2171 template<class DependeeType, class DependentType>
2172 std::string
2174 const
2175 {
2176  return "TwoDColDependency(" +
2179 }
2180 
2181 template <class DependeeType, class DependentType>
2182 void
2184  DependeeType newAmount,
2185  RCP<ParameterEntry> dependentToModify)
2186 {
2187  TwoDArray<DependentType> originalArray =
2188  any_cast<TwoDArray<DependentType> >(dependentToModify->getAny());
2189  originalArray.resizeCols(newAmount);
2190  dependentToModify->setValue(originalArray,
2191  false, dependentToModify->docString(), dependentToModify->validator());
2192 }
2193 
2194 template<class DependeeType, class DependentType>
2195 std::string
2197  std::ostringstream os;
2198  os <<
2199  "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
2200  "cols in TwoDArray(s) to a negative number. Silly. You can't have "
2201  "a TwoDArray with a negative number of cols!" << std::endl << std::endl <<
2202  "Error:" << std::endl <<
2203  "An attempt was made to set the number of columns of a TwoDArrayArray to a negative "
2204  "number by a TwoDColDependency" << std::endl << std::endl;
2205  return os.str();
2206 }
2207 
2213 template<class DependeeType, class DependentType>
2214 class DummyObjectGetter<TwoDColDependency<DependeeType, DependentType> >{
2215 
2216 public:
2217 
2220 
2225  getDummyObject();
2226 
2228 
2229 };
2230 
2231 template<class DependeeType, class DependentType>
2234 {
2235  return rcp(
2239 }
2240 
2241 
2242 
2243 } //namespace Teuchos
2244 #endif //TEUCHOS_STANDARDDEPENDCIES_HPP_
RCP< const ParameterEntryValidator > getDefaultValidator() const
A dependency in which the number of rows in a parameter with a TwoDArray depends on the value of anot...
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
A BoolValidatorDependency says the following about the relationship between two parameters: Dependeni...
std::pair< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorPair
Conveniece typedef.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
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.
An abstract parent class for all visual dependencies.
A string visual depdencies says the following about the relationship between two elements in a Parame...
A bool visual dependency says the following about the relationship between two elements in a Paramete...
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
A dependency in which the number of rows in a parameter with a TwoDArray depends on the value of anot...
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
NumberArrayLengthDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a NumberArrayLengthDependency.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool isType() const
Test the type of the data being contained.
std::string getBadDependentValueErrorMessage() const
T * get() const
Get the raw C++ pointer to the underlying object.
void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
virtual void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)=0
Modifies a particular attribute of the array according to the specific semantics of the dependency...
ArrayModifierDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs an ArrayModifierDependency.
This class represents a depndency between elements in a Parameter List.
This structure defines some basic traits for a scalar field type.
A RangeValidatorDependency says the following about the relationship between two parameters: Dependen...
const RangeToValidatorMap & getRangeToValidatorMap() const
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
TwoDRowDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDRowDependency.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
TwoDArrayModifierDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDArrayModifierDependency.
std::string getBadDependentValueErrorMessage() const
void resizeCols(size_type numberOfCols)
Changes the number of rows in the matrix.
A NumberArrayLengthDependency says the following about the relationship between two parameters: The l...
void resizeRows(size_type numberOfRows)
Changes the number of rows in the matrix.
This structure defines some basic traits for the ordinal field type.
TwoDArrayModifierDependency(RCP< const ParameterEntry > dependee, Dependency::ParameterEntryList dependents, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDArrayModifierDependency.
void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)
TwoDColDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const SimpleFunctionObject< DependeeType > > func=null)
Constructs a TwoDColDependency.
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...
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.
Defines basic traits for the ordinal field type.
Default traits class that just returns typeid(T).name().
Class for retrieving a dummy object of type T.
A StringValidatorDependency says the following about the relationship between two parameters: Depende...
RangeValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RangeToValidatorMap rangesAndValidators, RCP< const ParameterEntryValidator > defaultValidator=null)
Constructs a RangeValidatorDependency.
An abstract base class for all dependencies which modify the dimensional attributes of an Array param...
size_type size() const
Defines basic traits for the scalar field type.
static T zero()
Returns representation of zero for this scalar type.
An abstract base class for all validator dependencies.
std::string typeName() const
Return the name of the type.
Smart reference counting pointer class for automatic garbage collection.
A condition visual dependency says the following about the relationship between elements in a Paramet...
virtual std::string getBadDependentValueErrorMessage() const =0
Returns the error message that should be displayed if the dependent has taken on a value that...
std::pair< Range, RCP< const ParameterEntryValidator > > RangeValidatorPair
Convenience typedef.
const std::type_info & type() const
Return the type of value being stored.
void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)
std::string docString() const
Return the (optional) documentation std::string.
std::pair< T, T > Range
Convenience typedef.
RCP< const SimpleFunctionObject< DependeeType > > getFunctionObject() const
Retrieves the function being used to calculate the amount by which an arrays dimensional attribute sh...
A number 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...
std::map< Range, RCP< const ParameterEntryValidator > > RangeToValidatorMap
Convenience typedef.
Standard Conditions to be used.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
RCP< const SimpleFunctionObject< T > > getFunctionObject() const
Const version of function getter.