Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Dependency.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teuchos_Dependency.hpp"
11 
12 
13 namespace Teuchos{
14 
15 
16 Dependency::Dependency(
17 ConstParameterEntryList dependees,
18 ParameterEntryList dependents):
19  dependees_(dependees), dependents_(dependents)
20 {
21  checkDependeesAndDependents();
22  createConstDependents();
23 }
24 
25 Dependency::Dependency(
26  ConstParameterEntryList dependees,
27  RCP<ParameterEntry> dependent):
28  dependees_(dependees),
29  dependents_(ParameterEntryList(&dependent, &dependent+1))
30 {
31  checkDependeesAndDependents();
32  createConstDependents();
33 }
34 
35 
36 Dependency::Dependency(
38  ParameterEntryList dependents):
39  dependees_(ConstParameterEntryList(&dependee, &dependee+1)),
40  dependents_(dependents)
41 {
42  checkDependeesAndDependents();
43  createConstDependents();
44 }
45 
46 Dependency::Dependency(
48  RCP<ParameterEntry> dependent):
49  dependees_(ConstParameterEntryList(&dependee, &dependee+1)),
50  dependents_(ParameterEntryList(&dependent, &dependent+1))
51 {
52  checkDependeesAndDependents();
53  createConstDependents();
54 }
55 
56 
57 void Dependency::createConstDependents(){
58  for(
59  ParameterEntryList::iterator it = dependents_.begin();
60  it != dependents_.end();
61  ++it)
62  {
63  constDependents_.insert(it->getConst());
64  }
65 }
66 
67 void Dependency::print(std::ostream& out) const{
68  out << "Type: " << getTypeAttributeValue() << std::endl;
69  out << "Number of dependees: " << dependees_.size() << std::endl;
70  out << "Number of dependents: " << dependents_.size() << std::endl;
71 
72 }
73 
74 void Dependency::checkDependeesAndDependents(){
75  ConstParameterEntryList::iterator it1 = dependees_.begin();
76  for(; it1 != dependees_.end(); ++it1){
77  TEUCHOS_TEST_FOR_EXCEPTION((*it1).is_null(),
79  "Cannot have a null dependee!" << std::endl << std::endl);
80  }
81 
82  ParameterEntryList::iterator it2 = dependents_.begin();
83  for(; it2 != dependents_.end(); ++it2){
84  TEUCHOS_TEST_FOR_EXCEPTION((*it2).is_null(),
85  InvalidDependencyException,
86  "Cannot have a null dependent!" << std::endl << std::endl);
87  }
88 }
89 
90 } //namespace Teuchos
91 
std::set< RCP< const ParameterEntry >, RCPConstComp > ConstParameterEntryList
A list of dependents.
std::set< RCP< ParameterEntry >, RCPComp > ParameterEntryList
A list of Dependees.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
virtual void print(std::ostream &out) const
prints out information about the dependency.
virtual std::string getTypeAttributeValue() const =0
Returns the string to be used for the value of the type attribute when converting the dependency to X...
Smart reference counting pointer class for automatic garbage collection.