COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
tut2.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 
12 
13 #include "common/Log.hpp"
14 #include "common/Component.hpp"
15 #include "common/OptionList.hpp"
16 #include "common/PropertyList.hpp"
17 #include "common/OptionT.hpp"
18 #include "common/Signal.hpp"
19 #include "common/SignalHandler.hpp"
20 
21 #include "tutorial/Hello.hpp"
22 
23 using namespace std;
24 using namespace cf3;
25 using namespace cf3::common;
26 using namespace cf3::tutorial;
27 
29 
30 int main(int argc, char * argv[])
31 {
32  {
33  // Allocate new component
34  boost::shared_ptr<Hello> hello = allocate_component<Hello>("hello");
35 
36 
37  hello->print();
38  // output: Hello world!
39 
40 
41  hello->options().set("message",string("Goodbye world!"));
42  hello->print();
43  // output: Goodbye world!
44 
45  // Access a property from the component
46  CFinfo << "Print is called " << hello->properties().value<int>("print_count") << " times." << CFendl;
47  }
48  // ------------------------------------------------------------------------------------------ //
49 
58 
59  // Following is just to check if signals are implemented correctly.
60  // If this works, the signal can now be called in a dynamic language such as our GUI,
61  // or our python interface
62  {
63  // Build component using the registered builder by its name
64  boost::shared_ptr<Component> hello = build_component("cf3.tutorial.Hello","hello_world");
65  // The default behaviour, with the signature, containing default arguments,
66  // and explains what is expected from the user.
67  SignalArgs args;
68  (*hello->signal("print")->signature())(args);
69  hello->call_signal("print",args);
70  // output: Hello world!
71 
72  // The behaviour where the arguments are given by a user. Note that a signal_signature
73  // is not strictly necessary, but good practise.
74  SignalOptions options(args);
75  options["message"].change_value( string("Goodbye world!") );
76  options.flush();
77  hello->call_signal("print",args);
78  // output: Goodbye world!
79  }
80 
81 
82  return 0;
83 }
#define CFinfo
these are always defined
Definition: Log.hpp:104
Abstracts the use of XML when adding options to a signal frame.
boost::shared_ptr< Component > build_component(const std::string &builder_name, const std::string &name, const std::string &factory_type_name)
Definition: Component.cpp:1200
STL namespace.
#define CFendl
Definition: Log.hpp:109
Manages a set of maps.
Definition: SignalFrame.hpp:31
Holds the Component class, as well as the ComponentIterator class plus some functions related to comp...
int main(int argc, char *argv[])
Definition: tut2.cpp:30
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Contains Tutorial classes and functions.
Definition: Hello.cpp:23
Most basic kernel library.
Definition: Action.cpp:19
Send comments to:
COOLFluiD Web Admin