COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ActionDirector.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
8 #include "common/Builder.hpp"
10 #include "common/Log.hpp"
11 #include "common/OptionArray.hpp"
12 #include "common/OptionT.hpp"
13 #include "common/OptionURI.hpp"
15 #include "common/PropertyList.hpp"
16 #include "common/OptionList.hpp"
17 #include "common/PropertyList.hpp"
18 #include "common/Signal.hpp"
19 #include "common/URI.hpp"
20 
21 #include "common/XML/Protocol.hpp"
23 
24 #include "ActionDirector.hpp"
25 
26 namespace cf3 {
27 namespace common {
28 
30 
32 
33 ActionDirector::ActionDirector(const std::string& name): Action(name)
34 {
35  options().add("disabled_actions", std::vector<std::string>())
36  .description("Names of the actions to disable")
37  .pretty_name("Disabled Actions")
38  .attach_trigger(boost::bind(&ActionDirector::trigger_disabled_actions, this));
39 }
40 
42 {
43  BOOST_FOREACH(Component& child, *this)
44  {
45  Handle<Action> action(follow_link(child));
46 
47  const bool disabled = is_not_null(action) ? is_disabled(action->name()) : true;
48  if(!disabled)
49  {
50  CFdebug << name() << ": Executing action " << action->uri().path() << CFendl;
51  action->execute();
52  }
53  else
54  {
55  if(is_not_null(action))
56  CFdebug << name() << ": Skipping disabled action " << action->uri().path() << CFendl;
57  else
58  CFdebug << name() << ": Doing nothing for non-action " << child.uri().path() << CFendl;
59  }
60  }
61 }
62 
63 bool ActionDirector::is_disabled(const std::string& name)
64 {
65  return m_disabled_actions.count(name);
66 }
67 
69 {
70  m_disabled_actions.clear();
71 
72  std::vector<std::string> disabled_actions = options().value< std::vector<std::string> >("disabled_actions");
73  m_disabled_actions.insert(disabled_actions.begin(), disabled_actions.end());
74 }
75 
77 {
78  action_director.add_link(action);
79  return action_director;
80 }
81 
82 ActionDirector& operator<<(ActionDirector& action_director, const boost::shared_ptr<Action>& action)
83 {
84  action_director.add_component(action);
85  return action_director;
86 }
87 
88 const boost::shared_ptr< ActionDirector >& operator<<(const boost::shared_ptr< ActionDirector >& action_director, Action& action)
89 {
90  action_director->add_link(action);
91  return action_director;
92 }
93 
94 const boost::shared_ptr< ActionDirector >& operator<<(const boost::shared_ptr< ActionDirector >& action_director, const boost::shared_ptr< Action >& action)
95 {
96  action_director->add_component(action);
97  return action_director;
98 }
99 
100 
102 
103 } // common
104 } // cf3
std::string name(ComponentWrapper &self)
ComponentBuilder< ActionDirector, Action, LibCommon > ActionDirector_Builder
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
Helper class to create the Builder and place it in the factory.
Definition: Builder.hpp:212
std::string path() const
Definition: URI.cpp:253
URI uri() const
Construct the full path.
Definition: Component.cpp:248
const std::string & name() const
Access the name of the component.
Definition: Component.hpp:146
std::set< std::string > m_disabled_actions
bool is_disabled(const std::string &name)
True if the passed action is disabled.
#define CFendl
Definition: Log.hpp:109
ActionDirector & operator<<(ActionDirector &action_director, Action &action)
Add a link to the passed action as a child.
Holds the ComponentIterator class.
Uniform Resource Identifier (see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) ...
Top-level namespace for coolfluid.
Definition: Action.cpp:18
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
Definition: OptionList.hpp:104
ActionDirector(const std::string &name)
void add_link(Component &linked_component)
Definition: Component.cpp:317
Component that executes an action. Implementation of the IAction interface as a component, exposing the execute function as a signal.
Definition: Action.hpp:21
virtual void execute()
Execute all active child actions.
OptionList & options()
Definition: Component.cpp:856
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
Definition: OptionList.hpp:45
#define CFdebug
Definition: Log.hpp:107
Base class for defining CF components.
Definition: Component.hpp:82
Handle< Component > follow_link(const Handle< Component > &link_or_comp)
Follow links or return the component itself if it's not a link.
Definition: Link.cpp:84
bool is_not_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:147
Send comments to:
COOLFluiD Web Admin