Teuchos - Trilinos Tools Package  Version of the Day
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 
740  RCP<const SimpleFunctionObject<T> > getFunctionObject() const;
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>
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 
845  static RCP<NumberVisualDependency<T> > getDummyObject();
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 
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>
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  ++it;
1749  for(; it!=rangesAndValidators_.end(); ++it){
1750  TEUCHOS_TEST_FOR_EXCEPTION( typeid(*firstValidator) != typeid(*(it->second)),
1752  "Ay no! All of the validators in a RangeValidatorDependency "
1753  "must have the same type.");
1755  it->first.first > it->first.second,
1757  "The Range " << it->first.first << " to " << it->first.second <<
1758  " is invalid. The min can't be greater than the max, you silly goose!"
1759  );
1760  }
1761 
1763  nonnull(defaultValidator_)
1764  &&
1765  typeid(*firstValidator) != typeid(*defaultValidator_),
1767  "Ay no! The default validator of a RangeValidatorDependency "
1768  "must have the same type as the validators in rangesAndValidators map."
1769  );
1770 
1771 }
1772 
1773 template<class T>
1776 {
1777  typename ParameterEntryList::const_iterator it;
1778  for(
1779  it = getDependents().begin();
1780  it != getDependents().end();
1781  ++it)
1782  {
1783  (*it)->setValidator(toSet);
1784  }
1785 }
1786 
1792 template<class T>
1794 
1795 public:
1796 
1799 
1803  static RCP<RangeValidatorDependency<T> > getDummyObject();
1804 
1806 
1807 };
1808 
1809 template<class T>
1812 {
1814  typename RangeValidatorDependency<T>::Range dummyRange(
1816  RCP<FileNameValidator> dummyValidator =
1818  dummyMap.insert(typename RangeValidatorDependency<T>::RangeValidatorPair(
1819  dummyRange, dummyValidator));
1820  return rcp(new RangeValidatorDependency<T>(
1823  dummyMap));
1824 }
1825 
1830 template<class DependeeType, class DependentType>
1832  public ArrayModifierDependency<DependeeType, DependentType>
1833 {
1834 
1835 public:
1836 
1839 
1849  RCP<const ParameterEntry> dependee,
1850  RCP<ParameterEntry> dependent,
1851  RCP<const SimpleFunctionObject<DependeeType> > func=null):
1852  ArrayModifierDependency<DependeeType, DependentType>(
1853  dependee,
1854  dependent,
1855  func)
1856  {}
1857 
1858 
1868  RCP<const ParameterEntry> dependee,
1869  Dependency::ParameterEntryList dependents,
1870  RCP<const SimpleFunctionObject<DependeeType> > func=null):
1871  ArrayModifierDependency<DependeeType, DependentType>(
1872  dependee,
1873  dependents,
1874  func)
1875  {}
1876 
1878 
1879 protected:
1880 
1883 
1884  virtual void validateDep() const;
1885 
1887 
1888 };
1889 
1890 template<class DependeeType, class DependentType>
1891 void
1893  const
1894 {
1896  for(
1897  Dependency::ConstParameterEntryList::const_iterator it =
1898  this->getDependents().begin();
1899  it != this->getDependents().end();
1900  ++it)
1901  {
1903  typeid(Teuchos::TwoDArray<DependentType>) != (*it)->getAny().type(),
1905  "Ay no! The dependent parameter types don't match." << std::endl <<
1906  "Dependent Template Type: " <<
1907  TypeNameTraits<DependentType>::name() << std::endl <<
1908  "Dependent Parameter Type: " <<
1909  (*it)->getAny().typeName() << std::endl << std::endl);
1910  }
1911 }
1912 
1913 
1921 template<class DependeeType, class DependentType>
1923  public TwoDArrayModifierDependency<DependeeType, DependentType>
1924 {
1925 
1926 public:
1927 
1930 
1940  RCP<const ParameterEntry> dependee,
1941  RCP<ParameterEntry> dependent,
1942  RCP<const SimpleFunctionObject<DependeeType> > func=null);
1943 
1944 
1954  RCP<const ParameterEntry> dependee,
1955  Dependency::ParameterEntryList dependents,
1956  RCP<const SimpleFunctionObject<DependeeType> > func=null);
1957 
1959 
1962 
1964  std::string getTypeAttributeValue() const;
1965 
1967 
1968 protected:
1969 
1972 
1974  void modifyArray(
1975  DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
1976 
1978  std::string getBadDependentValueErrorMessage() const;
1980 
1981 };
1982 
1983 template<class DependeeType, class DependentType>
1985  RCP<const ParameterEntry> dependee,
1986  RCP<ParameterEntry> dependent,
1988  TwoDArrayModifierDependency<DependeeType, DependentType>(
1989  dependee, dependent, func)
1990 {
1991  this->validateDep();
1992 }
1993 
1994 template<class DependeeType, class DependentType>
1996  RCP<const ParameterEntry> dependee,
1997  Dependency::ParameterEntryList dependents,
1999  TwoDArrayModifierDependency<DependeeType, DependentType>(
2000  dependee, dependents, func)
2001 {
2002  this->validateDep();
2003 }
2004 
2005 
2006 template<class DependeeType, class DependentType>
2007 std::string
2009 const
2010 {
2011  return "TwoDRowDependency(" +
2014 }
2015 
2016 template <class DependeeType, class DependentType>
2017 void
2019  DependeeType newAmount,
2020  RCP<ParameterEntry> dependentToModify)
2021 {
2022  TwoDArray<DependentType> originalArray =
2023  any_cast<TwoDArray<DependentType> >(dependentToModify->getAny());
2024  originalArray.resizeRows(newAmount);
2025  dependentToModify->setValue(originalArray,
2026  false, dependentToModify->docString(), dependentToModify->validator());
2027 }
2028 
2029 template<class DependeeType, class DependentType>
2030 std::string
2032  std::ostringstream os;
2033  os <<
2034  "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
2035  "rows in TwoDArray(s) to a negative number. Silly. You can't have "
2036  "a TwoDArray with a negative number of rows!" << std::endl << std::endl <<
2037  "Error:" << std::endl <<
2038  "An attempt was made to set the number of rows of a TwoDArray to a negative "
2039  "number by a TwoDRowDependency" << std::endl << std::endl;
2040  return os.str();
2041 }
2042 
2048 template<class DependeeType, class DependentType>
2049 class DummyObjectGetter<TwoDRowDependency<DependeeType, DependentType> >{
2050 
2051 public:
2052 
2055 
2060  getDummyObject();
2061 
2063 
2064 };
2065 
2066 template<class DependeeType, class DependentType>
2069 {
2070  return rcp(
2074 }
2075 
2076 
2084 template<class DependeeType, class DependentType>
2086  public TwoDArrayModifierDependency<DependeeType, DependentType>
2087 {
2088 
2089 public:
2090 
2093 
2103  RCP<const ParameterEntry> dependee,
2104  RCP<ParameterEntry> dependent,
2105  RCP<const SimpleFunctionObject<DependeeType> > func=null);
2106 
2107 
2117  RCP<const ParameterEntry> dependee,
2118  Dependency::ParameterEntryList dependents,
2119  RCP<const SimpleFunctionObject<DependeeType> > func=null);
2120 
2122 
2125 
2127  std::string getTypeAttributeValue() const;
2128 
2130 
2131 protected:
2132 
2135 
2137  void modifyArray(
2138  DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
2139 
2141  std::string getBadDependentValueErrorMessage() const;
2143 
2144 };
2145 
2146 template<class DependeeType, class DependentType>
2148  RCP<const ParameterEntry> dependee,
2149  RCP<ParameterEntry> dependent,
2151  TwoDArrayModifierDependency<DependeeType, DependentType>(
2152  dependee, dependent, func)
2153 {
2154  this->validateDep();
2155 }
2156 
2157 template<class DependeeType, class DependentType>
2159  RCP<const ParameterEntry> dependee,
2160  Dependency::ParameterEntryList dependents,
2162  TwoDArrayModifierDependency<DependeeType, DependentType>(
2163  dependee, dependents, func)
2164 {
2165  this->validateDep();
2166 }
2167 
2168 
2169 template<class DependeeType, class DependentType>
2170 std::string
2172 const
2173 {
2174  return "TwoDColDependency(" +
2177 }
2178 
2179 template <class DependeeType, class DependentType>
2180 void
2182  DependeeType newAmount,
2183  RCP<ParameterEntry> dependentToModify)
2184 {
2185  TwoDArray<DependentType> originalArray =
2186  any_cast<TwoDArray<DependentType> >(dependentToModify->getAny());
2187  originalArray.resizeCols(newAmount);
2188  dependentToModify->setValue(originalArray,
2189  false, dependentToModify->docString(), dependentToModify->validator());
2190 }
2191 
2192 template<class DependeeType, class DependentType>
2193 std::string
2195  std::ostringstream os;
2196  os <<
2197  "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
2198  "cols in TwoDArray(s) to a negative number. Silly. You can't have "
2199  "a TwoDArray with a negative number of cols!" << std::endl << std::endl <<
2200  "Error:" << std::endl <<
2201  "An attempt was made to set the number of colums of a TwoDArrayArray to a negative "
2202  "number by a TwoDColDependency" << std::endl << std::endl;
2203  return os.str();
2204 }
2205 
2211 template<class DependeeType, class DependentType>
2212 class DummyObjectGetter<TwoDColDependency<DependeeType, DependentType> >{
2213 
2214 public:
2215 
2218 
2223  getDummyObject();
2224 
2226 
2227 };
2228 
2229 template<class DependeeType, class DependentType>
2232 {
2233  return rcp(
2237 }
2238 
2239 
2240 
2241 } //namespace Teuchos
2242 #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.
An abstract parent class for all visual dependencies.
ParameterEntryList & getDependents()
Gets the dependents of the dependency.
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...
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 "value" 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.
std::string getBadDependentValueErrorMessage() const
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 interpurted 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
virtual std::string getTypeAttributeValue() const =0
Returns the string to be used for the value of the type attribute when converting the dependency to X...
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.
RCP< const ParameterEntry > getFirstDependee() const
Gets the first dependee in the dependees list. This is a convience function.
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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
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.
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.
void modifyArray(DependeeType newAmount, RCP< ParameterEntry > dependentToModify)
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.