Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
Teuchos_StandardDependencies.cpp
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 
46 #ifdef TEUCHOS_HAVE_QT
47  #include <QDir>
48 #endif
49 
50 
51 namespace Teuchos{
52 
53 
55  RCP<const ParameterEntry> dependee,
56  RCP<ParameterEntry> dependent,
57  bool showIf):
58  Dependency(dependee, dependent),
59  showIf_(showIf){}
60 
63  ParameterEntryList dependents,
64  bool showIf):
65  Dependency(dependee, dependents),
66  showIf_(showIf){}
67 
69  ConstParameterEntryList dependees,
70  RCP<ParameterEntry> dependent,
71  bool showIf):
72  Dependency(dependees, dependent),
73  showIf_(showIf){}
74 
76  ConstParameterEntryList dependees,
77  ParameterEntryList dependents,
78  bool showIf):
79  Dependency(dependees, dependents),
80  showIf_(showIf){}
81 
83  return dependentVisible_;
84 }
85 
87  return showIf_;
88 }
89 
91  if((getDependeeState() && showIf_) || (!getDependeeState() && !showIf_)){
92  dependentVisible_ = true;
93  }
94  else{
95  dependentVisible_ = false;
96  }
97 }
98 
100  RCP<const ParameterEntry> dependee,
101  RCP<ParameterEntry> dependent):
102  Dependency(dependee, dependent){}
103 
105  RCP<const ParameterEntry> dependee,
106  ParameterEntryList dependents):
107  Dependency(dependee, dependents){}
108 
110  RCP<const ParameterEntry> dependee,
111  RCP<ParameterEntry> dependent,
112  std::string value,
113  bool showIf):
114  VisualDependency(dependee, dependent, showIf),
115  values_(ValueList(1,value))
116 {
117  validateDep();
118 }
119 
121  RCP<const ParameterEntry> dependee,
122  RCP<ParameterEntry> dependent,
123  const ValueList& values,
124  bool showIf):
125  VisualDependency(dependee, dependent, showIf),
126  values_(values)
127 {
128  validateDep();
129 }
130 
132  RCP<const ParameterEntry> dependee,
133  Dependency::ParameterEntryList dependents,
134  const std::string& value,
135  bool showIf):
136  VisualDependency(dependee, dependents, showIf),
137  values_(ValueList(1,value))
138 {
139  validateDep();
140 }
141 
143  RCP<const ParameterEntry> dependee,
144  Dependency::ParameterEntryList dependents,
145  const ValueList& values,
146  bool showIf):
147  VisualDependency(dependee, dependents, showIf),
148  values_(values)
149 {
150  validateDep();
151 }
152 
155 {
156  return values_;
157 }
158 
160  return find(values_.begin(), values_.end(),
161  getFirstDependeeValue<std::string>()) != values_.end();
162 }
163 
165  return "StringVisualDependency";
166 }
167 
169  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<std::string>(),
171  "Ay no! The dependee of a "
172  "String Visual Dependency must be of type "
173  << TypeNameTraits<std::string>::name() << std::endl <<
174  "Type encountered: " << getFirstDependee()->getAny().typeName() <<
175  std::endl << std::endl);
176 }
177 
180 {
181  std::string blahString = "blah";
182  return rcp(new StringVisualDependency(
183  rcp(new ParameterEntry(blahString)),
185  "i'm a dummy"));
186 }
187 
189  RCP<const ParameterEntry> dependee,
190  RCP<ParameterEntry> dependent,
191  bool showIf):
192  VisualDependency(dependee, dependent, showIf)
193 {
194  validateDep();
195 }
196 
198  RCP<const ParameterEntry> dependee,
199  Dependency::ParameterEntryList dependents,
200  bool showIf):
201  VisualDependency(dependee, dependents, showIf)
202 {
203  validateDep();
204 }
205 
207  return getFirstDependeeValue<bool>();
208 }
209 
211  return "BoolVisualDependency";
212 }
213 
215  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<bool>(),
217  "Ay no! The dependee of a "
218  "Bool Visual Dependency must be of type " <<
219  TypeNameTraits<bool>::name() << std::endl <<
220  "Encountered type: " << getFirstDependee()->getAny().typeName() <<
221  std::endl << std::endl);
222 }
223 
226 {
227  return rcp(new BoolVisualDependency(
228  rcp(new ParameterEntry(true)),
230 }
231 
233  RCP<const Condition> condition,
234  RCP<ParameterEntry> dependent,
235  bool showIf):
236  VisualDependency(condition->getAllParameters(), dependent, showIf),
237  condition_(condition)
238 {
239  validateDep();
240 }
241 
243  RCP<const Condition> condition,
245  bool showIf):
246  VisualDependency(condition->getAllParameters(), dependents, showIf),
247  condition_(condition)
248 {
249  validateDep();
250 }
251 
253  return condition_;
254 }
255 
257  return condition_->isConditionTrue();
258 }
259 
261  return "ConditionVisualDependency";
262 }
263 
266 {
267  return rcp(new ConditionVisualDependency(
270 }
271 
273  RCP<const ParameterEntry> dependee,
274  RCP<ParameterEntry> dependent,
276  RCP<ParameterEntryValidator> defaultValidator):
277  ValidatorDependency(dependee, dependent),
278  valuesAndValidators_(valuesAndValidators),
279  defaultValidator_(defaultValidator)
280 {
281  validateDep();
282 }
283 
285  RCP<const ParameterEntry> dependee,
288  RCP<ParameterEntryValidator> defaultValidator):
289  ValidatorDependency(dependee, dependents),
290  valuesAndValidators_(valuesAndValidators),
291  defaultValidator_(defaultValidator)
292 {
293  validateDep();
294 }
295 
298 {
299  return valuesAndValidators_;
300 }
301 
304 {
305  return defaultValidator_;
306 }
307 
309  std::string currentDependeeValue = getFirstDependeeValue<std::string>();
310  for(
311  ParameterEntryList::iterator it = getDependents().begin();
312  it != getDependents().end();
313  ++it)
314  {
315  if(
316  valuesAndValidators_.find(currentDependeeValue)
317  ==
318  valuesAndValidators_.end())
319  {
320  (*it)->setValidator(defaultValidator_);
321  }
322  else{
323  (*it)->setValidator(valuesAndValidators_[currentDependeeValue]);
324  }
325  }
326 }
327 
329  return "StringValidatorDependency";
330 }
331 
333  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<std::string>(),
335  "Ay no! The dependee of a "
336  "String Validator Dependency must be of type " <<
337  TypeNameTraits<std::string>::name() << std::endl <<
338  "Type Encountered: " << getFirstDependee()->getAny().typeName() <<
339  std::endl << std::endl);
340 
342  valuesAndValidators_.size() < 1,
344  "The valuesAndValidatord map for a string validator dependency must "
345  "have at least one entry!" << std::endl << std::endl);
346  ValueToValidatorMap::const_iterator it = valuesAndValidators_.begin();
347  RCP<const ParameterEntryValidator> firstVali = (it->second);
348  ++it;
349  for(; it != valuesAndValidators_.end(); ++it){
350  TEUCHOS_TEST_FOR_EXCEPTION( typeid(*firstVali) != typeid(*(it->second)),
352  "Ay no! All of the validators in a StringValidatorDependency "
353  "must have the same type.");
354  }
355 }
356 
357 
360 {
361  std::string blahString = "blah";
365  return rcp(new StringValidatorDependency(
366  rcp(new ParameterEntry(blahString)),
368  dummyMap));
369 }
370 
372  RCP<const ParameterEntry> dependee,
373  RCP<ParameterEntry> dependent,
375  RCP<const ParameterEntryValidator> falseValidator):
376  ValidatorDependency(dependee, dependent),
377  trueValidator_(trueValidator),
378  falseValidator_(falseValidator)
379 {
380  validateDep();
381 }
382 
384  RCP<const ParameterEntry> dependee,
387  RCP<const ParameterEntryValidator> falseValidator):
388  ValidatorDependency(dependee, dependents),
389  trueValidator_(trueValidator),
390  falseValidator_(falseValidator)
391 {
392  validateDep();
393 }
394 
396  bool dependeeValue = getFirstDependeeValue<bool>();
397  for(
398  ParameterEntryList::iterator it = getDependents().begin();
399  it != getDependents().end();
400  ++it)
401  {
402  dependeeValue ?
403  (*it)->setValidator(trueValidator_)
404  :
405  (*it)->setValidator(falseValidator_);
406  }
407 }
408 
411 {
412  return trueValidator_;
413 }
414 
417 {
418  return falseValidator_;
419 }
420 
422  return "BoolValidatorDependency";
423 }
424 
425 
427 
428  TEUCHOS_TEST_FOR_EXCEPTION(!getFirstDependee()->isType<bool>(),
430  "Ay no! The dependee of a "
431  "Bool Validator Dependency must be of type " <<
432  TypeNameTraits<bool>::name() << std::endl <<
433  "Encountered type: " << getFirstDependee()->getAny().typeName() <<
434  std::endl << std::endl);
435 
436  if(!falseValidator_.is_null() && !trueValidator_.is_null()){
439  "Ay no! The true and false validators of a Bool Validator Dependency "
440  "must be the same type! " <<std::endl << std::endl);
441  }
442 
443 }
444 
447 {
448  return rcp(new BoolValidatorDependency(
449  rcp(new ParameterEntry(true)),
451  null, null));
452 }
453 
454 }
455 
RCP< const ParameterEntryValidator > getDefaultValidator() const
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
RCP< ParameterEntryValidator > defaultValidator_
The default validator to be used if a request is made for a value that does not appear in the valuesA...
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
std::pair< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorPair
Conveniece typedef.
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
An abstract parent class for all visual dependencies.
ParameterEntryList & getDependents()
Gets the dependents of the dependency.
BoolValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, RCP< const ParameterEntryValidator > trueValidator, RCP< const ParameterEntryValidator > falseValidator=null)
Constructs a BoolValidatorDependency.
RCP< const ParameterEntryValidator > trueValidator_
The validators to be used when the dependee is either true or false.
bool dependentVisible_
Whether or not the dependent is currently visible.
void validateDep() const
Validates the dependency to make sure it&#39;s valid/has been setup properly. If subclassing, this fucntion should be called in the new subclasses constructor.
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
This object is held as the "value" in the Teuchos::ParameterList std::map.
StringValidatorDependency::ValueToValidatorMap valuesAndValidators
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool getShowIf() const
Get&#39;s the value of the showIf variable.
const ValueToValidatorMap & getValuesAndValidators() const
retrieve a const reference to the ValueToValidator map being used by this StringValidatorDependency ...
VisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, bool showIf=getShowIfDefaultValue())
Constructs a VisualDependency.
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
This class represents a depndency between elements in a Parameter List.
RCP< const ParameterEntryValidator > falseValidator_
const ValueList & getValues() const
get the List of values the dependee will be checked against.
RCP< const ParameterEntryValidator > getFalseValidator() const
Gets the false validator.
bool showIf_
Whether or not to show the dependent if the dependee is set to the value.
RCP< const Condition > condition_
The Condition to determine whether or not the dependent is displayed.
BoolVisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, bool showIf=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
ValueToValidatorMap valuesAndValidators_
A map associating particular dependee values with validators that could be placed on the dependent...
StringVisualDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, std::string value, bool showIf=true)
Constructs a StringVisualDependency.
RCP< const ParameterEntryValidator > getTrueValidator() const
Gets the true validator.
ValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent)
Constructs a ValidatorDependency.
A collection of standard dependencies.
RCP< const ParameterEntry > getFirstDependee() const
Gets the first dependee in the dependees list. This is a convience function.
virtual bool getDependeeState() const =0
Get the state of the dependee in order to evaluate the dependency.
RCP< const Condition > getCondition() const
Gets the condition being used in this dependency.
Default traits class that just returns typeid(T).name().
Class for retrieving a dummy object of type T.
ConditionVisualDependency(RCP< const Condition > condition, RCP< ParameterEntry > dependent, bool showIf=true)
An abstract base class for all validator dependencies.
StringValidatorDependency(RCP< const ParameterEntry > dependee, RCP< ParameterEntry > dependent, ValueToValidatorMap valuesAndValidators, RCP< ParameterEntryValidator > defaultValidator=null)
Constructs a StringValidatorDependency.
Smart reference counting pointer class for automatic garbage collection.
bool isDependentVisible() const
Determines whether or not the dependent is currently visible.
iterator begin()
void validateDep() const
Validates the dependency to make sure it&#39;s valid/has been setup properly. If subclassing, this fucntion should be called in the new subclasses constructor.