Teuchos - Trilinos Tools Package Version of the Day
Teuchos_StandardDependencies.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 
00043 
00044 #ifndef TEUCHOS_STANDARDDEPENDCIES_HPP_
00045 #define TEUCHOS_STANDARDDEPENDCIES_HPP_
00046 
00051 #include "Teuchos_Dependency.hpp"
00052 #include "Teuchos_StandardParameterEntryValidators.hpp"
00053 #include "Teuchos_StandardConditions.hpp"
00054 #include "Teuchos_StandardFunctionObjects.hpp"
00055 #include "Teuchos_ScalarTraits.hpp"
00056 #include "Teuchos_OrdinalTraits.hpp"
00057 
00058 
00059 namespace Teuchos{
00060 
00061 
00072 class TEUCHOS_LIB_DLL_EXPORT VisualDependency : public Dependency{
00073 
00074 public:
00075 
00077   static const bool& getShowIfDefaultValue(){
00078     static const bool SHOW_IF_DEFAULT_VALUE = true;
00079     return SHOW_IF_DEFAULT_VALUE;
00080   }
00081     
00082 
00085 
00094   VisualDependency(
00095     RCP<const ParameterEntry> dependee, 
00096     RCP<ParameterEntry> dependent,
00097     bool showIf=getShowIfDefaultValue());
00098 
00107   VisualDependency(
00108     RCP<const ParameterEntry> dependee,
00109     ParameterEntryList dependents,
00110     bool showIf=getShowIfDefaultValue());
00111 
00120   VisualDependency(
00121     ConstParameterEntryList dependees, 
00122     RCP<ParameterEntry> dependent,
00123     bool showIf=getShowIfDefaultValue());
00124 
00133   VisualDependency(
00134     ConstParameterEntryList dependees,
00135     ParameterEntryList dependents,
00136     bool showIf=getShowIfDefaultValue());
00137 
00139 
00141 
00142 
00149   virtual bool getDependeeState() const = 0;
00150   
00154   bool isDependentVisible() const;
00155 
00157   bool getShowIf() const;
00158 
00160 
00163 
00165   void evaluate();
00166   
00168 
00169 private:
00170 
00173   
00177   bool dependentVisible_;
00178 
00183   bool showIf_;
00184   
00186 
00187 };
00188 
00192 class TEUCHOS_LIB_DLL_EXPORT ValidatorDependency : public Dependency{
00193 
00194 public:
00195 
00198 
00205   ValidatorDependency(
00206     RCP<const ParameterEntry> dependee,
00207     RCP<ParameterEntry> dependent);
00208 
00215   ValidatorDependency(
00216     RCP<const ParameterEntry> dependee, 
00217     ParameterEntryList dependents);
00218 
00220 
00223 
00225   virtual void evaluate() = 0;
00226   
00228 
00229 };
00230 
00244 class TEUCHOS_LIB_DLL_EXPORT StringVisualDependency : public VisualDependency{
00245 
00246 public:
00247 
00250 
00254   typedef Array<std::string> ValueList; 
00255   
00257 
00260 
00274   StringVisualDependency(
00275     RCP<const ParameterEntry> dependee,
00276     RCP<ParameterEntry> dependent,
00277     std::string value,
00278     bool showIf=true);
00279 
00293   StringVisualDependency(
00294     RCP<const ParameterEntry> dependee,
00295     RCP<ParameterEntry> dependent,
00296     const ValueList& values,
00297     bool showIf=true);
00298 
00312   StringVisualDependency(
00313     RCP<const ParameterEntry> dependee, 
00314     Dependency::ParameterEntryList dependents, 
00315     const std::string& value,
00316     bool showIf=true);
00317 
00332   StringVisualDependency(
00333     RCP<const ParameterEntry> dependee, 
00334     Dependency::ParameterEntryList dependents, 
00335     const ValueList& values,
00336     bool showIf=true);
00337   
00339 
00342 
00344   const ValueList& getValues() const;
00345 
00347 
00350 
00352   bool getDependeeState() const;
00353   
00355   
00358 
00360   std::string getTypeAttributeValue() const;
00361   
00363 
00364 protected:
00365 
00368 
00370   void validateDep() const;
00371   
00373 
00374 private:
00375 
00378   
00382   const ValueList values_;
00383   
00385   
00386 };
00387 
00388 
00394 template<>
00395 class TEUCHOS_LIB_DLL_EXPORT DummyObjectGetter<StringVisualDependency>{
00396 
00397 public:
00398 
00401 
00405   static RCP<StringVisualDependency> getDummyObject();
00406   
00408   
00409 };
00410 
00411 
00425 class TEUCHOS_LIB_DLL_EXPORT BoolVisualDependency : public VisualDependency{
00426 
00427 public:
00428 
00431 
00441   BoolVisualDependency(
00442     RCP<const ParameterEntry> dependee,
00443     RCP<ParameterEntry> dependent,
00444     bool showIf=true);
00445 
00455   BoolVisualDependency(
00456     RCP<const ParameterEntry> dependee, 
00457     Dependency::ParameterEntryList dependents, 
00458     bool showIf=true);
00459   
00461 
00464 
00466   bool getDependeeState() const;
00467   
00469 
00472 
00474   std::string getTypeAttributeValue() const;
00475   
00477 
00478 protected:
00479 
00482   
00484   void validateDep() const;
00485   
00487 
00488 };
00489 
00490 
00496 template<>
00497 class TEUCHOS_LIB_DLL_EXPORT DummyObjectGetter<BoolVisualDependency>{
00498 
00499 public:
00500 
00503 
00507   static RCP<BoolVisualDependency> getDummyObject();
00508   
00510   
00511 };
00512 
00529 class TEUCHOS_LIB_DLL_EXPORT ConditionVisualDependency : public VisualDependency{
00530 
00531 public:
00532 
00535 
00547   ConditionVisualDependency(
00548     RCP<const Condition> condition,
00549     RCP<ParameterEntry> dependent,
00550     bool showIf=true);
00551 
00562   ConditionVisualDependency(
00563     RCP<const Condition> condition, 
00564     Dependency::ParameterEntryList dependents,
00565     bool showIf=true);
00566   
00568   
00571   
00573   RCP<const Condition> getCondition() const;
00574 
00577 
00579   bool getDependeeState() const;
00580   
00582 
00585 
00587   std::string getTypeAttributeValue() const;
00588   
00590 
00591 protected:
00592 
00595 
00597   void validateDep() const {}
00598   
00600 
00601 
00602 private:
00603 
00606   
00610   RCP<const Condition> condition_;
00611   
00613 
00614 };
00615 
00616 
00622 template<>
00623 class TEUCHOS_LIB_DLL_EXPORT DummyObjectGetter<ConditionVisualDependency>{
00624 
00625 public:
00626 
00629 
00632   static RCP<ConditionVisualDependency> getDummyObject();
00633 
00635   
00636 };
00637 
00638 
00659 template <class T>
00660 class NumberVisualDependency : public VisualDependency{
00661 
00662 public:
00663 
00666 
00687   NumberVisualDependency(
00688     RCP<const ParameterEntry> dependee,
00689     RCP<ParameterEntry> dependent,
00690     bool showIf=true,
00691     RCP<SimpleFunctionObject<T> > func=null);
00692 
00713   NumberVisualDependency(
00714     RCP<const ParameterEntry> dependee,
00715     ParameterEntryList dependents,
00716     bool showIf=true,
00717     RCP<SimpleFunctionObject<T> > func=null);
00718 
00720 
00723 
00724   bool getDependeeState() const;
00725   
00727 
00730 
00732   std::string getTypeAttributeValue() const;
00733   
00735   
00738   
00740   RCP<const SimpleFunctionObject<T> > getFunctionObject() const;
00741 
00743 
00744 protected:
00745 
00748 
00750   void validateDep() const;
00751   
00753   
00754 private:
00755 
00758   
00763     RCP<SimpleFunctionObject<T> > func_;
00764   
00766   //
00767 };
00768 
00769 template<class T>
00770 NumberVisualDependency<T>::NumberVisualDependency(
00771   RCP<const ParameterEntry> dependee,
00772   RCP<ParameterEntry> dependent,
00773   bool showIf,
00774   RCP<SimpleFunctionObject<T> > func)
00775   :VisualDependency(dependee, dependent, showIf),
00776   func_(func)
00777 {
00778   validateDep();
00779 }
00780 
00781 template<class T>
00782 NumberVisualDependency<T>::NumberVisualDependency(
00783   RCP<const ParameterEntry> dependee,
00784   ParameterEntryList dependents,
00785   bool showIf,
00786   RCP<SimpleFunctionObject<T> > func)
00787   :VisualDependency(dependee, dependents, showIf),
00788   func_(func)
00789 {
00790   validateDep();
00791 }
00792 
00793 template<class T>
00794 bool NumberVisualDependency<T>::getDependeeState() const{
00795   T value = getFirstDependeeValue<T>();
00796   if(!func_.is_null()){
00797     value = func_->runFunction(value);
00798   }
00799   return value > ScalarTraits<T>::zero() ? true : false;
00800 }
00801 
00802 template<class T>
00803 std::string NumberVisualDependency<T>::getTypeAttributeValue() const{
00804   return "NumberVisualDependency(" + TypeNameTraits<T>::name() + ")";
00805 }
00806 
00807 template<class T>
00808 RCP<const SimpleFunctionObject<T> > 
00809   NumberVisualDependency<T>::getFunctionObject() const
00810 {
00811   return func_.getConst();
00812 }
00813 
00814 template<class T>
00815 void NumberVisualDependency<T>::validateDep() const{
00816   RCP<const ParameterEntry> dependee = getFirstDependee();
00817   TEST_FOR_EXCEPTION(
00818     !dependee->isType<T>(),
00819     InvalidDependencyException,
00820     "The dependee of a " <<
00821     "Number Visual Dependency must the same type as the dependency's " <<
00822     "template type!" << std::endl <<
00823     "Type Encountered: " << dependee->getAny().typeName() << std::endl <<
00824     "Template Type: " << TypeNameTraits<T>::name() << std::endl <<
00825     std::endl);
00826 }
00827   
00828 
00834 template<class T>
00835 class DummyObjectGetter<NumberVisualDependency<T> >{
00836 
00837 public:
00838 
00841 
00845   static RCP<NumberVisualDependency<T> > getDummyObject();
00846   
00848   
00849 };
00850 
00851 template<class T> 
00852 RCP<NumberVisualDependency<T> >
00853   DummyObjectGetter<NumberVisualDependency<T> >::getDummyObject()
00854 {
00855   return rcp(new NumberVisualDependency<T>(
00856     rcp(new ParameterEntry(ScalarTraits<T>::zero())),
00857     DummyObjectGetter<ParameterEntry>::getDummyObject()));
00858 }
00859 
00864 template<class DependeeType, class DependentType>
00865 class ArrayModifierDependency : public Dependency{
00866 public:
00867 
00870 
00878   ArrayModifierDependency(
00879     RCP<const ParameterEntry> dependee,
00880     RCP<ParameterEntry> dependent,
00881     RCP<const SimpleFunctionObject<DependeeType> > func=null);
00882 
00890   ArrayModifierDependency(
00891     RCP<const ParameterEntry> dependee,
00892     ParameterEntryList dependents,
00893     RCP<const SimpleFunctionObject<DependeeType> > func=null);
00894 
00896 
00899 
00906   inline RCP<const SimpleFunctionObject<DependeeType> > 
00907     getFunctionObject() const
00908   {
00909     return func_;
00910   }
00911 
00913 
00916 
00918   virtual void evaluate();
00919 
00920 protected:
00921 
00923   virtual void validateDep() const;
00924   
00926 
00929 
00937   virtual void modifyArray(
00938     DependeeType newAmount, 
00939     RCP<ParameterEntry> dependentToModify) = 0;
00940 
00948   virtual std::string getBadDependentValueErrorMessage() const=0;
00949 
00951 private:
00952 
00955   
00959   RCP<const SimpleFunctionObject<DependeeType> > func_;
00960 
00961   //}
00962 };
00963 
00964 template<class DependeeType, class DependentType>
00965 ArrayModifierDependency<DependeeType,DependentType>::ArrayModifierDependency(
00966   RCP<const ParameterEntry> dependee,
00967   RCP<ParameterEntry> dependent,
00968   RCP<const SimpleFunctionObject<DependeeType> > func):
00969   Dependency(dependee, dependent),
00970   func_(func)
00971 {}
00972 
00973 template<class DependeeType, class DependentType>
00974 ArrayModifierDependency<DependeeType,DependentType>::ArrayModifierDependency(
00975   RCP<const ParameterEntry> dependee,
00976   ParameterEntryList dependents,
00977   RCP<const SimpleFunctionObject<DependeeType> > func):
00978   Dependency(dependee, dependents),
00979   func_(func)
00980 {}
00981 
00982 template<class DependeeType, class DependentType>
00983 void ArrayModifierDependency<DependeeType,DependentType>::validateDep() const{
00984   TEST_FOR_EXCEPTION(
00985     typeid(DependeeType) != getFirstDependee()->getAny().type(),
00986     InvalidDependencyException,
00987     "Ay no! The dependee parameter types don't match." << std::endl <<
00988     "Dependee Template Type: " << TypeNameTraits<DependeeType>::name() <<
00989     std::endl <<
00990     "Dependee Parameter Type: " << getFirstDependee()->getAny().typeName()
00991     << std::endl << std::endl);
00992 }
00993 
00994 template<class DependeeType, class DependentType>
00995 void ArrayModifierDependency<DependeeType,DependentType>::evaluate(){
00996   DependeeType newAmount = Dependency::getFirstDependeeValue<DependeeType>();
00997   if(!this->getFunctionObject().is_null()){
00998     newAmount = this->getFunctionObject()->runFunction(newAmount);
00999   }
01000 
01001   TEST_FOR_EXCEPTION(newAmount < OrdinalTraits<DependeeType>::zero(),
01002     Exceptions::InvalidParameterValue,
01003     getBadDependentValueErrorMessage());
01004 
01005   for(
01006     Dependency::ParameterEntryList::iterator it = this->getDependents().begin();
01007     it != this->getDependents().end(); 
01008     ++it)
01009   {
01010     modifyArray(newAmount, *it);
01011   }
01012 }
01013 
01014 
01037 template<class DependeeType, class DependentType>
01038 class NumberArrayLengthDependency : 
01039   public ArrayModifierDependency<DependeeType, DependentType>
01040 {
01041 
01042 public:
01043 
01046 
01055   NumberArrayLengthDependency(
01056     RCP<const ParameterEntry> dependee,
01057     RCP<ParameterEntry> dependent,
01058     RCP<const SimpleFunctionObject<DependeeType> > func=null);
01059 
01068   NumberArrayLengthDependency(
01069     RCP<const ParameterEntry> dependee,
01070     Dependency::ParameterEntryList dependents,
01071     RCP<const SimpleFunctionObject<DependeeType> > func=null);
01072 
01074 
01077   
01079   std::string getTypeAttributeValue() const;
01080   
01082 
01083 protected:
01084 
01087 
01088   virtual void validateDep() const;
01089   
01091   void modifyArray(
01092     DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
01093   
01095   std::string getBadDependentValueErrorMessage() const;
01096 
01098   
01099 };
01100 
01101 template<class DependeeType, class DependentType>
01102 NumberArrayLengthDependency<DependeeType, DependentType>::NumberArrayLengthDependency(
01103   RCP<const ParameterEntry> dependee,
01104   RCP<ParameterEntry> dependent,
01105   RCP<const SimpleFunctionObject<DependeeType> > func):
01106   ArrayModifierDependency<DependeeType, DependentType>(dependee, dependent, func)
01107 {
01108   validateDep();
01109 }
01110 
01111 template<class DependeeType, class DependentType>
01112 NumberArrayLengthDependency<DependeeType, DependentType>::NumberArrayLengthDependency(
01113   RCP<const ParameterEntry> dependee,
01114   Dependency::ParameterEntryList dependents,
01115   RCP<const SimpleFunctionObject<DependeeType> > func):
01116   ArrayModifierDependency<DependeeType, DependentType>(dependee, dependents, func)
01117 {
01118   validateDep();
01119 }
01120 
01121 
01122 template<class DependeeType, class DependentType>
01123 std::string 
01124 NumberArrayLengthDependency<DependeeType, DependentType>::getTypeAttributeValue()
01125 const
01126 {
01127   return "NumberArrayLengthDependency(" +
01128     TypeNameTraits<DependeeType>::name() + ", " +
01129     TypeNameTraits<DependentType>::name() +")";
01130 }
01131 
01132 template <class DependeeType, class DependentType>
01133 void 
01134 NumberArrayLengthDependency<DependeeType, DependentType>::modifyArray(
01135   DependeeType newAmount, RCP<ParameterEntry> dependentToModify)
01136 {
01137   const Array<DependentType> originalArray = 
01138     any_cast<Array<DependentType> >(dependentToModify->getAny()); 
01139   Array<DependentType> newArray(newAmount);
01140   DependeeType i;
01141   for(
01142     i=OrdinalTraits<DependeeType>::zero(); 
01143     i<originalArray.size() && i<newAmount; 
01144     ++i)
01145   {
01146     newArray[i] = originalArray[i];
01147   }
01148 
01149   dependentToModify->setValue(newArray,
01150     false, dependentToModify->docString(), dependentToModify->validator());
01151 }
01152 
01153 template<class DependeeType, class DependentType>
01154 std::string 
01155 NumberArrayLengthDependency<DependeeType, DependentType>::getBadDependentValueErrorMessage() const{
01156     std::ostringstream os;
01157     os <<
01158     "Ruh Roh Shaggy! Looks like a dependency tried to set the length "
01159     "of the Array(s) to a negative number. Silly. You can't have "
01160     "an Array with a negative length!" << std::endl << std::endl <<
01161     "Error:" << std::endl <<
01162     "An attempt was made to set the length of an Array to a negative "
01163     "number by a NumberArrayLengthDependency" << std::endl << std::endl;
01164     return os.str();
01165 }
01166 
01167 template<class DependeeType, class DependentType>
01168 void 
01169 NumberArrayLengthDependency<DependeeType, DependentType>::validateDep() 
01170   const
01171 {
01172   ArrayModifierDependency<DependeeType, DependentType>::validateDep();
01173   for(
01174     Dependency::ConstParameterEntryList::const_iterator it = 
01175       this->getDependents().begin(); 
01176     it != this->getDependents().end(); 
01177     ++it)
01178   {
01179     TEST_FOR_EXCEPTION(
01180       typeid(Teuchos::Array<DependentType>) != (*it)->getAny().type(),
01181         InvalidDependencyException,
01182         "Ay no! The dependent parameter types don't match." << std::endl <<
01183         "Dependent Template Type: " << 
01184         TypeNameTraits<DependentType>::name() << std::endl <<
01185         "Dependent Parameter Type: " << 
01186         (*it)->getAny().typeName() << std::endl << std::endl);
01187   }
01188 }
01189 
01195 template<class DependeeType, class DependentType>
01196 class DummyObjectGetter<NumberArrayLengthDependency<DependeeType, DependentType> >{
01197 
01198 public:
01199 
01202 
01206   static RCP<NumberArrayLengthDependency<DependeeType, DependentType> >
01207     getDummyObject();
01208   
01210   
01211 };
01212 
01213 template<class DependeeType, class DependentType>
01214 RCP<NumberArrayLengthDependency<DependeeType, DependentType> >
01215   DummyObjectGetter<NumberArrayLengthDependency<DependeeType, DependentType> >::getDummyObject()
01216 {
01217   return rcp(
01218     new NumberArrayLengthDependency<DependeeType, DependentType>(
01219     rcp(new ParameterEntry(ScalarTraits<DependeeType>::zero())),
01220     rcp(new ParameterEntry(Array<DependentType>(1)))));
01221 }
01222 
01247 class TEUCHOS_LIB_DLL_EXPORT StringValidatorDependency : public ValidatorDependency{
01248 
01249 public:
01250 
01253 
01257   typedef std::map<std::string, RCP<const ParameterEntryValidator> > 
01258     ValueToValidatorMap;
01259 
01263   typedef std::pair<std::string, RCP<const ParameterEntryValidator> > 
01264     ValueToValidatorPair;
01265   
01267 
01270 
01284   StringValidatorDependency(
01285     RCP<const ParameterEntry> dependee, 
01286     RCP<ParameterEntry> dependent,
01287     ValueToValidatorMap valuesAndValidators, 
01288     RCP<ParameterEntryValidator> defaultValidator=null);
01289 
01303   StringValidatorDependency(
01304     RCP<const ParameterEntry> dependee, 
01305     Dependency::ParameterEntryList dependents,
01306     ValueToValidatorMap valuesAndValidators, 
01307     RCP<ParameterEntryValidator> defaultValidator = null);
01308 
01310 
01313 
01316   const ValueToValidatorMap& getValuesAndValidators() const;
01317 
01319   RCP<const ParameterEntryValidator> getDefaultValidator() const;
01320 
01322   
01325 
01327   void evaluate();
01328   
01330 
01333 
01335   std::string getTypeAttributeValue() const;
01336   
01338 
01339 protected:
01340 
01343 
01344   void validateDep() const;
01345   
01347 
01348 private:
01349 
01352   
01357   ValueToValidatorMap valuesAndValidators_;
01358 
01364   RCP<ParameterEntryValidator> defaultValidator_;
01365   
01367   
01368 };
01369 
01370 
01376 template<>
01377 class TEUCHOS_LIB_DLL_EXPORT DummyObjectGetter<StringValidatorDependency>{
01378 
01379 public:
01380 
01383 
01386   static RCP<StringValidatorDependency > getDummyObject();
01387   
01389   
01390 };
01391 
01407 class TEUCHOS_LIB_DLL_EXPORT BoolValidatorDependency : public ValidatorDependency{
01408 
01409 public:
01410 
01413 
01424   BoolValidatorDependency(
01425     RCP<const ParameterEntry> dependee,
01426     RCP<ParameterEntry> dependent,
01427     RCP<const ParameterEntryValidator> trueValidator,
01428     RCP<const ParameterEntryValidator> falseValidator=null);
01429 
01440   BoolValidatorDependency(
01441     RCP<const ParameterEntry> dependee,
01442     Dependency::ParameterEntryList dependents,
01443     RCP<const ParameterEntryValidator> trueValidator,
01444     RCP<const ParameterEntryValidator> falseValidator=null);
01445 
01447 
01450 
01451   void evaluate();
01452   
01454 
01457     
01459   RCP<const ParameterEntryValidator> getTrueValidator() const;
01460 
01462   RCP<const ParameterEntryValidator> getFalseValidator() const;
01463   
01465 
01468 
01470   std::string getTypeAttributeValue() const;
01471   
01473 
01474 protected:
01475 
01478 
01479   void validateDep() const;
01480   
01482 
01483 private:
01484 
01487   
01492   RCP<const ParameterEntryValidator> trueValidator_, falseValidator_;
01493   
01495 
01496 };
01497 
01503 template<>
01504 class TEUCHOS_LIB_DLL_EXPORT DummyObjectGetter<BoolValidatorDependency>{
01505 
01506 public:
01507 
01510 
01512   static RCP<BoolValidatorDependency > getDummyObject();
01513   
01515   
01516 };
01517 
01547 template<class T>
01548 class RangeValidatorDependency : public ValidatorDependency{
01549 
01550 public:
01551 
01554 
01558   typedef std::pair<T,T> Range;
01559 
01563   typedef std::map<Range, RCP<const ParameterEntryValidator> > 
01564     RangeToValidatorMap;
01565 
01569   typedef std::pair<Range, RCP<const ParameterEntryValidator> > 
01570     RangeValidatorPair;
01571   
01573 
01576 
01590   RangeValidatorDependency(
01591     RCP<const ParameterEntry> dependee,
01592     RCP<ParameterEntry> dependent,
01593     RangeToValidatorMap rangesAndValidators,
01594     RCP<const ParameterEntryValidator> defaultValidator=null);
01595 
01609   RangeValidatorDependency(
01610     RCP<const ParameterEntry> dependee,
01611     Dependency::ParameterEntryList dependents,
01612     RangeToValidatorMap rangesAndValidators,
01613     RCP<const ParameterEntryValidator> defaultValidator=null);
01614 
01616 
01619 
01621   const RangeToValidatorMap& getRangeToValidatorMap() const{
01622     return rangesAndValidators_;
01623   }
01624 
01626   RCP<const ParameterEntryValidator> getDefaultValidator() const{
01627     return defaultValidator_;
01628   }
01629   
01631 
01634 
01636   void evaluate();
01637   
01639 
01642 
01644   std::string getTypeAttributeValue() const;
01645   
01647 
01648 protected:
01649 
01652   
01654   void validateDep() const;
01655   
01657 
01658   
01659 private:
01660 
01663   
01667   RangeToValidatorMap rangesAndValidators_;
01668   
01669   void setDependentsToValidator(RCP<const ParameterEntryValidator> toSet);
01670 
01671   RCP<const ParameterEntryValidator> defaultValidator_;
01672 
01674 
01675 };
01676 
01677 template<class T>
01678 RangeValidatorDependency<T>::RangeValidatorDependency(
01679   RCP<const ParameterEntry> dependee,
01680   RCP<ParameterEntry> dependent,
01681   RangeToValidatorMap rangesAndValidators,
01682   RCP<const ParameterEntryValidator> defaultValidator)
01683   :ValidatorDependency(dependee, dependent),
01684   rangesAndValidators_(rangesAndValidators),
01685   defaultValidator_(defaultValidator)
01686 {
01687   validateDep();
01688 }
01689 
01690 template<class T>
01691 RangeValidatorDependency<T>::RangeValidatorDependency(
01692   RCP<const ParameterEntry> dependee,
01693   Dependency::ParameterEntryList dependents,
01694   RangeToValidatorMap rangesAndValidators,
01695   RCP<const ParameterEntryValidator> defaultValidator)
01696   :ValidatorDependency(dependee, dependents),
01697   rangesAndValidators_(rangesAndValidators),
01698   defaultValidator_(defaultValidator)
01699 {
01700   validateDep();
01701 }
01702 
01703 template<class T>
01704 std::string RangeValidatorDependency<T>::getTypeAttributeValue() const
01705 {
01706   return "RangeValidatorDependency(" + TypeNameTraits<T>::name() + ")";
01707 }
01708   
01709 
01710 template<class T>
01711 void RangeValidatorDependency<T>::evaluate(){
01712   typename RangeToValidatorMap::const_iterator it;
01713   T dependeeValue = getFirstDependeeValue<T>();
01714   for(
01715     it = rangesAndValidators_.begin(); 
01716     it != rangesAndValidators_.end(); 
01717     ++it)
01718   {
01719     T min = it->first.first;
01720     T max = it->first.second;
01721     if(dependeeValue >= min && dependeeValue <max){
01722        setDependentsToValidator(it->second);
01723       return;
01724     }
01725   }
01726   setDependentsToValidator(defaultValidator_); 
01727 }
01728 
01729 template<class T>
01730 void RangeValidatorDependency<T>::validateDep() const{
01731   RCP<const ParameterEntry> dependee = getFirstDependee();
01732   TEST_FOR_EXCEPTION(dependee->getAny().type() != typeid(T),
01733     InvalidDependencyException,
01734     "The dependee of a RangeValidatorDependency must be the same type as " <<
01735     "The RangeValidatorDependency template type!" << std::endl <<
01736     "Dependee Type: " << dependee->getAny().typeName() << std::endl <<
01737     "Templated Type: " << TypeNameTraits<T>::name() << std::endl << std::endl);
01738   
01739   TEST_FOR_EXCEPTION(
01740     rangesAndValidators_.size() < 1,
01741     InvalidDependencyException,
01742     "The rangesAndValidators map RangeValidatorDependency "
01743     "must have at least one entry!" << std::endl << std::endl);
01744 
01745   typename RangeToValidatorMap::const_iterator it = 
01746     rangesAndValidators_.begin();
01747   RCP<const ParameterEntryValidator> firstValidator = it->second;
01748   ++it;
01749   for(; it!=rangesAndValidators_.end(); ++it){
01750     TEST_FOR_EXCEPTION( typeid(*firstValidator) != typeid(*(it->second)),
01751       InvalidDependencyException,
01752       "Ay no! All of the validators in a RangeValidatorDependency "
01753       "must have the same type.");
01754     TEST_FOR_EXCEPTION(
01755       it->first.first > it->first.second,
01756       InvalidDependencyException,
01757       "The Range " << it->first.first << " to " << it->first.second <<
01758       " is invalid. The min can't be greater than the max, you silly goose!"
01759       );
01760   }
01761   
01762   TEST_FOR_EXCEPTION(
01763     nonnull(defaultValidator_) 
01764     && 
01765     typeid(*firstValidator) != typeid(*defaultValidator_),
01766     InvalidDependencyException,
01767     "Ay no! The default validator of a RangeValidatorDependency "
01768     "must have the same type as the validators in rangesAndValidators map."
01769   );
01770     
01771 }
01772 
01773 template<class T>
01774 void RangeValidatorDependency<T>::setDependentsToValidator(
01775   RCP<const ParameterEntryValidator> toSet)
01776 {
01777   typename ParameterEntryList::const_iterator it;
01778   for(
01779     it = getDependents().begin(); 
01780     it != getDependents().end(); 
01781     ++it)
01782   {
01783     (*it)->setValidator(toSet);
01784   }
01785 }
01786 
01792 template<class T>
01793 class DummyObjectGetter<RangeValidatorDependency<T> >{
01794 
01795 public:
01796 
01799 
01803   static RCP<RangeValidatorDependency<T> > getDummyObject();
01804   
01806   
01807 };
01808 
01809 template<class T>
01810 RCP<RangeValidatorDependency<T> > 
01811   DummyObjectGetter<RangeValidatorDependency<T> >::getDummyObject()
01812 {
01813   typename RangeValidatorDependency<T>::RangeToValidatorMap dummyMap;
01814   typename RangeValidatorDependency<T>::Range dummyRange(
01815     ScalarTraits<T>::zero(), ScalarTraits<T>::one());
01816   RCP<FileNameValidator> dummyValidator = 
01817     DummyObjectGetter<FileNameValidator>::getDummyObject();
01818   dummyMap.insert(typename RangeValidatorDependency<T>::RangeValidatorPair(
01819     dummyRange, dummyValidator));
01820   return rcp(new RangeValidatorDependency<T>(
01821     rcp(new ParameterEntry(ScalarTraits<T>::zero())),
01822     DummyObjectGetter<ParameterEntry>::getDummyObject(),
01823     dummyMap));
01824 }
01825 
01830 template<class DependeeType, class DependentType>
01831 class TwoDArrayModifierDependency : 
01832   public ArrayModifierDependency<DependeeType, DependentType>
01833 {
01834 
01835 public:
01836 
01839 
01848   TwoDArrayModifierDependency(
01849     RCP<const ParameterEntry> dependee,
01850     RCP<ParameterEntry> dependent,
01851     RCP<const SimpleFunctionObject<DependeeType> > func=null):
01852     ArrayModifierDependency<DependeeType, DependentType>(
01853       dependee,
01854       dependent,
01855       func)
01856   {}
01857 
01858 
01867   TwoDArrayModifierDependency(
01868     RCP<const ParameterEntry> dependee,
01869     Dependency::ParameterEntryList dependents,
01870     RCP<const SimpleFunctionObject<DependeeType> > func=null):
01871     ArrayModifierDependency<DependeeType, DependentType>(
01872       dependee,
01873       dependents,
01874       func)
01875   {}
01876 
01878 
01879 protected:
01880 
01883 
01884   virtual void validateDep() const;
01885   
01887   
01888 };
01889 
01890 template<class DependeeType, class DependentType>
01891 void 
01892 TwoDArrayModifierDependency<DependeeType, DependentType>::validateDep() 
01893   const
01894 {
01895   ArrayModifierDependency<DependeeType, DependentType>::validateDep();
01896   for(
01897     Dependency::ConstParameterEntryList::const_iterator it = 
01898       this->getDependents().begin(); 
01899     it != this->getDependents().end(); 
01900     ++it)
01901   {
01902     TEST_FOR_EXCEPTION(
01903       typeid(Teuchos::TwoDArray<DependentType>) != (*it)->getAny().type(),
01904         InvalidDependencyException,
01905         "Ay no! The dependent parameter types don't match." << std::endl <<
01906         "Dependent Template Type: " << 
01907         TypeNameTraits<DependentType>::name() << std::endl <<
01908         "Dependent Parameter Type: " << 
01909         (*it)->getAny().typeName() << std::endl << std::endl);
01910   }
01911 }
01912 
01913 
01921 template<class DependeeType, class DependentType>
01922 class TwoDRowDependency : 
01923   public TwoDArrayModifierDependency<DependeeType, DependentType>
01924 {
01925 
01926 public:
01927 
01930 
01939   TwoDRowDependency(
01940     RCP<const ParameterEntry> dependee,
01941     RCP<ParameterEntry> dependent,
01942     RCP<const SimpleFunctionObject<DependeeType> > func=null);
01943 
01944 
01953   TwoDRowDependency(
01954     RCP<const ParameterEntry> dependee,
01955     Dependency::ParameterEntryList dependents,
01956     RCP<const SimpleFunctionObject<DependeeType> > func=null);
01957 
01959 
01962 
01964   std::string getTypeAttributeValue() const;
01965   
01967 
01968 protected:
01969 
01972   
01974   void modifyArray(
01975     DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
01976   
01978   std::string getBadDependentValueErrorMessage() const;
01980   
01981 };
01982 
01983 template<class DependeeType, class DependentType>
01984 TwoDRowDependency<DependeeType, DependentType>::TwoDRowDependency(
01985   RCP<const ParameterEntry> dependee,
01986   RCP<ParameterEntry> dependent,
01987   RCP<const SimpleFunctionObject<DependeeType> > func):
01988   TwoDArrayModifierDependency<DependeeType, DependentType>(
01989     dependee, dependent, func)
01990 {
01991   this->validateDep();
01992 }
01993 
01994 template<class DependeeType, class DependentType>
01995 TwoDRowDependency<DependeeType, DependentType>::TwoDRowDependency(
01996   RCP<const ParameterEntry> dependee,
01997   Dependency::ParameterEntryList dependents,
01998   RCP<const SimpleFunctionObject<DependeeType> > func):
01999   TwoDArrayModifierDependency<DependeeType, DependentType>(
02000     dependee, dependents, func)
02001 {
02002   this->validateDep();
02003 }
02004 
02005 
02006 template<class DependeeType, class DependentType>
02007 std::string 
02008 TwoDRowDependency<DependeeType, DependentType>::getTypeAttributeValue()
02009 const
02010 {
02011   return "TwoDRowDependency(" +
02012     TypeNameTraits<DependeeType>::name() + ", " +
02013     TypeNameTraits<DependentType>::name() +")";
02014 }
02015 
02016 template <class DependeeType, class DependentType>
02017 void 
02018 TwoDRowDependency<DependeeType, DependentType>::modifyArray(
02019   DependeeType newAmount, 
02020   RCP<ParameterEntry> dependentToModify)
02021 {
02022   TwoDArray<DependentType> originalArray = 
02023     any_cast<TwoDArray<DependentType> >(dependentToModify->getAny()); 
02024   originalArray.resizeRows(newAmount);
02025   dependentToModify->setValue(originalArray,
02026     false, dependentToModify->docString(), dependentToModify->validator());
02027 }
02028 
02029 template<class DependeeType, class DependentType>
02030 std::string 
02031 TwoDRowDependency<DependeeType, DependentType>::getBadDependentValueErrorMessage() const{
02032   std::ostringstream os;
02033   os <<
02034     "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
02035     "rows in TwoDArray(s) to a negative number. Silly. You can't have "
02036     "a TwoDArray with a negative number of rows!" << std::endl << std::endl <<
02037     "Error:" << std::endl <<
02038     "An attempt was made to set the number of rows of a TwoDArray to a negative "
02039     "number by a TwoDRowDependency" << std::endl << std::endl;
02040   return os.str();
02041 }
02042 
02048 template<class DependeeType, class DependentType>
02049 class DummyObjectGetter<TwoDRowDependency<DependeeType, DependentType> >{
02050 
02051 public:
02052 
02055 
02059   static RCP<TwoDRowDependency<DependeeType, DependentType> >
02060     getDummyObject();
02061   
02063   
02064 };
02065 
02066 template<class DependeeType, class DependentType>
02067 RCP<TwoDRowDependency<DependeeType, DependentType> >
02068   DummyObjectGetter<TwoDRowDependency<DependeeType, DependentType> >::getDummyObject()
02069 {
02070   return rcp(
02071     new TwoDRowDependency<DependeeType, DependentType>(
02072     rcp(new ParameterEntry(ScalarTraits<DependeeType>::zero())),
02073     rcp(new ParameterEntry(TwoDArray<DependentType>(1,1)))));
02074 }
02075 
02076 
02084 template<class DependeeType, class DependentType>
02085 class TwoDColDependency : 
02086   public TwoDArrayModifierDependency<DependeeType, DependentType>
02087 {
02088 
02089 public:
02090 
02093 
02102   TwoDColDependency(
02103     RCP<const ParameterEntry> dependee,
02104     RCP<ParameterEntry> dependent,
02105     RCP<const SimpleFunctionObject<DependeeType> > func=null);
02106 
02107 
02116   TwoDColDependency(
02117     RCP<const ParameterEntry> dependee,
02118     Dependency::ParameterEntryList dependents,
02119     RCP<const SimpleFunctionObject<DependeeType> > func=null);
02120 
02122 
02125 
02127   std::string getTypeAttributeValue() const;
02128   
02130 
02131 protected:
02132 
02135   
02137   void modifyArray(
02138     DependeeType newAmount, RCP<ParameterEntry> dependentToModify);
02139   
02141   std::string getBadDependentValueErrorMessage() const;
02143   
02144 };
02145 
02146 template<class DependeeType, class DependentType>
02147 TwoDColDependency<DependeeType, DependentType>::TwoDColDependency(
02148   RCP<const ParameterEntry> dependee,
02149   RCP<ParameterEntry> dependent,
02150   RCP<const SimpleFunctionObject<DependeeType> > func):
02151   TwoDArrayModifierDependency<DependeeType, DependentType>(
02152     dependee, dependent, func)
02153 {
02154   this->validateDep();
02155 }
02156 
02157 template<class DependeeType, class DependentType>
02158 TwoDColDependency<DependeeType, DependentType>::TwoDColDependency(
02159   RCP<const ParameterEntry> dependee,
02160   Dependency::ParameterEntryList dependents,
02161   RCP<const SimpleFunctionObject<DependeeType> > func):
02162   TwoDArrayModifierDependency<DependeeType, DependentType>(
02163     dependee, dependents, func)
02164 {
02165   this->validateDep();
02166 }
02167 
02168 
02169 template<class DependeeType, class DependentType>
02170 std::string 
02171 TwoDColDependency<DependeeType, DependentType>::getTypeAttributeValue()
02172 const
02173 {
02174   return "TwoDColDependency(" +
02175     TypeNameTraits<DependeeType>::name() + ", " +
02176     TypeNameTraits<DependentType>::name() +")";
02177 }
02178 
02179 template <class DependeeType, class DependentType>
02180 void 
02181 TwoDColDependency<DependeeType, DependentType>::modifyArray(
02182   DependeeType newAmount, 
02183   RCP<ParameterEntry> dependentToModify)
02184 {
02185   TwoDArray<DependentType> originalArray = 
02186     any_cast<TwoDArray<DependentType> >(dependentToModify->getAny()); 
02187   originalArray.resizeCols(newAmount);
02188   dependentToModify->setValue(originalArray,
02189     false, dependentToModify->docString(), dependentToModify->validator());
02190 }
02191 
02192 template<class DependeeType, class DependentType>
02193 std::string 
02194 TwoDColDependency<DependeeType, DependentType>::getBadDependentValueErrorMessage() const{
02195   std::ostringstream os;
02196   os <<
02197     "Ruh Roh Shaggy! Looks like a dependency tried to set the number of "
02198     "cols in TwoDArray(s) to a negative number. Silly. You can't have "
02199     "a TwoDArray with a negative number of cols!" << std::endl << std::endl <<
02200     "Error:" << std::endl <<
02201     "An attempt was made to set the number of colums  of a TwoDArrayArray to a negative "
02202     "number by a TwoDColDependency" << std::endl << std::endl;
02203   return os.str();
02204 }
02205 
02211 template<class DependeeType, class DependentType>
02212 class DummyObjectGetter<TwoDColDependency<DependeeType, DependentType> >{
02213 
02214 public:
02215 
02218 
02222   static RCP<TwoDColDependency<DependeeType, DependentType> >
02223     getDummyObject();
02224   
02226   
02227 };
02228 
02229 template<class DependeeType, class DependentType>
02230 RCP<TwoDColDependency<DependeeType, DependentType> >
02231   DummyObjectGetter<TwoDColDependency<DependeeType, DependentType> >::getDummyObject()
02232 {
02233   return rcp(
02234     new TwoDColDependency<DependeeType, DependentType>(
02235     rcp(new ParameterEntry(ScalarTraits<DependeeType>::zero())),
02236     rcp(new ParameterEntry(TwoDArray<DependentType>(1,1)))));
02237 }
02238 
02239 
02240 
02241 } //namespace Teuchos
02242 #endif //TEUCHOS_STANDARDDEPENDCIES_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines