Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Teuchos_StandardDependencies.cpp
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 #include "Teuchos_StandardDependencies.hpp"
00045 #include "Teuchos_StandardParameterEntryValidators.hpp"
00046 #ifdef TEUCHOS_HAVE_QT
00047   #include <QDir>
00048 #endif
00049 
00050 
00051 namespace Teuchos{
00052 
00053 
00054 VisualDependency::VisualDependency(
00055   RCP<const ParameterEntry> dependee, 
00056   RCP<ParameterEntry> dependent,
00057   bool showIf):
00058   Dependency(dependee, dependent),
00059   showIf_(showIf){}
00060 
00061 VisualDependency::VisualDependency(
00062   RCP<const ParameterEntry> dependee,
00063   ParameterEntryList dependents,
00064   bool showIf):
00065   Dependency(dependee, dependents),
00066   showIf_(showIf){}
00067 
00068 VisualDependency::VisualDependency(
00069   ConstParameterEntryList dependees, 
00070   RCP<ParameterEntry> dependent,
00071   bool showIf):
00072   Dependency(dependees, dependent),
00073   showIf_(showIf){}
00074 
00075 VisualDependency::VisualDependency(
00076   ConstParameterEntryList dependees,
00077   ParameterEntryList dependents,
00078   bool showIf):
00079   Dependency(dependees, dependents),
00080   showIf_(showIf){}
00081 
00082 bool VisualDependency::isDependentVisible() const{
00083   return dependentVisible_;
00084 }
00085 
00086 bool VisualDependency::getShowIf() const{
00087   return showIf_;
00088 }
00089 
00090 void VisualDependency::evaluate(){
00091   if((getDependeeState() && showIf_) || (!getDependeeState() && !showIf_)){
00092     dependentVisible_ = true;
00093   }
00094   else{
00095     dependentVisible_ = false;
00096   }
00097 }
00098   
00099 ValidatorDependency::ValidatorDependency( 
00100   RCP<const ParameterEntry> dependee,
00101   RCP<ParameterEntry> dependent):
00102   Dependency(dependee, dependent){}
00103 
00104 ValidatorDependency::ValidatorDependency(
00105   RCP<const ParameterEntry> dependee, 
00106   ParameterEntryList dependents):
00107   Dependency(dependee, dependents){}
00108 
00109 StringVisualDependency::StringVisualDependency(
00110   RCP<const ParameterEntry> dependee,
00111   RCP<ParameterEntry> dependent,
00112   std::string value,
00113   bool showIf):
00114   VisualDependency(dependee, dependent, showIf),
00115   values_(ValueList(1,value))
00116 {
00117   validateDep();
00118 }
00119 
00120 StringVisualDependency::StringVisualDependency(
00121   RCP<const ParameterEntry> dependee,
00122   RCP<ParameterEntry> dependent,
00123   const ValueList& values,
00124   bool showIf):
00125   VisualDependency(dependee, dependent, showIf),
00126   values_(values)
00127 {
00128   validateDep();
00129 }
00130 
00131 StringVisualDependency::StringVisualDependency(
00132   RCP<const ParameterEntry> dependee, 
00133   Dependency::ParameterEntryList dependents, 
00134   const std::string& value,
00135   bool showIf):
00136   VisualDependency(dependee, dependents, showIf),
00137   values_(ValueList(1,value))
00138 {
00139   validateDep();
00140 }
00141 
00142 StringVisualDependency::StringVisualDependency(
00143   RCP<const ParameterEntry> dependee, 
00144   Dependency::ParameterEntryList dependents, 
00145   const ValueList& values,
00146   bool showIf):
00147   VisualDependency(dependee, dependents, showIf),
00148   values_(values)
00149 {
00150   validateDep();
00151 }
00152 
00153 const StringVisualDependency::ValueList& 
00154   StringVisualDependency::getValues() const
00155 {
00156   return values_;
00157 }
00158 
00159 bool StringVisualDependency::getDependeeState() const{
00160   return find(values_.begin(), values_.end(), 
00161     getFirstDependeeValue<std::string>()) != values_.end();
00162 }
00163 
00164 std::string StringVisualDependency::getTypeAttributeValue() const{
00165   return "StringVisualDependency";
00166 }
00167 
00168 void StringVisualDependency::validateDep() const{
00169   TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<std::string>(),
00170     InvalidDependencyException,
00171     "Ay no! The dependee of a "
00172     "String Visual Dependency must be of type " 
00173     << TypeNameTraits<std::string>::name() << std::endl <<
00174     "Type encountered: " << getFirstDependee()->getAny().typeName() << 
00175     std::endl << std::endl);
00176 }
00177 
00178 RCP<StringVisualDependency> 
00179   DummyObjectGetter<StringVisualDependency>::getDummyObject()
00180 {
00181   std::string blahString = "blah";
00182   return rcp(new StringVisualDependency(
00183     rcp(new ParameterEntry(blahString)),
00184     DummyObjectGetter<ParameterEntry>::getDummyObject(),
00185     "i'm a dummy"));
00186 }
00187 
00188 BoolVisualDependency::BoolVisualDependency(
00189   RCP<const ParameterEntry> dependee,
00190   RCP<ParameterEntry> dependent,
00191   bool showIf):
00192   VisualDependency(dependee, dependent, showIf)
00193 {
00194   validateDep();
00195 }
00196 
00197 BoolVisualDependency::BoolVisualDependency(
00198   RCP<const ParameterEntry> dependee, 
00199   Dependency::ParameterEntryList dependents, 
00200   bool showIf):
00201   VisualDependency(dependee, dependents, showIf)
00202 {
00203   validateDep();
00204 }
00205 
00206 bool BoolVisualDependency::getDependeeState() const{
00207   return getFirstDependeeValue<bool>();
00208 }
00209 
00210 std::string BoolVisualDependency::getTypeAttributeValue() const{
00211   return "BoolVisualDependency";
00212 }
00213 
00214 void BoolVisualDependency::validateDep() const{
00215   TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<bool>(),
00216     InvalidDependencyException,
00217     "Ay no! The dependee of a "
00218     "Bool Visual Dependency must be of type " << 
00219     TypeNameTraits<bool>::name() << std::endl <<
00220     "Encountered type: " << getFirstDependee()->getAny().typeName() << 
00221     std::endl << std::endl);
00222 }
00223 
00224 RCP<BoolVisualDependency> 
00225   DummyObjectGetter<BoolVisualDependency>::getDummyObject()
00226 {
00227   return rcp(new BoolVisualDependency(
00228     rcp(new ParameterEntry(true)),
00229     DummyObjectGetter<ParameterEntry>::getDummyObject()));
00230 }
00231 
00232 ConditionVisualDependency::ConditionVisualDependency(
00233   RCP<const Condition> condition,
00234   RCP<ParameterEntry> dependent, 
00235   bool showIf):
00236   VisualDependency(condition->getAllParameters(), dependent, showIf),
00237   condition_(condition)
00238 {
00239   validateDep();
00240 }
00241 
00242 ConditionVisualDependency::ConditionVisualDependency(
00243   RCP<const Condition> condition,
00244   Dependency::ParameterEntryList dependents,
00245   bool showIf):
00246   VisualDependency(condition->getAllParameters(), dependents, showIf),
00247   condition_(condition)
00248 {
00249   validateDep();
00250 }
00251 
00252 RCP<const Condition> ConditionVisualDependency::getCondition() const{
00253   return condition_;
00254 }
00255 
00256 bool ConditionVisualDependency::getDependeeState() const{
00257   return condition_->isConditionTrue();
00258 }
00259 
00260 std::string ConditionVisualDependency::getTypeAttributeValue() const{
00261   return "ConditionVisualDependency";
00262 }
00263 
00264 RCP<ConditionVisualDependency> 
00265   DummyObjectGetter<ConditionVisualDependency>::getDummyObject()
00266 {
00267   return rcp(new ConditionVisualDependency(
00268     DummyObjectGetter<NotCondition>::getDummyObject(),
00269     DummyObjectGetter<ParameterEntry>::getDummyObject()));
00270 }
00271 
00272 StringValidatorDependency::StringValidatorDependency(
00273   RCP<const ParameterEntry> dependee, 
00274   RCP<ParameterEntry> dependent,
00275   ValueToValidatorMap valuesAndValidators, 
00276   RCP<ParameterEntryValidator> defaultValidator):
00277   ValidatorDependency(dependee, dependent),
00278   valuesAndValidators_(valuesAndValidators),
00279   defaultValidator_(defaultValidator)
00280 {
00281   validateDep();
00282 }
00283 
00284 StringValidatorDependency::StringValidatorDependency(
00285   RCP<const ParameterEntry> dependee, 
00286   Dependency::ParameterEntryList dependents,
00287   ValueToValidatorMap valuesAndValidators, 
00288   RCP<ParameterEntryValidator> defaultValidator):
00289   ValidatorDependency(dependee, dependents),
00290   valuesAndValidators_(valuesAndValidators),
00291   defaultValidator_(defaultValidator)
00292 {
00293   validateDep();
00294 }
00295 
00296 const StringValidatorDependency::ValueToValidatorMap& 
00297   StringValidatorDependency::getValuesAndValidators() const
00298 {
00299   return valuesAndValidators_;
00300 }
00301 
00302 RCP<const ParameterEntryValidator> 
00303   StringValidatorDependency::getDefaultValidator() const
00304 {
00305   return defaultValidator_;
00306 }
00307 
00308 void StringValidatorDependency::evaluate(){
00309   std::string currentDependeeValue = getFirstDependeeValue<std::string>();
00310   for(
00311     ParameterEntryList::iterator it = getDependents().begin(); 
00312     it != getDependents().end(); 
00313     ++it)
00314   {
00315     if(
00316       valuesAndValidators_.find(currentDependeeValue) 
00317       == 
00318       valuesAndValidators_.end())
00319     {
00320       (*it)->setValidator(defaultValidator_);
00321     }
00322     else{
00323       (*it)->setValidator(valuesAndValidators_[currentDependeeValue]);
00324     }
00325   }
00326 }
00327 
00328 std::string StringValidatorDependency::getTypeAttributeValue() const{
00329   return "StringValidatorDependency";
00330 }
00331 
00332 void StringValidatorDependency::validateDep() const{
00333   TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<std::string>(),
00334     InvalidDependencyException,
00335     "Ay no! The dependee of a "
00336     "String Validator Dependency must be of type " <<
00337     TypeNameTraits<std::string>::name() << std::endl <<
00338     "Type Encountered: " << getFirstDependee()->getAny().typeName() <<
00339     std::endl << std::endl);
00340 
00341   TEUCHOS_TEST_FOR_EXCEPTION(
00342     valuesAndValidators_.size() < 1,
00343     InvalidDependencyException,
00344     "The valuesAndValidatord map for a string validator dependency must "
00345     "have at least one entry!" << std::endl << std::endl);
00346   ValueToValidatorMap::const_iterator it = valuesAndValidators_.begin();
00347   RCP<const ParameterEntryValidator> firstVali = (it->second);
00348   ++it;
00349   for(; it != valuesAndValidators_.end(); ++it){
00350     TEUCHOS_TEST_FOR_EXCEPTION( typeid(*firstVali) != typeid(*(it->second)),
00351       InvalidDependencyException,
00352       "Ay no! All of the validators in a StringValidatorDependency "
00353       "must have the same type.");
00354    }
00355 }
00356 
00357 
00358 RCP<StringValidatorDependency >
00359   DummyObjectGetter<StringValidatorDependency>::getDummyObject()
00360 {
00361   std::string blahString = "blah";
00362   StringValidatorDependency::ValueToValidatorMap dummyMap;
00363   dummyMap.insert(StringValidatorDependency::ValueToValidatorPair("blah",
00364     DummyObjectGetter<FileNameValidator>::getDummyObject()));
00365   return rcp(new StringValidatorDependency(
00366     rcp(new ParameterEntry(blahString)),
00367     DummyObjectGetter<ParameterEntry>::getDummyObject(),
00368     dummyMap));
00369 }
00370   
00371 BoolValidatorDependency::BoolValidatorDependency(
00372   RCP<const ParameterEntry> dependee,
00373   RCP<ParameterEntry> dependent,
00374   RCP<const ParameterEntryValidator> trueValidator,
00375   RCP<const ParameterEntryValidator> falseValidator):
00376   ValidatorDependency(dependee, dependent),
00377   trueValidator_(trueValidator),
00378   falseValidator_(falseValidator)
00379 {
00380   validateDep();
00381 }
00382 
00383 BoolValidatorDependency::BoolValidatorDependency(
00384   RCP<const ParameterEntry> dependee,
00385   Dependency::ParameterEntryList dependents,
00386   RCP<const ParameterEntryValidator> trueValidator,
00387   RCP<const ParameterEntryValidator> falseValidator):
00388   ValidatorDependency(dependee, dependents),
00389   trueValidator_(trueValidator),
00390   falseValidator_(falseValidator)
00391 {
00392   validateDep();
00393 }
00394 
00395 void BoolValidatorDependency::evaluate(){
00396   bool dependeeValue = getFirstDependeeValue<bool>();
00397   for(
00398     ParameterEntryList::iterator it = getDependents().begin();
00399     it != getDependents().end(); 
00400     ++it)
00401   { 
00402     dependeeValue ? 
00403       (*it)->setValidator(trueValidator_) 
00404       :
00405       (*it)->setValidator(falseValidator_);
00406   }
00407 }
00408 
00409 RCP<const ParameterEntryValidator> 
00410   BoolValidatorDependency::getTrueValidator() const
00411 {
00412   return trueValidator_;
00413 }
00414 
00415 RCP<const ParameterEntryValidator> 
00416   BoolValidatorDependency::getFalseValidator() const
00417 {
00418   return falseValidator_;
00419 }
00420 
00421 std::string BoolValidatorDependency::getTypeAttributeValue() const{
00422   return "BoolValidatorDependency";
00423 }
00424   
00425 
00426 void BoolValidatorDependency::validateDep() const{
00427 
00428   TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<bool>(),
00429     InvalidDependencyException,
00430     "Ay no! The dependee of a "
00431     "Bool Validator Dependency must be of type " <<
00432     TypeNameTraits<bool>::name() << std::endl <<
00433     "Encountered type: " << getFirstDependee()->getAny().typeName() <<
00434     std::endl << std::endl);
00435 
00436   if(!falseValidator_.is_null() && !trueValidator_.is_null()){
00437     TEUCHOS_TEST_FOR_EXCEPTION(typeid(*falseValidator_) != typeid(*trueValidator_),
00438       InvalidDependencyException,
00439       "Ay no! The true and false validators of a Bool Validator Dependency "
00440       "must be the same type! " <<std::endl << std::endl);
00441   }
00442   
00443 }
00444 
00445 RCP<BoolValidatorDependency>
00446   DummyObjectGetter<BoolValidatorDependency>::getDummyObject()
00447 {
00448   return rcp(new BoolValidatorDependency(
00449     rcp(new ParameterEntry(true)),
00450     DummyObjectGetter<ParameterEntry>::getDummyObject(),
00451     null, null));
00452 }
00453 
00454 }
00455 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines