Optika_StandardDependencies.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #include "Optika_StandardDependencies.hpp"
00029 #include "Teuchos_StandardParameterEntryValidators.hpp"
00030 #include <QDir>
00031 
00032 namespace Optika{
00033 
00034 VisualDependency::VisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00035 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, bool showIf)
00036 :Dependency(dependeeName, dependeeParentList, dependentName, dependentParentList, Dependency::VisualDep), showIf(showIf){}
00037 
00038 VisualDependency::VisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00039 ParameterParentMap dependents, bool showIf)
00040 :Dependency(dependeeName, dependeeParentList, dependents,  Dependency::VisualDep), showIf(showIf){}
00041 
00042 VisualDependency::VisualDependency(ParameterParentMap dependees, std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, bool showIf)
00043 :Dependency(dependees, dependentName, dependentParentList, Dependency::VisualDep), showIf(showIf){}
00044 
00045 VisualDependency::VisualDependency(ParameterParentMap dependees, ParameterParentMap dependents, bool showIf) 
00046 :Dependency(dependees, dependents, Dependency::VisualDep), showIf(showIf){}
00047 
00048 VisualDependency::VisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00049 ParameterParentMap dependents)
00050 :Dependency(dependeeName, dependeeParentList, dependents,  Dependency::VisualDep){}
00051 
00052 VisualDependency::VisualDependency(ParameterParentMap dependees, std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList)
00053 :Dependency(dependees, dependentName, dependentParentList, Dependency::VisualDep){}
00054 
00055 VisualDependency::VisualDependency(ParameterParentMap dependees, ParameterParentMap dependents) 
00056 :Dependency(dependees, dependents, Dependency::VisualDep){}
00057 
00058 bool VisualDependency::isDependentVisible(){
00059   return dependentVisible;
00060 }
00061 
00062 ValidatorDependency::ValidatorDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00063 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList)
00064 :Dependency(dependeeName, dependeeParentList, dependentName, dependentParentList, Dependency::ValidatorDep){}
00065 
00066 ValidatorDependency::ValidatorDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00067 ParameterParentMap dependents)
00068 :Dependency(dependeeName, dependeeParentList, dependents, Dependency::ValidatorDep){}
00069 
00070 
00071 StringVisualDependency::StringVisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00072 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, std::string value, bool showIf)
00073 :VisualDependency(dependeeName, dependeeParentList, dependentName, dependentParentList, showIf), values(ValueList(1,value)){
00074   validateDep();
00075 }
00076 
00077 StringVisualDependency::StringVisualDependency(std::string dependeeName, std::string dependentName, 
00078 Teuchos::RCP<Teuchos::ParameterList> parentList, std::string value, bool showIf)
00079 :VisualDependency(dependeeName, parentList, dependentName, parentList, showIf), values(ValueList(1,value)){
00080   validateDep();
00081 }
00082 
00083 StringVisualDependency::StringVisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00084 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, const ValueList& values, bool showIf)
00085 :VisualDependency(dependeeName, dependeeParentList, dependentName, dependentParentList, showIf), values(values){
00086   validateDep();
00087 }
00088 
00089 StringVisualDependency::StringVisualDependency(std::string dependeeName, std::string dependentName, 
00090 Teuchos::RCP<Teuchos::ParameterList> parentList, const ValueList& values, bool showIf)
00091 :VisualDependency(dependeeName, parentList, dependentName, parentList, showIf), values(values){
00092   validateDep();
00093 }
00094 
00095 StringVisualDependency::StringVisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList, 
00096 ParameterParentMap dependents, std::string value, bool showIf)
00097 :VisualDependency(dependeeName, dependeeParentList, dependents, showIf), values(ValueList(1,value)){
00098   validateDep();
00099 }
00100 
00101 StringVisualDependency::StringVisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00102 ParameterParentMap dependents, const ValueList& values, bool showIf)
00103 :VisualDependency(dependeeName, dependeeParentList, dependents, showIf), values(values){
00104   validateDep();
00105 }
00106 
00107 void StringVisualDependency::evaluate(){
00108   std::string dependeeValue = getFirstDependeeValue<std::string>();
00109   ValueList::const_iterator result;
00110   result = find(values.begin(), values.end(), dependeeValue);
00111   if((result != values.end() && showIf) || (result==values.end() && !showIf)){
00112     dependentVisible = true;
00113   }
00114   else{
00115     dependentVisible = false;
00116   }
00117 }
00118 
00119 void StringVisualDependency::validateDep(){
00120   /*
00121    * This error should never get thrown, unless someone
00122    * is doing something wonky in a sublcass.
00123    */
00124   if(dependees.size() != 1){
00125     throw InvalidDependencyException("Uh oh. Looks like you tried to make a "
00126     "String Visual Dependency doesn't have exactly one dependee. This is kind of a problem. " 
00127     "You should probably take a look into it. I'm actually amazed you even threw this error. You must "
00128     "be doing some subclassing you sly-dog ;)\n\n" 
00129     "Error: A String Visual Dependency must have exactly 1 dependee. " 
00130     "You have tried to assign it "+ QString::number(dependees.size()).toStdString() + " dependees.\n" 
00131     "Dependees: " + getDependeeNamesString() + "\n" 
00132     "Dependents: " + getDependentNamesString());
00133   }
00134   if(!getFirstDependee()->isType<std::string>()){
00135     throw InvalidDependencyException("Ay no! The dependee of a "
00136     "String Visual Dependency must be of type string.\n"
00137     "Problem dependee: " + getFirstDependeeName() + "\n"
00138     "Actual type: " + getFirstDependee()->getAny().typeName() + "\n"
00139     "Dependent: " + getDependentNamesString());
00140   }
00141 }
00142 
00143 BoolVisualDependency::BoolVisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00144 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, bool showIf)
00145 :VisualDependency(dependeeName, dependeeParentList, dependentName, dependentParentList, showIf){
00146   validateDep();
00147 }
00148 
00149 BoolVisualDependency::BoolVisualDependency(std::string dependeeName, std::string dependentName, 
00150 Teuchos::RCP<Teuchos::ParameterList> parentList, bool showIf)
00151 :VisualDependency(dependeeName, parentList, dependentName, parentList, showIf){
00152   validateDep();
00153 }
00154 
00155 BoolVisualDependency::BoolVisualDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00156 ParameterParentMap dependents, bool showIf)
00157 :VisualDependency(dependeeName, dependeeParentList, dependents, showIf){
00158   validateDep();
00159 }
00160 
00161 void BoolVisualDependency::evaluate(){
00162   bool dependeeValue = getFirstDependeeValue<bool>();
00163   if((dependeeValue && showIf) || (!dependeeValue && !showIf)){
00164     dependentVisible = true;
00165   }
00166   else{
00167     dependentVisible = false;
00168   }
00169 }
00170 
00171 void BoolVisualDependency::validateDep(){
00172   /*
00173    * This error should never get thrown, unless someone
00174    * is doing something wonky in a sublcass.
00175    */
00176   if(dependees.size() != 1){
00177     throw InvalidDependencyException("Uh oh. Looks like you tried to make a "
00178     "Bool Visual Dependency doesn't have exactly one dependee. This is kind of a problem. " 
00179     "You should probably take a look into it. I'm actually amazed you even threw this error. You must "
00180     "be doing some subclassing you sly-dog ;)\n\n" 
00181     "Error: A Bool Visual Dependency must have exactly 1 dependee. " 
00182     "You have tried to assign it "+ QString::number(dependees.size()).toStdString() + " dependees.\n" 
00183     "Dependees: " + getDependeeNamesString() + "\n" 
00184     "Dependents: " + getDependentNamesString());
00185   }
00186 
00187   if(!getFirstDependee()->isType<bool>()){
00188     throw InvalidDependencyException("Ay no! The dependee of a "
00189     "Bool Visual Dependency must be of type bool.\n"
00190     "Problem dependee: " + getFirstDependeeName() + "\n"
00191     "Actual type: " + getFirstDependee()->getAny().typeName() + "\n"
00192     "Dependents: " + getDependentNamesString());
00193   }
00194 }
00195 
00196 ConditionVisualDependency::ConditionVisualDependency(Teuchos::RCP<Condition> condition,
00197 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, bool showIf)
00198 :VisualDependency(condition->getAllParameters(), dependentName, dependentParentList, showIf), condition(condition){
00199   validateDep();
00200 }
00201 
00202 ConditionVisualDependency::ConditionVisualDependency(Teuchos::RCP<Condition> condition, ParameterParentMap dependents, bool showIf)
00203 :VisualDependency(condition->getAllParameters(), dependents, showIf), condition(condition){
00204   validateDep();
00205 }
00206 
00207 void ConditionVisualDependency::evaluate(){
00208   bool conditionState = condition->isConditionTrue();
00209   if((conditionState && showIf) || (!conditionState && !showIf)){
00210     dependentVisible = true;
00211   }
00212   else{
00213     dependentVisible = false;
00214   }
00215 }
00216 
00217 void ConditionVisualDependency::validateDep(){} 
00218 
00219 NumberArrayLengthDependency::NumberArrayLengthDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00220 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, int (*func)(int))
00221 :Dependency(dependeeName, dependeeParentList, dependentName, dependentParentList, Dependency::NumberArrayLengthDep), func(func){
00222   validateDep();
00223 }
00224 
00225 NumberArrayLengthDependency::NumberArrayLengthDependency(std::string dependeeName, std::string dependentName, 
00226 Teuchos::RCP<Teuchos::ParameterList> parentList, int (*func)(int))
00227 :Dependency(dependeeName, parentList, dependentName, parentList, Dependency::NumberArrayLengthDep), func(func){
00228   validateDep();
00229 }
00230 
00231 NumberArrayLengthDependency::NumberArrayLengthDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00232 ParameterParentMap dependents, int (*func)(int))
00233 :Dependency(dependeeName, dependeeParentList, dependents, Dependency::NumberArrayLengthDep), func(func){
00234   validateDep();
00235 }
00236 
00237 int NumberArrayLengthDependency::runFunction(int argument) const{
00238   if(func !=0){
00239     return (*func)(argument);
00240   }
00241   else{
00242     return argument;
00243   }
00244 }
00245 
00246 template <class S>
00247 void NumberArrayLengthDependency::modifyArrayLength(int newLength, Teuchos::ParameterEntry* dependentToModify){
00248   const Teuchos::Array<S> originalArray = Teuchos::any_cast<Teuchos::Array<S> >(dependentToModify->getAny()); 
00249   Teuchos::RCP<const EnhancedNumberValidator<S> > potentialValidator = Teuchos::null;
00250   if(!Teuchos::is_null(dependentToModify->validator())){
00251       potentialValidator = Teuchos::rcp_dynamic_cast<const ArrayNumberValidator<S> >(dependentToModify->validator(),true)->getPrototype();
00252   }
00253   Teuchos::Array<S> newArray;
00254   int i;
00255   for(i=0; i<originalArray.size() && i<newLength; ++i){
00256     newArray.append(originalArray[i]);
00257   }
00258   for(;i<newLength;++i){
00259     if(Teuchos::is_null(potentialValidator)){
00260       newArray.append(0);
00261     }
00262     else{
00263       newArray.append(potentialValidator->min());
00264     }
00265   }
00266   dependentToModify->setValue(newArray, false, dependentToModify->docString(), dependentToModify->validator());
00267 }
00268 
00269 template<>
00270 void NumberArrayLengthDependency::modifyArrayLength<std::string>(int newLength, Teuchos::ParameterEntry* dependentToModify){
00271   const Teuchos::Array<std::string> originalArray = Teuchos::any_cast<Teuchos::Array<std::string> >(dependentToModify->getAny()); 
00272   Teuchos::Array<std::string> newArray;
00273   Teuchos::RCP<const Teuchos::ParameterEntryValidator> validator = dependentToModify->validator();
00274   int i;
00275   for(i=0; i<originalArray.size() && i<newLength; ++i){
00276     newArray.append(originalArray[i]);
00277   }
00278   for(;i<newLength;++i){
00279     if(Teuchos::is_null(validator)){
00280       newArray.append(" ");
00281     }
00282     else if(!Teuchos::is_null(Teuchos::rcp_dynamic_cast<const ArrayFileNameValidator>(validator))){
00283       newArray.append(QDir::homePath().toStdString());
00284     }
00285     else{
00286       newArray.append(validator->validStringValues()->at(0));
00287     }
00288   }
00289   dependentToModify->setValue(newArray, false, dependentToModify->docString(), dependentToModify->validator());
00290 }
00291 
00292 void NumberArrayLengthDependency::evaluate(){
00293   int newLength = runFunction(getFirstDependeeValue<int>());
00294   if(newLength <0){
00295     std::stringstream oss;
00296     std::string msg;
00297     oss << "Ruh Roh Shaggy! Looks like a dependency tried to set the length of the Array(s) in the " <<
00298     getDependentNamesString() << " parameter(s) to a negative number. Silly. You can't have an Array " <<
00299     "with a negative length! You should probably contact the maintainer of this program and " <<
00300     "give him or her the following information: \n\n" <<
00301     "Error:\n" <<
00302     "An attempt was made to set the length of an Array to a negative number by a NumberArrayLengthDependency\n" <<
00303     "Dependency Type: " << QString::number(getType()).toStdString() + "\n" <<
00304     "Problem Dependee: " << getFirstDependeeName() <<
00305     "Problem Dependents: " << getDependentNamesString();
00306     msg = oss.str();
00307     throw Teuchos::Exceptions::InvalidParameterValue(msg);
00308   }
00309   Teuchos::ParameterEntry *currentDependent;
00310   for(ParameterParentMap::const_iterator it = dependents.begin(); it != dependents.end(); ++it){ 
00311     currentDependent = it->second->getEntryPtr(it->first);
00312     QString dependentType = determineArrayType(currentDependent);
00313     if(dependentType.contains(intId)){
00314       modifyArrayLength<int>(newLength, currentDependent);
00315     }
00316     else if(dependentType.contains(shortId)){
00317       modifyArrayLength<short>(newLength, currentDependent);
00318     }
00319     else if(dependentType.contains(doubleId)){
00320       modifyArrayLength<double>(newLength, currentDependent);
00321     }
00322     else if(dependentType.contains(floatId)){
00323       modifyArrayLength<float>(newLength, currentDependent);
00324     }
00325     else if(dependentType.contains(stringId)){
00326       modifyArrayLength<std::string>(newLength, currentDependent);
00327     }
00328   }
00329 }
00330 
00331 void NumberArrayLengthDependency::validateDep(){
00332   /*
00333    * This error should never get thrown, unless someone
00334    * is doing something wonky in a sublcass.
00335    */
00336   if(dependees.size() != 1){
00337     throw InvalidDependencyException("Uh oh. Looks like you tried to make a "
00338     "Number Array Length Dependency doesn't have exactly one currentDependee. This is kind of a problem. " 
00339     "You should probably take a look into it. I'm actually amazed you even threw this error. You must "
00340     "be doing some subclassing you sly-dog ;)\n\n" 
00341     "Error: A Number Array Length Dependency must have exactly 1 currentDependee. " 
00342     "You have tried to assign it "+ QString::number(dependees.size()).toStdString() + " dependees.\n" 
00343     "Dependees: " + getDependeeNamesString() + "\n" 
00344     "Dependents: " + getDependentNamesString());
00345   }
00346 
00347   if(!getFirstDependee()->isType<int>() && !getFirstDependee()->isType<short>()){
00348     throw InvalidDependencyException("Ay no! The currentDependee for an "
00349     "Array Length Dependency must be either of type short or of type int.\n" 
00350     "Problem currentDependee: " + getFirstDependeeName() + "\n" 
00351     "Actual type: " + getFirstDependee()->getAny().typeName() + "\n"
00352     "Dependent: " + getDependentNamesString());
00353   }
00354   Teuchos::ParameterEntry *currentDependent;
00355   for(ParameterParentMap::const_iterator it = dependents.begin(); it != dependents.end(); ++it){ 
00356     currentDependent = it->second->getEntryPtr(it->first);
00357     if(!doesParameterContainArray(currentDependent)){
00358       throw InvalidDependencyException("Ay no! The dependent of an "
00359       "Array Length Dependency must be an array.\n"
00360       "Problem dependent: " + it->first + "\n" 
00361       "Actual type: " + currentDependent->getAny().typeName() + "\n"
00362       "Dependees: " + getDependeeNamesString());
00363     }
00364   }
00365 }
00366 
00367 StringValidatorDependency::StringValidatorDependency(std::string currentDependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00368 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList,
00369 ValueToValidatorMap valuesAndValidators, Teuchos::RCP<Teuchos::ParameterEntryValidator> defaultValidator)
00370 :ValidatorDependency(currentDependeeName, dependeeParentList, dependentName, dependentParentList), defaultValidator(defaultValidator), valuesAndValidators(valuesAndValidators){
00371   validateDep();
00372 }
00373 
00374 StringValidatorDependency::StringValidatorDependency(std::string currentDependeeName, std::string dependentName, 
00375 Teuchos::RCP<Teuchos::ParameterList> parentList, ValueToValidatorMap valuesAndValidators, 
00376 Teuchos::RCP<Teuchos::ParameterEntryValidator> defaultValidator)
00377 :ValidatorDependency(currentDependeeName, parentList, dependentName, parentList), defaultValidator(defaultValidator), valuesAndValidators(valuesAndValidators){
00378   validateDep();
00379 }
00380 
00381 StringValidatorDependency::StringValidatorDependency(std::string currentDependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00382 ParameterParentMap dependents,
00383 ValueToValidatorMap valuesAndValidators, Teuchos::RCP<Teuchos::ParameterEntryValidator> defaultValidator)
00384 :ValidatorDependency(currentDependeeName, dependeeParentList, dependents), defaultValidator(defaultValidator), valuesAndValidators(valuesAndValidators){
00385   validateDep();
00386 }
00387 
00388 void StringValidatorDependency::evaluate(){
00389   std::string currentDependeeValue = getFirstDependeeValue<std::string>();
00390   Teuchos::ParameterEntry *currentDependent;
00391   for(ParameterParentMap::const_iterator it = dependents.begin(); it != dependents.end(); ++it){ 
00392     currentDependent = it->second->getEntryPtr(it->first);
00393     if(valuesAndValidators.find(currentDependeeValue) == valuesAndValidators.end()){
00394       currentDependent->setValidator(defaultValidator);
00395     }
00396     else{
00397       currentDependent->setValidator(valuesAndValidators[currentDependeeValue]);
00398     }
00399   }
00400 }
00401 void StringValidatorDependency::validateDep(){
00402   /*
00403    * This error should never get thrown, unless someone
00404    * is doing something wonky in a sublcass.
00405    */
00406   if(dependees.size() != 1){
00407     throw InvalidDependencyException("Uh oh. Looks like you tried to make a "
00408     "String Validator Dependency doesn't have exactly one dependee. This is kind of a problem. " 
00409     "You should probably take a look into it. I'm actually amazed you even threw this error. You must "
00410     "be doing some subclassing you sly-dog ;)\n\n" 
00411     "Error: A String Validator Dependency must have exactly 1 dependee. "
00412     "You have tried to assign it "+ QString::number(dependees.size()).toStdString() + " dependees.\n"
00413     "Dependees: " + getDependeeNamesString() + "\n"
00414     "Dependents: " + getDependentNamesString());
00415   }
00416 
00417   if(!getFirstDependee()->isType<std::string>()){
00418     throw InvalidDependencyException("Ay no! The dependee of a "
00419     "String Validator Dependency must be of type string.\n"
00420     "Problem dependee: " + getFirstDependeeName() + "\n"
00421     "Actual type: " + getFirstDependee()->getAny().typeName() + "\n"
00422     "Dependent: " + getDependentNamesString());
00423   }
00424   for(ValueToValidatorMap::const_iterator it = valuesAndValidators.begin(); it != valuesAndValidators.end(); ++it){
00425     Teuchos::ParameterEntry *currentDependent;
00426     for(ParameterParentMap::const_iterator it2 = dependents.begin(); it2 != dependents.end(); ++it2){ 
00427       currentDependent = it2->second->getEntryPtr(it2->first);
00428       if(typeid(*(currentDependent->validator().get())) != typeid(*(it->second.get()))){
00429         throw InvalidDependencyException("Ay no! The validator of a dependent of a "
00430         "String Validator Dependency must be the same type as all of the validators "
00431         "in the valuesAndValidators map. "
00432         "Note this means that the dependent must have an initial validator.\n"
00433         "Problem dependent: " + it->first + "\n"
00434         "Validator Type: " + typeid(*(currentDependent->validator())).name() + "\n"
00435         "Problem Map Value: " + it->first + "\n"
00436         "The Validator type associated with the Map Value: " + typeid(*(it->second)).name());
00437       }
00438     }
00439   }
00440 }
00441 
00442 BoolValidatorDependency::BoolValidatorDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00443 std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList,
00444 Teuchos::RCP<const Teuchos::ParameterEntryValidator> trueValidator, Teuchos::RCP<const Teuchos::ParameterEntryValidator> falseValidator)
00445 :ValidatorDependency(dependeeName, dependeeParentList, dependentName, dependentParentList), trueValidator(trueValidator), falseValidator(falseValidator){
00446   validateDep();
00447 }
00448 
00449 BoolValidatorDependency::BoolValidatorDependency(std::string dependeeName, std::string dependentName, 
00450 Teuchos::RCP<Teuchos::ParameterList> parentList, Teuchos::RCP<const Teuchos::ParameterEntryValidator> trueValidator,
00451 Teuchos::RCP<const Teuchos::ParameterEntryValidator> falseValidator)
00452 :ValidatorDependency(dependeeName, parentList, dependentName, parentList), trueValidator(trueValidator), falseValidator(falseValidator){
00453   validateDep();
00454 }
00455 
00456 BoolValidatorDependency::BoolValidatorDependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00457 ParameterParentMap dependents,
00458 Teuchos::RCP<const Teuchos::ParameterEntryValidator> trueValidator, Teuchos::RCP<const Teuchos::ParameterEntryValidator> falseValidator)
00459 :ValidatorDependency(dependeeName, dependeeParentList, dependents), trueValidator(trueValidator), falseValidator(falseValidator){
00460   validateDep();
00461 }
00462 
00463 void BoolValidatorDependency::evaluate(){
00464   bool dependeeValue = getFirstDependeeValue<bool>();
00465   Teuchos::ParameterEntry *currentDependent;
00466   for(ParameterParentMap::const_iterator it = dependents.begin(); it != dependents.end(); ++it){ 
00467     currentDependent = it->second->getEntryPtr(it->first);
00468     dependeeValue ? currentDependent->setValidator(trueValidator) : currentDependent->setValidator(falseValidator);
00469   }
00470 }
00471 
00472 void BoolValidatorDependency::validateDep(){
00473   /*
00474    * This error should never get thrown, unless someone
00475    * is doing something wonky in a sublcass.
00476    */
00477   if(dependees.size() != 1){
00478     throw InvalidDependencyException("Uh oh. Looks like you tried to make a "
00479     "Bool Validator Dependency doesn't have exactly one dependee. This is kind of a problem. " 
00480     "You should probably take a look into it. I'm actually amazed you even threw this error. You must "
00481     "be doing some subclassing you sly-dog ;)\n\n" 
00482     "Error: A Bool Validator Dependency must have exactly 1 dependee. "
00483     "You have tried to assign it "+ QString::number(dependees.size()).toStdString() + " dependees.\n"
00484     "Dependees: " + getDependeeNamesString() + "\n" 
00485     "Dependents: " + getDependentNamesString());
00486   }
00487 
00488   if(!getFirstDependee()->isType<bool>()){
00489     throw InvalidDependencyException("Ay no! The dependee of a "
00490     "Bool Validator Dependency must be of type boolean.\n"
00491     "Problem dependee: " + getFirstDependeeName() + "\n"
00492     "Actual type: " + getFirstDependee()->getAny().typeName() + "\n"
00493     "Dependent: " + getDependentNamesString());
00494   }
00495   Teuchos::ParameterEntry *currentDependent;
00496   for(ParameterParentMap::const_iterator it = dependents.begin(); it != dependents.end(); ++it){ 
00497     currentDependent = it->second->getEntryPtr(it->first);
00498     if(typeid(*(currentDependent->validator().get())) != typeid(*(trueValidator.get()))){
00499       throw InvalidDependencyException("Ay no! The validator of a dependent of a "
00500       "Bool Validator Dependency must be the same type as the \"true\" validator. "
00501       "Note this means that the dependent must have an initial validator.\n"
00502       "Problem dependent: " + it->first + "\n"
00503       "Validator Type: " + typeid(*(currentDependent->validator().get())).name() + "\n"
00504       "Type of the \"true\" validator: " + typeid(*(trueValidator.get())).name());
00505     }
00506     if(typeid(*(currentDependent->validator().get())) != typeid(*(falseValidator.get()))){
00507       throw InvalidDependencyException("Ay no! The validator of a dependent of a "
00508       "Bool Validator Dependency must be the same type as the \"false\" validator. "
00509       "Note this means that the dependent must have an initial validator.\n"
00510       "Problem dependent: " + it->first + "\n"
00511       "Validator Type: " + typeid(*(currentDependent->validator().get())).name() + "\n"
00512       "Type of the \"false\" validator: " + typeid(*(falseValidator.get())).name());
00513     }
00514   }
00515 }
00516 
00517 }
00518 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Generated on Wed Apr 13 10:05:58 2011 for Optika GUI Toolik by  doxygen 1.6.3