|
Teuchos - Trilinos Tools Package
Version of the Day
|
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 #ifndef TEUCHOS_STANDARDCONDITION_HPP_ 00044 #define TEUCHOS_STANDARDCONDITION_HPP_ 00045 00050 #include "Teuchos_Condition.hpp" 00051 #include "Teuchos_InvalidConditionException.hpp" 00052 #include "Teuchos_ParameterList.hpp" 00053 #include "Teuchos_StandardFunctionObjects.hpp" 00054 #include "Teuchos_DummyObjectGetter.hpp" 00055 #include "Teuchos_ScalarTraits.hpp" 00056 00057 00058 namespace Teuchos{ 00059 00060 00068 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ParameterCondition : public Condition{ 00069 00070 public: 00071 00074 00080 ParameterCondition(RCP<const ParameterEntry> parameter); 00081 00082 virtual ~ParameterCondition(){} 00083 00085 00087 00088 00096 virtual bool evaluateParameter() const = 0; 00097 00101 inline RCP<const ParameterEntry> getParameter() const{ 00102 return parameterEntry_.getConst(); 00103 } 00104 00106 00109 00110 bool isConditionTrue() const{ 00111 return evaluateParameter(); 00112 } 00113 00114 bool containsAtLeasteOneParameter() const{ 00115 return true; 00116 } 00117 00118 Dependency::ConstParameterEntryList getAllParameters() const; 00119 00121 00122 private: 00123 00126 00130 RCP<const ParameterEntry> parameterEntry_; 00131 00133 00134 }; 00135 00144 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringCondition : public ParameterCondition{ 00145 00146 public: 00147 00150 00154 typedef Array<std::string> ValueList; 00155 00157 00160 00168 StringCondition(RCP<const ParameterEntry> parameter, std::string value); 00169 00176 StringCondition(RCP<const ParameterEntry> parameter, ValueList values); 00177 00178 virtual ~StringCondition(){} 00179 00181 00184 00185 std::string getTypeAttributeValue() const{ 00186 return "StringCondition"; 00187 } 00188 00190 00193 00194 bool evaluateParameter() const; 00195 00197 00200 00202 const ValueList& getValueList() const{ 00203 return values_; 00204 } 00205 00207 00208 private: 00209 00212 00216 ValueList values_; 00217 00219 void checkParameterType(); 00220 00222 00223 }; 00224 00225 00231 template<> 00232 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<StringCondition>{ 00233 00234 public: 00235 00238 00242 static RCP<StringCondition> getDummyObject(); 00243 00245 00246 }; 00247 00248 00259 template<class T> 00260 class NumberCondition : public ParameterCondition{ 00261 00262 public: 00263 00266 00277 NumberCondition( 00278 RCP<const ParameterEntry> parameter, 00279 RCP<const SimpleFunctionObject<T> > func=null): 00280 ParameterCondition(parameter), 00281 func_(func) 00282 {} 00283 00284 virtual ~NumberCondition(){} 00285 00287 00290 00291 std::string getTypeAttributeValue() const{ 00292 return "NumberCondition(" + TypeNameTraits<T>::name() + ")"; 00293 } 00294 00296 00299 00301 bool evaluateParameter() const{ 00302 T value = getValue<T>(*getParameter()); 00303 if(!func_.is_null()){ 00304 value = func_->runFunction(value); 00305 } 00306 return value > 0; 00307 } 00308 00310 00313 00317 RCP<const SimpleFunctionObject<T> > getFunctionObject() const{ 00318 return func_.getConst(); 00319 } 00320 00322 00323 private: 00324 00327 00329 RCP<const SimpleFunctionObject<T> > func_; 00330 00332 00333 }; 00334 00335 00341 template<class T> 00342 class DummyObjectGetter<NumberCondition<T> >{ 00343 00344 public: 00345 00348 00352 static RCP<NumberCondition<T> > getDummyObject(); 00353 00355 00356 }; 00357 00358 template<class T> 00359 RCP<NumberCondition<T> > 00360 DummyObjectGetter<NumberCondition<T> >::getDummyObject() 00361 { 00362 return rcp(new NumberCondition<T>( 00363 rcp(new ParameterEntry(ScalarTraits<T>::zero())))); 00364 } 00365 00366 00374 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolCondition : public ParameterCondition{ 00375 00376 public: 00377 00380 00386 BoolCondition(RCP<const ParameterEntry> parameter); 00387 00388 virtual ~BoolCondition(){} 00389 00391 00394 00395 std::string getTypeAttributeValue() const{ 00396 return "BoolCondition"; 00397 } 00398 00400 00403 00404 bool evaluateParameter() const; 00405 00407 00408 }; 00409 00410 00416 template<> 00417 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<BoolCondition>{ 00418 00419 public: 00420 00423 00427 static RCP<BoolCondition > getDummyObject(); 00428 00430 00431 }; 00432 00433 00441 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolLogicCondition : public Condition{ 00442 00443 public: 00444 00447 00453 BoolLogicCondition(ConstConditionList& conditions); 00454 00458 virtual ~BoolLogicCondition(){} 00459 00461 00465 00473 void addCondition(RCP<const Condition> toAdd); 00474 00476 00478 00479 00489 virtual bool applyOperator(bool op1, bool op2) const = 0; 00490 00495 inline 00496 const ConstConditionList& getConditions() const{ 00497 return conditions_; 00498 } 00499 00501 00504 00506 virtual bool isConditionTrue() const; 00507 00509 bool containsAtLeasteOneParameter() const; 00510 00512 Dependency::ConstParameterEntryList getAllParameters() const; 00513 00515 00516 private: 00517 00520 00521 /* 00522 * \brief A list of conditions on which to perform some logic operation. 00523 */ 00524 ConstConditionList conditions_; 00525 00527 00528 }; 00529 00537 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT OrCondition : public BoolLogicCondition{ 00538 00539 public: 00540 00543 00549 OrCondition(ConstConditionList& conditions); 00550 00554 virtual ~OrCondition(){} 00555 00557 00560 00561 std::string getTypeAttributeValue() const{ 00562 return "OrCondition"; 00563 } 00564 00566 00569 00571 bool applyOperator(bool op1, bool op2) const; 00572 00574 00575 }; 00576 00577 00583 template<> 00584 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<OrCondition>{ 00585 00586 public: 00587 00590 00594 static RCP<OrCondition> getDummyObject(); 00595 00597 00598 }; 00599 00600 00608 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT AndCondition : public BoolLogicCondition{ 00609 00610 public: 00611 00614 00620 AndCondition(ConstConditionList& conditions); 00621 00625 virtual ~AndCondition(){} 00626 00628 00631 00632 std::string getTypeAttributeValue() const{ 00633 return "AndCondition"; 00634 } 00635 00637 00638 00641 00643 bool applyOperator(bool op1, bool op2) const; 00644 00646 00647 }; 00648 00649 00655 template<> 00656 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<AndCondition>{ 00657 00658 public: 00659 00662 00666 static RCP<AndCondition > getDummyObject(); 00667 00669 00670 }; 00671 00672 00680 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT EqualsCondition : public BoolLogicCondition{ 00681 00682 public: 00683 00686 00692 EqualsCondition(ConstConditionList& conditions); 00693 00697 virtual ~EqualsCondition(){} 00698 00700 00703 00704 std::string getTypeAttributeValue() const{ 00705 return "EqualsCondition"; 00706 } 00707 00709 00712 00714 bool applyOperator(bool op1, bool op2) const; 00715 00717 00718 }; 00719 00720 00726 template<> 00727 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<EqualsCondition>{ 00728 00729 public: 00730 00733 00737 static RCP<EqualsCondition > getDummyObject(); 00738 00740 00741 }; 00742 00743 00752 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT NotCondition : public Condition{ 00753 00754 public: 00755 00758 00764 NotCondition(RCP<const Condition> condition); 00765 00769 virtual ~NotCondition(){} 00770 00772 00775 00777 RCP<const Condition> getChildCondition() const{ 00778 return childCondition_; 00779 } 00780 00782 00785 00787 bool isConditionTrue() const; 00788 00790 bool containsAtLeasteOneParameter() const; 00791 00793 Dependency::ConstParameterEntryList getAllParameters() const; 00794 00795 std::string getTypeAttributeValue() const{ 00796 return "NotCondition"; 00797 } 00798 00800 00801 private: 00802 00805 00809 RCP<const Condition> childCondition_; 00810 00812 00813 }; 00814 00815 00821 template<> 00822 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<NotCondition>{ 00823 00824 public: 00825 00828 00832 static RCP<NotCondition> getDummyObject(); 00833 00835 00836 }; 00837 00838 } //namespace Teuchos 00839 00840 00841 #endif //TEUCHOS_STANDARDCONDITION_HPP_
1.7.6.1