Optika GUI Toolik Version of the Day
Optika_Dependency.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_Dependency.hpp"
00029 
00030 namespace Optika{
00031 
00032 Dependency::Dependency(ParameterParentMap& dependees, ParameterParentMap& dependents, Type type):
00033   type(type)
00034 {
00035   intitializeDependeesAndDependents(dependees,dependents);
00036 }
00037 
00038 Dependency::Dependency(ParameterParentMap& dependees, std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, Type type):
00039   type(type)
00040 {
00041   ParameterParentMap dependents;
00042   dependents.insert(std::pair<std::string, Teuchos::RCP<Teuchos::ParameterList> >(dependentName, dependentParentList));
00043   intitializeDependeesAndDependents(dependees,dependents);
00044 }
00045 
00046 Dependency::Dependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00047   ParameterParentMap& dependents, Type type):
00048   type(type)
00049 {
00050   ParameterParentMap dependees;
00051   dependees.insert(std::pair<std::string, Teuchos::RCP<Teuchos::ParameterList> >(dependeeName, dependeeParentList));
00052   intitializeDependeesAndDependents(dependees,dependents);
00053 }
00054   
00055 Dependency::Dependency(std::string dependeeName, Teuchos::RCP<Teuchos::ParameterList> dependeeParentList,
00056   std::string dependentName, Teuchos::RCP<Teuchos::ParameterList> dependentParentList, Type type):
00057   type(type)
00058 {
00059   ParameterParentMap dependees;
00060   dependees.insert(std::pair<std::string, Teuchos::RCP<Teuchos::ParameterList> >(dependeeName, dependeeParentList));
00061   ParameterParentMap dependents;
00062   dependents.insert(std::pair<std::string, Teuchos::RCP<Teuchos::ParameterList> >(dependentName, dependentParentList));
00063   intitializeDependeesAndDependents(dependees, dependents);
00064 }
00065 
00066 void Dependency::intitializeDependeesAndDependents(ParameterParentMap& dependees, ParameterParentMap& dependents){
00067   ParameterParentMap::iterator it;
00068   for(it = dependees.begin(); it != dependees.end(); ++it){
00069     if(it->second->getEntryPtr(it->first) == NULL){
00070       throw InvalidDependencyException("The Dependee Parameter \"" + it->first + "\" does "
00071       "not exist in the given Dependent Parent List \"" + it->second->name() + "\"."
00072       "\n\nBummer! Maybe you just mispelled something? Why not go back and check to make sure "
00073       "you've got the names of the dependee and the depedent right? "
00074       "It might also be that you just didn't specify the correct parent lists for the dependent and "
00075       "dependee. Either way, I'm sure it's just a simple mistake. "
00076       "You're a great programmer, I'm sure you'll figure it out! :)");
00077     }
00078     else{
00079       this->dependees.insert(std::pair<std::string, Teuchos::RCP<Teuchos::ParameterList> >(it->first, it->second));
00080       dependeeNames.insert(it->first);
00081     }
00082   }
00083   for(it = dependents.begin(); it != dependents.end(); ++it){
00084     if(it->second->getEntryPtr(it->first) == NULL){
00085       throw InvalidDependencyException("The Dependent Parameter \"" + it->first + "\" does "
00086       "not exist in the given Dependent Parent List \"" + it->second->name() + "\"."
00087       "\n\nBummer! Maybe you just mispelled something? Why not go back and check to make sure "
00088       "you've got the names of the dependee and the depedent right? "
00089       "It might also be that you just didn't specify the correct parent lists for the dependent and "
00090       "dependee. Either way, I'm sure it's just a simple mistake. "
00091       "You're a great programmer, I'm sure you'll figure it out! :)");
00092     }
00093     else{
00094       this->dependents.insert(std::pair<std::string, Teuchos::RCP<Teuchos::ParameterList> >(it->first, it->second));
00095       dependentNames.insert(it->first);
00096     }
00097   }
00098 }
00099 
00100 
00101 Dependency::ParameterParentMap Dependency::getDependees() const{
00102   return dependees;
00103 }
00104 
00105 Dependency::ParameterParentMap Dependency::getDependents() const{
00106   return dependents;
00107 }
00108 
00109 std::set<std::string> Dependency::getDependeeNames() const{
00110   return dependeeNames;
00111 }
00112 
00113 std::string Dependency::getDependeeName(const Teuchos::ParameterEntry* dependee) const{
00114   for(ParameterParentMap::const_iterator it = dependees.begin(); it != dependees.end(); ++it){
00115     if(dependee == it->second->getEntryPtr(it->first)){
00116       return it->first;
00117     }
00118   }
00119   throw InvalidDependencyException("Fooey! Looks like you tried to get the name of a dependee parameter "
00120   "that isn't actually a dependee parameter for this dependency. Make sure you're giving this funciton "
00121   "the right pointer. Maybe the information below can help you out.\n\n"
00122   "Error: Dependency does not contain specified dependee parameter.\n"
00123   "Dependee(s): " + getDependeeNamesString() + "\n"
00124   "Dependent(s): " + getDependentNamesString() + "\n");
00125   return "";
00126 }
00127 
00128 
00129 std::set<std::string> Dependency::getDependentNames() const{
00130   return dependentNames;
00131 }
00132 
00133 std::string Dependency::getDependeeNamesString() const{
00134   std::string names = "";
00135   for(std::set<std::string>::const_iterator it=dependeeNames.begin(); it != dependeeNames.end(); ++it){
00136     names += *it + " ";
00137   }
00138   return names;
00139 }
00140 
00141 std::string Dependency::getDependentNamesString() const{
00142   std::string names = "";
00143   for(std::set<std::string>::const_iterator it=dependentNames.begin(); it != dependentNames.end(); ++it){
00144     names += *it + " ";
00145   }
00146   return names;
00147 }
00148 
00149 Dependency::Type Dependency::getType() const{
00150   return type;
00151 }
00152 
00153 bool Dependency::doesListContainList(Teuchos::RCP<Teuchos::ParameterList> parentList, Teuchos::RCP<Teuchos::ParameterList> listToFind){
00154   if(parentList.get() == listToFind.get()){
00155     return true;
00156   }
00157   else{
00158     for(Teuchos::ParameterList::ConstIterator it = parentList->begin(); it!=parentList->end(); ++it){
00159       if(it->second.isList()){
00160         if(doesListContainList(sublist(parentList, it->first,true), listToFind)){
00161           return true;
00162         }
00163       }
00164     }
00165   }
00166   return false;
00167 }
00168 
00169 }
00170 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends