Optika_StandardConditions.hpp

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 #ifndef OPTIKA_STANDARDCONDITION_HPP_
00029 #define OPTIKA_STANDARDCONDITION_HPP_
00030 #include "Optika_Condition.hpp"
00031 #include "Optika_InvalidConditionException.hpp"
00032 #include "Teuchos_ParameterList.hpp"
00033 
00034 namespace Optika{
00035 
00043 class BinaryLogicalCondition : public Condition{
00044 public:
00050   BinaryLogicalCondition(ConditionList& conditions);
00051 
00055   virtual ~BinaryLogicalCondition(){}
00056   
00064   virtual void addCondition(Teuchos::RCP<Condition> toAdd);
00065 
00066   virtual bool isConditionTrue()=0;
00067 
00068   bool containsAtLeasteOneParameter();
00069 
00070   Dependency::ParameterParentMap getAllParameters();
00071 
00072 protected:
00073   /*
00074    * A list of conditions on which to perform some logic operation.
00075    */
00076   ConditionList conditions;
00077 };
00078 
00083 class OrCondition : public BinaryLogicalCondition{
00084 public:
00090   OrCondition(ConditionList& conditions);
00091 
00095   virtual ~OrCondition(){}
00096 
00097   bool isConditionTrue();
00098 };
00099 
00104 class AndCondition : public BinaryLogicalCondition{
00105 public:
00111   AndCondition(ConditionList& conditions);
00112 
00116   virtual ~AndCondition(){}
00117 
00118   bool isConditionTrue();
00119 };
00120 
00125 class EqualsCondition : public BinaryLogicalCondition{
00126 public:
00132   EqualsCondition(ConditionList& conditions);
00133 
00137   virtual ~EqualsCondition(){}
00138 
00139   bool isConditionTrue();
00140 };
00141 
00147 class NotCondition : public Condition{
00148 public:
00154   NotCondition(Teuchos::RCP<Condition> condition);
00155 
00159   virtual ~NotCondition(){}
00160 
00161   bool isConditionTrue();
00162 
00163   bool containsAtLeasteOneParameter();
00164 
00165   Dependency::ParameterParentMap getAllParameters();
00166 
00167 private:
00171   Teuchos::RCP<Condition> condition;
00172 };
00173 
00180 class ParameterCondition : public Condition{
00181 public:
00182 
00193   ParameterCondition(std::string parameterName, Teuchos::RCP<Teuchos::ParameterList> parentList, bool whenParamEqualsValue);
00194 
00195   virtual ~ParameterCondition(){}
00196 
00197   virtual bool isConditionTrue()=0;
00198 
00199   bool containsAtLeasteOneParameter();
00200 
00201   Dependency::ParameterParentMap getAllParameters();
00202 
00203 protected:
00207   std::string parameterName;
00208 
00212   Teuchos::RCP<Teuchos::ParameterList> parentList;
00213 
00217   bool whenParamEqualsValue;
00218 
00222   Teuchos::ParameterEntry* parameter;
00223 };
00224 
00230 class StringCondition : public ParameterCondition{
00231 public:
00235   typedef Teuchos::Array<std::string> ValueList; 
00236 
00248   StringCondition(std::string parameterName, Teuchos::RCP<Teuchos::ParameterList> parentList, std::string value, bool whenParamEqualsValue=true);
00249 
00261   StringCondition(std::string parameterName, Teuchos::RCP<Teuchos::ParameterList> parentList, ValueList values, bool whenParamEqualsValue=true);
00262 
00263   virtual ~StringCondition(){}
00264 
00265   bool isConditionTrue();
00266 
00267 private:
00271   ValueList values;
00272 };
00273 
00280 template<class T>
00281 class NumberCondition : public ParameterCondition{
00282 public:
00296   NumberCondition(std::string parameterName, Teuchos::RCP<Teuchos::ParameterList> parentList, T (*func)(T)=0, bool whenParamEqualsValue=true):
00297     ParameterCondition(parameterName, parentList, whenParamEqualsValue), func(func)
00298   {
00299     if(!parameter->isType<int>()
00300     && !parameter->isType<short>()
00301     && !parameter->isType<double>()
00302     && !parameter->isType<float>()){
00303       std::string expectedTypeName = typeid(T).name();
00304       throw InvalidConditionException("The parameter of a "
00305       "Number Condition must be of a supported number type!\n"
00306       "Expected type: " + expectedTypeName + "\n" 
00307       "Actual type: " + parameter->getAny().typeName());
00308     }
00309   }
00310     
00325   NumberCondition(std::string parameterName, Teuchos::RCP<Teuchos::ParameterList> parentList, bool whenParamEqualsValue=true):
00326     ParameterCondition(parameterName, parentList, whenParamEqualsValue), func(0){}
00327 
00328   virtual ~NumberCondition(){}
00329 
00330   bool isConditionTrue(){
00331     bool toReturn = (runFunction(Teuchos::getValue<T>(*parameter)) > 0);
00332     return whenParamEqualsValue ? toReturn : !toReturn;
00333   }
00334 
00335 private:
00336   T (*func)(T);   
00337 
00344   T runFunction(T argument) const{
00345     if(func !=0)
00346       return (*func)(argument);
00347     else
00348       return argument;
00349   } 
00350 };
00351 
00356 class BoolCondition : public ParameterCondition{
00357 public:
00368   BoolCondition(std::string parameterName, Teuchos::RCP<Teuchos::ParameterList> parentList, bool whenParamEqualsValue=true);
00369 
00370   virtual ~BoolCondition(){}
00371 
00372   bool isConditionTrue();
00373 };
00374 
00375 }
00376 #endif //OPTIKA_STANDARDCONDITION_HPP_
 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