Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StandardConditions.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 
43 #ifndef TEUCHOS_STANDARDCONDITION_HPP_
44 #define TEUCHOS_STANDARDCONDITION_HPP_
45 
50 #include "Teuchos_Condition.hpp"
51 #include "Teuchos_InvalidConditionException.hpp"
53 #include "Teuchos_StandardFunctionObjects.hpp"
55 #include "Teuchos_ScalarTraits.hpp"
56 
57 
58 namespace Teuchos{
59 
60 
68 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ParameterCondition : public Condition{
69 
70 public:
71 
74 
81 
82  virtual ~ParameterCondition(){}
83 
85 
87 
88 
96  virtual bool evaluateParameter() const = 0;
97 
102  return parameterEntry_.getConst();
103  }
104 
106 
109 
110  bool isConditionTrue() const{
111  return evaluateParameter();
112  }
113 
115  return true;
116  }
117 
118  Dependency::ConstParameterEntryList getAllParameters() const;
119 
121 
122 private:
123 
126 
130  RCP<const ParameterEntry> parameterEntry_;
131 
133 
134 };
135 
144 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT StringCondition : public ParameterCondition{
145 
146 public:
147 
150 
155 
157 
160 
168  StringCondition(RCP<const ParameterEntry> parameter, std::string value);
169 
177 
178  virtual ~StringCondition(){}
179 
181 
184 
185  std::string getTypeAttributeValue() const{
186  return "StringCondition";
187  }
188 
190 
193 
194  bool evaluateParameter() const;
195 
197 
200 
202  const ValueList& getValueList() const{
203  return values_;
204  }
205 
207 
208 private:
209 
212 
216  ValueList values_;
217 
219  void checkParameterType();
220 
222 
223 };
224 
225 
231 template<>
232 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<StringCondition>{
233 
234 public:
235 
238 
242  static RCP<StringCondition> getDummyObject();
243 
245 
246 };
247 
248 
259 template<class T>
261 
262 public:
263 
266 
278  RCP<const ParameterEntry> parameter,
279  RCP<const SimpleFunctionObject<T> > func=null):
280  ParameterCondition(parameter),
281  func_(func)
282  {}
283 
284  virtual ~NumberCondition(){}
285 
287 
290 
291  std::string getTypeAttributeValue() const{
292  return "NumberCondition(" + TypeNameTraits<T>::name() + ")";
293  }
294 
296 
299 
301  bool evaluateParameter() const{
302  T value = getValue<T>(*getParameter());
303  if(!func_.is_null()){
304  value = func_->runFunction(value);
305  }
306  return value > 0;
307  }
308 
310 
313 
318  return func_.getConst();
319  }
320 
322 
323 private:
324 
327 
330 
332 
333 };
334 
335 
341 template<class T>
343 
344 public:
345 
348 
353 
355 
356 };
357 
358 template<class T>
361 {
362  return rcp(new NumberCondition<T>(
364 }
365 
366 
374 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolCondition : public ParameterCondition{
375 
376 public:
377 
380 
387 
388  virtual ~BoolCondition(){}
389 
391 
394 
395  std::string getTypeAttributeValue() const{
396  return "BoolCondition";
397  }
398 
400 
403 
404  bool evaluateParameter() const;
405 
407 
408 };
409 
410 
416 template<>
417 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<BoolCondition>{
418 
419 public:
420 
423 
427  static RCP<BoolCondition > getDummyObject();
428 
430 
431 };
432 
433 
441 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT BoolLogicCondition : public Condition{
442 
443 public:
444 
447 
453  BoolLogicCondition(ConstConditionList& conditions);
454 
459 
461 
465 
473  void addCondition(RCP<const Condition> toAdd);
474 
476 
478 
479 
489  virtual bool applyOperator(bool op1, bool op2) const = 0;
490 
495  inline
496  const ConstConditionList& getConditions() const{
497  return conditions_;
498  }
499 
501 
504 
506  virtual bool isConditionTrue() const;
507 
509  bool containsAtLeasteOneParameter() const;
510 
512  Dependency::ConstParameterEntryList getAllParameters() const;
513 
515 
516 private:
517 
520 
521  /*
522  * \brief A list of conditions on which to perform some logic operation.
523  */
524  ConstConditionList conditions_;
525 
527 
528 };
529 
537 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT OrCondition : public BoolLogicCondition{
538 
539 public:
540 
543 
549  OrCondition(ConstConditionList& conditions);
550 
554  virtual ~OrCondition(){}
555 
557 
560 
561  std::string getTypeAttributeValue() const{
562  return "OrCondition";
563  }
564 
566 
569 
571  bool applyOperator(bool op1, bool op2) const;
572 
574 
575 };
576 
577 
583 template<>
584 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<OrCondition>{
585 
586 public:
587 
590 
594  static RCP<OrCondition> getDummyObject();
595 
597 
598 };
599 
600 
608 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT AndCondition : public BoolLogicCondition{
609 
610 public:
611 
614 
620  AndCondition(ConstConditionList& conditions);
621 
625  virtual ~AndCondition(){}
626 
628 
631 
632  std::string getTypeAttributeValue() const{
633  return "AndCondition";
634  }
635 
637 
638 
641 
643  bool applyOperator(bool op1, bool op2) const;
644 
646 
647 };
648 
649 
655 template<>
656 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<AndCondition>{
657 
658 public:
659 
662 
666  static RCP<AndCondition > getDummyObject();
667 
669 
670 };
671 
672 
680 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT EqualsCondition : public BoolLogicCondition{
681 
682 public:
683 
686 
692  EqualsCondition(ConstConditionList& conditions);
693 
697  virtual ~EqualsCondition(){}
698 
700 
703 
704  std::string getTypeAttributeValue() const{
705  return "EqualsCondition";
706  }
707 
709 
712 
714  bool applyOperator(bool op1, bool op2) const;
715 
717 
718 };
719 
720 
726 template<>
727 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<EqualsCondition>{
728 
729 public:
730 
733 
737  static RCP<EqualsCondition > getDummyObject();
738 
740 
741 };
742 
743 
752 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT NotCondition : public Condition{
753 
754 public:
755 
758 
765 
769  virtual ~NotCondition(){}
770 
772 
775 
778  return childCondition_;
779  }
780 
782 
785 
787  bool isConditionTrue() const;
788 
790  bool containsAtLeasteOneParameter() const;
791 
793  Dependency::ConstParameterEntryList getAllParameters() const;
794 
795  std::string getTypeAttributeValue() const{
796  return "NotCondition";
797  }
798 
800 
801 private:
802 
805 
809  RCP<const Condition> childCondition_;
810 
812 
813 };
814 
815 
821 template<>
822 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT DummyObjectGetter<NotCondition>{
823 
824 public:
825 
828 
832  static RCP<NotCondition> getDummyObject();
833 
835 
836 };
837 
838 } //namespace Teuchos
839 
840 
841 #endif //TEUCHOS_STANDARDCONDITION_HPP_
A Bool Logic Condition that returns the result or perfroming a logical OR on the conditions.
std::string getTypeAttributeValue() const
Get the value that should be used for the condition type attribute when converting a condition to XML...
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
virtual ~NotCondition()
Deconstructs a Not Condition.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
Array< std::string > ValueList
Convience typedef representing an array of strings.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
A Bool Logic Condition that returns the result or perfroming a logical AND on the conditions...
std::string getTypeAttributeValue() const
Get the value that should be used for the condition type attribute when converting a condition to XML...
A Not condition returns the result of performing a logical NOT on a given condition.
An object to determin if a particular set of conditions are occuring.
const ValueList & getValueList() const
Returns the value list being used with this StringCondition.
A Number Condition is a Parameter Condition that evaluates whether or not a number parameter is great...
NumberCondition(RCP< const ParameterEntry > parameter, RCP< const SimpleFunctionObject< T > > func=null)
Constructs a Number Condition.
virtual ~EqualsCondition()
Deconstructs an Equals Condition.
This structure defines some basic traits for a scalar field type.
std::string getTypeAttributeValue() const
Get the value that should be used for the condition type attribute when converting a condition to XML...
RCP< const SimpleFunctionObject< T > > getFunctionObject() const
Gets the funciton this NumberCondition is using. Returns null if the NumberCondition is not using one...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
A String Condition is a Parameter Condition that evaluates whether or not a string parameter has take...
virtual ~OrCondition()
Deconstructs an Or Condition.
A Bool Logic Condition that returns the result or perfroming a logical EQUALS on the conditions...
RCP< const Condition > getChildCondition() const
Retrieve the child condition.
A Bool Condition is a Parameter Condition that evaluates whether or not a Boolean parameter is ture...
virtual ~BoolLogicCondition()
Deconstructor for a BoolLogicCondition.
const ConstConditionList & getConditions() const
Gets a list of all conditions that are a part of this BoolLogicCondition/.
Class for retrieving a dummy object of type T.
A Condition determines whether or not a particular set of conditions are currently occuring...
std::string getTypeAttributeValue() const
Get the value that should be used for the condition type attribute when converting a condition to XML...
Defines basic traits for the scalar field type.
virtual ~AndCondition()
Deconstructs an And Condition.
An abstract parent class for all Bool Logic Conditions.
RCP< const ParameterEntry > getParameter() const
Gets a const pointer to the Parameter being evaluated by this ParameterCondition. ...
bool isConditionTrue() const
Determins whether or not a condition is true.
Smart reference counting pointer class for automatic garbage collection.
std::string getTypeAttributeValue() const
Get the value that should be used for the condition type attribute when converting a condition to XML...
std::string getTypeAttributeValue() const
Get the value that should be used for the condition type attribute when converting a condition to XML...
std::string getTypeAttributeValue() const
Get the value that should be used for the condition type attribute when converting a condition to XML...
An Abstract Base class for all ParameterConditions.
bool containsAtLeasteOneParameter() const
Determines whether or not the evaluation of a parameter occurs somewhere in this condition.