ObserverWrap.cxx
Go to the documentation of this file.
1 
12 #ifdef HAVE_CONFIG_H
13 // for old python
14 #include "config.h"
15 #endif
16 
17 // include first to avoid _POSIX_C_SOURCE warning.
18 #include <boost/python.hpp>
19 
20 #include "ObserverWrap.h"
21 
22 #include "pattern/Observable.h"
23 
24 #include <iostream>
25 
26 using std::string;
27 
28 using namespace boost::python;
29 
30 
31 namespace hippodraw {
32  namespace Python {
33  void
35  {
36  class_ < ObserverWrap,
37  std::auto_ptr<ObserverWrap>,
38  boost::noncopyable >
39  ( "Observer",
40  "The base class for classes that can be targets of Observable\n"
41  "update messages.",
42  no_init )
43  ;
44 
45  class_ < Observable >
46  ( "Observable",
47  "The base class for classes that can be target of an Observer\n"
48  "object.",
49  init <> () )
50  ;
51  }
52  } // namespace Python
53 } // namespace hippodraw
54 
55 using namespace hippodraw;
56 
59 ObserverWrap::
60 ObserverWrap ( PyObject * self )
61  : hippodraw::Observer (),
62  m_self ( self )
63 {
64 }
65 
68  : hippodraw::Observer (),
69  m_self ( 0 )
70 {
71 }
73 ObserverWrap ( const Observer & ow )
74  : hippodraw::Observer ( ow ),
75  m_self ( 0 )
76 {
77 }
78 
79 template <class T>
80 object
82 get_owner(T* ) const // me
83 {
84  // Use secret interface to get the Python object
85  // that owns *this. I guess I will have to make that
86  // interface public. -- Dave Abrahams
87  return
88 object ( handle<> ( borrowed ( detail::wrapper_base_::get_owner(*this))));
89 }
90 
93 void
95 update ( const Observable * obs )
96 {
97 #ifndef HAVE_OLD_PYTHON
98  PyGILState_STATE state = PyGILState_Ensure ();
99 
100  try {
101  object self = get_owner ( this );
102  call_method < void, const Observable * > ( self.ptr(), "update", obs );
103  } catch ( error_already_set & ) {
104  std::cout << "ObserverWrap::update: caught error_already_set"
105  << std::endl;
106  PyErr_Print();
107  handle_exception();
108  }
109 
110  PyGILState_Release ( state );
111 #endif
112 }

Generated for HippoDraw Class Library by doxygen