Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Teuchos_StandardConditionXMLConverters.hpp
Go to the documentation of this file.
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 #ifndef TEUCHOS_STANDARDCONDITIONXMLCONVERTERS_HPP
00043 #define TEUCHOS_STANDARDCONDITIONXMLCONVERTERS_HPP
00044 
00049 #include "Teuchos_FunctionObjectXMLConverterDB.hpp"
00050 #include "Teuchos_ConditionXMLConverter.hpp"
00051 #include "Teuchos_StandardConditions.hpp"
00052 
00053 
00054 namespace Teuchos {
00055 
00056 
00059 class BoolLogicConditionConverter : public ConditionXMLConverter{
00060 
00061 public:
00062 
00065 
00073   virtual RCP<BoolLogicCondition> getSpecificBoolLogicCondition(
00074     Condition::ConstConditionList& conditions) const = 0;
00075  
00077 
00080 
00082   virtual RCP<Condition> convertXML(
00083     const XMLObject& xmlObj,
00084     const XMLParameterListReader::EntryIDsMap& entryIDsMap) const;
00085 
00087   void convertCondition(
00088     const RCP<const Condition> condition, 
00089     XMLObject& xmlObj,
00090     const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const;
00091   
00093 
00094 };
00095 
00105 class OrConditionConverter : public BoolLogicConditionConverter{
00106 
00107 public:
00108 
00111 
00113   RCP<BoolLogicCondition> getSpecificBoolLogicCondition(
00114     Condition::ConstConditionList& conditions) const;
00115  
00117 
00118 };
00119 
00129 class AndConditionConverter : public BoolLogicConditionConverter{
00130 
00131 public:
00132 
00135 
00137   RCP<BoolLogicCondition> getSpecificBoolLogicCondition(
00138     Condition::ConstConditionList& conditions) const;
00139  
00141 
00142 };
00143 
00144 
00154 class EqualsConditionConverter : public BoolLogicConditionConverter{
00155 
00156 public:
00157 
00160 
00162   RCP<BoolLogicCondition> getSpecificBoolLogicCondition(
00163     Condition::ConstConditionList& conditions) const;
00164  
00166 
00167 };
00168 
00178 class NotConditionConverter : public ConditionXMLConverter{
00179 
00180 public:
00181 
00184 
00186   virtual RCP<Condition> convertXML(
00187     const XMLObject& xmlObj,
00188     const XMLParameterListReader::EntryIDsMap& entryIDsMap) const;
00189 
00191   void convertCondition(
00192     const RCP<const Condition> condition, 
00193     XMLObject& xmlObj,
00194     const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const;
00195 
00197 
00198 };
00199 
00202 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ParameterConditionConverter : public ConditionXMLConverter{
00203 
00204 public:
00205 
00208 
00217   virtual RCP<ParameterCondition> getSpecificParameterCondition(
00218     const XMLObject& xmlObj,
00219     RCP<ParameterEntry> parameterEntry) const = 0;
00220   
00228   virtual void addSpecificXMLTraits(
00229     RCP<const ParameterCondition> condition, XMLObject& xmlObj) const = 0;
00230  
00232 
00235 
00237   virtual RCP<Condition> convertXML(
00238     const XMLObject& xmlObj,
00239     const XMLParameterListReader::EntryIDsMap& entryIDsMap) const;
00240 
00242   void convertCondition(
00243     const RCP<const Condition> condition, 
00244     XMLObject& xmlObj,
00245     const XMLParameterListWriter::EntryIDsMap& entryIDsMap) const;
00246   
00248  
00249 private:
00250 
00253  
00255   static const std::string& getParameterEntryIdAttributeName(){
00256     static const std::string parameterEntryIdAttributeName = "parameterId";
00257     return parameterEntryIdAttributeName;
00258   }
00259   
00261   
00262 };
00263 
00275 class StringConditionConverter : public ParameterConditionConverter{
00276 
00277 public:
00278 
00281 
00283   RCP<ParameterCondition> getSpecificParameterCondition(
00284     const XMLObject& xmlObj,
00285     RCP<ParameterEntry> parameterEntry) const;
00286  
00288   void addSpecificXMLTraits(
00289     RCP<const ParameterCondition> condition, XMLObject& xmlObj) const;
00290  
00292 
00293 private:
00294 
00296   static const std::string& getValuesTagName(){
00297     static const std::string valuesTagName = "Values";
00298     return valuesTagName;
00299   }
00300 
00302   static const std::string& getStringTagName(){
00303     static const std::string stringTagName = "String";
00304     return stringTagName;
00305   }
00306 
00308   static const std::string& getStringValueAttributeName(){
00309     static const std::string stringValueAttributeName = "value";
00310     return stringValueAttributeName;
00311   }
00312 
00313 
00314 };
00315 
00323 class BoolConditionConverter : public ParameterConditionConverter{
00324 
00325 public:
00326 
00329 
00331   RCP<ParameterCondition> getSpecificParameterCondition(
00332     const XMLObject& xmlObj,
00333     RCP<ParameterEntry> parameterEntry) const;
00334  
00336   void addSpecificXMLTraits(
00337     RCP<const ParameterCondition> condition, XMLObject& xmlObj) const;
00338 
00340 
00341 };
00342 
00352 template<class T>
00353 class NumberConditionConverter : public ParameterConditionConverter{
00354 
00355 public:
00356 
00359 
00361   RCP<ParameterCondition> getSpecificParameterCondition(
00362     const XMLObject& xmlObj,
00363     RCP<ParameterEntry> parameterEntry) const;
00364 
00366   void addSpecificXMLTraits(
00367     RCP<const ParameterCondition> condition, XMLObject& xmlObj) const;
00368  
00370 
00371 };
00372 
00373 template<class T>
00374 RCP<ParameterCondition> 
00375 NumberConditionConverter<T>::getSpecificParameterCondition(
00376   const XMLObject& xmlObj,
00377   RCP<ParameterEntry> parameterEntry) const
00378 {
00379   int functionTag = xmlObj.findFirstChild(FunctionObject::getXMLTagName());
00380   if(functionTag == -1){
00381     return rcp(new NumberCondition<T>(parameterEntry));
00382   }
00383   else{
00384     RCP<FunctionObject> functionObj = 
00385       FunctionObjectXMLConverterDB::convertXML(xmlObj.getChild(functionTag));
00386     RCP<SimpleFunctionObject<T> > castedFunction = 
00387       rcp_dynamic_cast<SimpleFunctionObject<T> >(functionObj);
00388     return rcp(new NumberCondition<T>(parameterEntry, castedFunction));
00389   }
00390 }
00391 
00392 template<class T>
00393 void NumberConditionConverter<T>::addSpecificXMLTraits(
00394   RCP<const ParameterCondition> condition, XMLObject& xmlObj) const
00395 {
00396   RCP<const NumberCondition<T> > castedCondition = 
00397     rcp_dynamic_cast<const NumberCondition<T> >(condition);
00398   RCP<const SimpleFunctionObject<T> > functionObject =
00399     castedCondition->getFunctionObject();
00400   if(!functionObject.is_null()){
00401     XMLObject functionXML = 
00402       FunctionObjectXMLConverterDB::convertFunctionObject(functionObject);
00403     xmlObj.addChild(functionXML);
00404   }
00405 }
00406 
00407 
00408 
00409 } // namespace Teuchos
00410 
00411 
00412 #endif // TEUCHOS_STANDARDCONDITIONXMLCONVERTERS_HPP
00413 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines