|
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 00044 #include "Teuchos_StandardConditions.hpp" 00045 00046 namespace Teuchos{ 00047 00048 ParameterCondition::ParameterCondition(RCP<const ParameterEntry> parameter): 00049 parameterEntry_(parameter) 00050 { 00051 TEUCHOS_TEST_FOR_EXCEPTION(is_null(parameter), 00052 InvalidConditionException, 00053 "Parameter conditions can't be given a null parameter" << 00054 std::endl << std::endl); 00055 } 00056 00057 Dependency::ConstParameterEntryList 00058 ParameterCondition::getAllParameters() const 00059 { 00060 Dependency::ConstParameterEntryList toReturn; 00061 toReturn.insert(getParameter()); 00062 return toReturn; 00063 } 00064 00065 BoolLogicCondition::BoolLogicCondition(ConstConditionList& conditions): 00066 conditions_(conditions) 00067 { 00068 TEUCHOS_TEST_FOR_EXCEPTION(conditions_.size() ==0, 00069 InvalidConditionException, 00070 "You must provide at least one condition " 00071 "when you're constructing a BoolLogicCondition. " 00072 << std::endl << std::endl << 00073 "Error: Empty condition list given to a BoolLogicCondition " 00074 "constructor."); 00075 } 00076 00077 00078 void BoolLogicCondition::addCondition(RCP<const Condition> toAdd){ 00079 conditions_.append(toAdd); 00080 } 00081 00082 bool BoolLogicCondition::isConditionTrue() const{ 00083 ConstConditionList::const_iterator it = conditions_.begin(); 00084 bool toReturn = (*it)->isConditionTrue(); 00085 ++it; 00086 for(;it != conditions_.end(); ++it){ 00087 toReturn = applyOperator(toReturn,(*it)->isConditionTrue()); 00088 } 00089 return toReturn; 00090 } 00091 00092 bool BoolLogicCondition::containsAtLeasteOneParameter() const{ 00093 for( 00094 ConstConditionList::const_iterator it=conditions_.begin(); 00095 it!=conditions_.end(); 00096 ++it) 00097 { 00098 if((*it)->containsAtLeasteOneParameter()){ 00099 return true; 00100 } 00101 } 00102 return false; 00103 } 00104 00105 Dependency::ConstParameterEntryList 00106 BoolLogicCondition::getAllParameters() const{ 00107 Dependency::ConstParameterEntryList toReturn; 00108 Dependency::ConstParameterEntryList currentList; 00109 for( 00110 ConstConditionList::const_iterator it = conditions_.begin(); 00111 it != conditions_.end(); 00112 ++it) 00113 { 00114 currentList = (*it)->getAllParameters(); 00115 toReturn.insert(currentList.begin(), currentList.end()); 00116 } 00117 return toReturn; 00118 } 00119 00120 OrCondition::OrCondition(ConstConditionList& conditions): 00121 BoolLogicCondition(conditions){} 00122 00123 bool OrCondition::applyOperator(bool op1, bool op2) const{ 00124 return op1 || op2; 00125 } 00126 00127 RCP<OrCondition> DummyObjectGetter<OrCondition>::getDummyObject(){ 00128 Condition::ConstConditionList dummyList; 00129 dummyList.append(DummyObjectGetter<BoolCondition>::getDummyObject()); 00130 return rcp(new OrCondition(dummyList)); 00131 } 00132 00133 AndCondition::AndCondition(ConstConditionList& conditions): 00134 BoolLogicCondition(conditions){} 00135 00136 bool AndCondition::applyOperator(bool op1, bool op2) const{ 00137 return op1 && op2; 00138 } 00139 00140 RCP<AndCondition> DummyObjectGetter<AndCondition>::getDummyObject(){ 00141 Condition::ConstConditionList dummyList; 00142 dummyList.append(DummyObjectGetter<BoolCondition>::getDummyObject()); 00143 return rcp(new AndCondition(dummyList)); 00144 } 00145 00146 EqualsCondition::EqualsCondition(ConstConditionList& conditions): 00147 BoolLogicCondition(conditions){} 00148 00149 bool EqualsCondition::applyOperator(bool op1, bool op2) const{ 00150 return op1 == op2; 00151 } 00152 00153 RCP<EqualsCondition> DummyObjectGetter<EqualsCondition>::getDummyObject(){ 00154 Condition::ConstConditionList dummyList; 00155 dummyList.append(DummyObjectGetter<BoolCondition>::getDummyObject()); 00156 return rcp(new EqualsCondition(dummyList)); 00157 } 00158 00159 NotCondition::NotCondition(RCP<const Condition> childCondition): 00160 childCondition_(childCondition) 00161 { 00162 TEUCHOS_TEST_FOR_EXCEPTION(childCondition_.is_null(), 00163 InvalidConditionException, 00164 "OOOOOOOOPppppps! Looks like you tried " 00165 "to give me " 00166 "a null pointer when you were making a not conditon. " 00167 "That's a no no. Go back and " 00168 "checkout your not conditions and make sure you didn't " 00169 "give any of them a null pointer " 00170 "as an argument to the constructor." << std::endl << std::endl << 00171 "Error: Null pointer given to NotCondition constructor."); 00172 } 00173 00174 bool NotCondition::isConditionTrue() const{ 00175 return (!childCondition_->isConditionTrue()); 00176 } 00177 00178 bool NotCondition::containsAtLeasteOneParameter() const{ 00179 return childCondition_->containsAtLeasteOneParameter(); 00180 } 00181 00182 Dependency::ConstParameterEntryList NotCondition::getAllParameters() const{ 00183 return childCondition_->getAllParameters(); 00184 } 00185 00186 RCP<NotCondition> DummyObjectGetter<NotCondition>::getDummyObject(){ 00187 return rcp(new NotCondition( 00188 DummyObjectGetter<BoolCondition>::getDummyObject())); 00189 } 00190 00191 StringCondition::StringCondition( 00192 RCP<const ParameterEntry> parameter, 00193 std::string value): 00194 ParameterCondition(parameter), 00195 values_(ValueList(1,value)) 00196 { 00197 checkParameterType(); 00198 } 00199 00200 StringCondition::StringCondition( 00201 RCP<const ParameterEntry> parameter, 00202 ValueList values): 00203 ParameterCondition(parameter), 00204 values_(values) 00205 { 00206 checkParameterType(); 00207 } 00208 00209 void StringCondition::checkParameterType(){ 00210 TEUCHOS_TEST_FOR_EXCEPTION(!getParameter()->isType<std::string>(), 00211 InvalidConditionException, 00212 "The parameter of a String Condition " 00213 "must be of type string." << std::endl << 00214 "Expected type: " << TypeNameTraits<std::string>::name() << std::endl << 00215 "Actual type: " << getParameter()->getAny().typeName() << 00216 std::endl << std::endl); 00217 } 00218 00219 00220 bool StringCondition::evaluateParameter() const{ 00221 return find( 00222 values_.begin(), values_.end(), 00223 getValue<std::string>(*getParameter())) != values_.end(); 00224 } 00225 00226 RCP<StringCondition> DummyObjectGetter<StringCondition>::getDummyObject(){ 00227 std::string empty = ""; 00228 return rcp(new StringCondition(rcp(new ParameterEntry(empty)), empty)); 00229 } 00230 00231 BoolCondition::BoolCondition(RCP<const ParameterEntry> parameter): 00232 ParameterCondition(parameter) 00233 { 00234 TEUCHOS_TEST_FOR_EXCEPTION(!getParameter()->isType<bool>(), 00235 InvalidConditionException, 00236 "The parameter of a Bool Condition " 00237 "must be of type " << TypeNameTraits<bool>::name() << std::endl << 00238 "Expected type: Bool" << std::endl << 00239 "Actual type: " << getParameter()->getAny().typeName() << 00240 std::endl << std::endl); 00241 } 00242 00243 bool BoolCondition::evaluateParameter() const{ 00244 return getValue<bool>(*getParameter()); 00245 } 00246 00247 RCP<BoolCondition> DummyObjectGetter<BoolCondition>::getDummyObject(){ 00248 return rcp(new BoolCondition(rcp(new ParameterEntry(true)))); 00249 } 00250 00251 00252 } //namespace Teuchos 00253
1.7.6.1