COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ComponentWrapper.hpp
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 
7 #ifndef cf3_Python_Component_hpp
8 #define cf3_Python_Component_hpp
9 
10 #include <boost/python/object.hpp>
11 
13 #include "common/SignalHandler.hpp"
14 
15 namespace cf3 {
16  namespace common { class Component; }
17  template<typename T> class Handle;
18 namespace python {
19 
26 {
27  virtual ~PythonListInterface() {}
28 
30  virtual Uint len() const = 0;
31 
33  virtual boost::python::object get_item(const Uint i) const = 0;
34 
36  virtual void set_item(const Uint i, boost::python::object& value) = 0;
37 
39  virtual std::string to_str() const = 0;
40 };
41 
44 {
45 public:
48 
51 
53  template<typename ComponentT>
54  ComponentT& component()
55  {
56  ComponentT* comp = dynamic_cast<ComponentT*>(&component());
57  if(!comp)
58  throw common::CastingFailed(FromHere(), "Could not cast python wrapped object to type " + ComponentT::type_name());
59 
60  return *comp;
61  }
62 
66  void set_list_interface(PythonListInterface* interface);
67 
70 
71 private:
72  friend boost::python::object wrap_component(const cf3::Handle<common::Component>&);
74  boost::shared_ptr<Implementation> m_implementation; // Shared pointer so we can easily make shallow copies
75 };
76 
78 void def_component();
79 
81 boost::python::object wrap_component(const cf3::Handle<common::Component>& component);
82 
83 } // python
84 } // cf3
85 
87 
88 #endif // cf3_Python_Component_hpp
virtual void set_item(const Uint i, boost::python::object &value)=0
Set item i in the list.
ComponentT & component()
Properly typed access to the wrapped component.
std::string type_name(const boost::python::api::object &python_object)
Definition: PythonAny.cpp:283
PythonListInterface * get_list_interface()
Get the curent list interface, or null if there is none.
void def_component()
Python wrapping for the Component class.
virtual Uint len() const =0
The number of items in the list.
friend boost::python::object wrap_component(const cf3::Handle< common::Component > &)
Wrap the passed component in a python object.
boost::python::object wrap_component(const Handle< common::Component > &component)
Wrap the passed component in a python object.
virtual boost::python::object get_item(const Uint i) const =0
Get item i from the list.
virtual std::string to_str() const =0
Get the whole list as a string.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
ComponentWrapper(const Handle< common::Component > &component)
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
boost::shared_ptr< Implementation > m_implementation
Base class for defining CF components.
Definition: Component.hpp:82
Wrapper class for components.
common::Component & component()
Access to the wrapped component.
void set_list_interface(PythonListInterface *interface)
#define FromHere()
Send comments to:
COOLFluiD Web Admin