py_object Class Reference

Python object class. More...

#include <py_object.h>

Collaboration diagram for py_object:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 py_object ()
 Default constructor.
 ~py_object ()
 Destructor.
void clear ()
 Resets the script to it's post-constructor state.
PyObject creation
bool create_instance (string file, string classname, PyObject *args=NULL)
 Creates an instance of a Python class.
bool reload_instance (string file, string classname, PyObject *args=NULL)
 Similar to create_instance, except that it will reload the module from disk, in case it has been changed in the meantime.
PyObject method calling
PyObject * call_method_ret (const string &name, PyObject *args=NULL) const
 Call a method of this object.
void call_method (const string &name, PyObject *args=NULL) const
 Call a method of this object.
void run (PyObject *args=NULL)
 Calls the run () method of this object.
PyObject member access
bool has_attribute (const std::string &name)
 Tests whether the object contains a certain attribute (i.e.
PyObject * get_attribute (const string &name) const
 Returns a new reference to an attribute of this object.
s_int32 get_attribute_int (const string &name)
 Returns the given attribute as integer value.
string get_attribute_string (const string &name)
 Returns the given attribute as string value.
void set_attribute (const string &name, PyObject *value)
 Assign a new attribute to the module, overriding an existing attribute of the same name.
void set_attribute_int (const string &name, s_int32 value)
 Assign a new integer attribute to the module, overriding an existing attribute of the same name.
void set_attribute_string (const string &name, const string &value)
 Assign a new string attribute to the module, overriding an existing attribute of the same name.
Member access
PyObject * get_instance (const bool &incref=true) const
 Direct access to the instance object.
std::string class_name () const
 Returns the class name of this object.
std::string file_name () const
 Returns the file name of this object.

Protected Attributes

PyObject * Instance
 The python class instance wrapped by py_object.


Detailed Description

Python object class.

Use this class to create instances of Python classes contained in Python modules, then control their execution. You can pass an argument tuple to the class constructor and to any method you want to run. It is further possible to access and change attributes of the Python instance.

Definition at line 41 of file py_object.h.


Constructor & Destructor Documentation

py_object::py_object (  ) 

Default constructor.

Definition at line 29 of file py_object.cc.

py_object::~py_object (  ) 

Destructor.

Definition at line 36 of file py_object.cc.


Member Function Documentation

void py_object::clear (  ) 

Resets the script to it's post-constructor state.

Definition at line 42 of file py_object.cc.

bool py_object::create_instance ( string  file,
string  classname,
PyObject *  args = NULL 
)

Creates an instance of a Python class.

Parameters:
file file name of the module to use.
classname name of the class to import.
args Python tuple containing the arguments to pass to the Python class constructor.

Definition at line 53 of file py_object.cc.

bool py_object::reload_instance ( string  file,
string  classname,
PyObject *  args = NULL 
)

Similar to create_instance, except that it will reload the module from disk, in case it has been changed in the meantime.

Mainly interesting for script development or tools like dlgedit.

Parameters:
file file name of the module to use.
classname name of the class to import.
args Python tuple containing the arguments to pass to the Python class constructor.

Definition at line 64 of file py_object.cc.

PyObject * py_object::call_method_ret ( const string &  name,
PyObject *  args = NULL 
) const

Call a method of this object.

Parameters:
name name of the method to call.
args Python tuple containing the arguments to pass to the method.
Returns:
the return value of the method as PyObject. Needs to be Py_DECREF'd when no longer needed.

Definition at line 108 of file py_object.cc.

void py_object::call_method ( const string &  name,
PyObject *  args = NULL 
) const [inline]

Call a method of this object.

Parameters:
name name of the method to call.
args Python tuple containing the arguments to pass to the method.

Definition at line 109 of file py_object.h.

void py_object::run ( PyObject *  args = NULL  )  [inline]

Calls the run () method of this object.

Equivalent to call_method ("run", args);

Parameters:
args Python tuple containing the arguments to pass to the method.

Definition at line 121 of file py_object.h.

bool py_object::has_attribute ( const std::string &  name  ) 

Tests whether the object contains a certain attribute (i.e.

method or variable).

Parameters:
name Name of the attribute to test for
Returns:
true if the attribute exists, false otherwise.

Definition at line 130 of file py_object.cc.

PyObject * py_object::get_attribute ( const string &  name  )  const

Returns a new reference to an attribute of this object.

Parameters:
name Name of the attribute to access
Returns:
New reference to the attribute or NULL on error

Definition at line 139 of file py_object.cc.

s_int32 py_object::get_attribute_int ( const string &  name  ) 

Returns the given attribute as integer value.

Parameters:
name Name of the attribute to access
Returns:
An integer.

Definition at line 148 of file py_object.cc.

string py_object::get_attribute_string ( const string &  name  ) 

Returns the given attribute as string value.

Parameters:
name Name of the attribute to access
Returns:
A string.

Definition at line 165 of file py_object.cc.

void py_object::set_attribute ( const string &  name,
PyObject *  value 
)

Assign a new attribute to the module, overriding an existing attribute of the same name.

Parameters:
name The attribute's name
value The attribute's value

Definition at line 182 of file py_object.cc.

void py_object::set_attribute_int ( const string &  name,
s_int32  value 
)

Assign a new integer attribute to the module, overriding an existing attribute of the same name.

Parameters:
name The attribute's name
value The attribute's value

void py_object::set_attribute_string ( const string &  name,
const string &  value 
)

Assign a new string attribute to the module, overriding an existing attribute of the same name.

Parameters:
name The attribute's name
value The attribute's value

Definition at line 206 of file py_object.cc.

PyObject* py_object::get_instance ( const bool &  incref = true  )  const [inline]

Direct access to the instance object.

The default behaviour is to increase the instance's reference count, so that this method can be safely called from Python scripts.

Parameters:
incref whether to increase the reference count.
Returns:
the Python class instance.

Definition at line 204 of file py_object.h.

std::string py_object::class_name (  )  const [inline]

Returns the class name of this object.

This is the name of the wrapped Python class.

Returns:
class name of this object.

Definition at line 219 of file py_object.h.

std::string py_object::file_name (  )  const [inline]

Returns the file name of this object.

This is the name of the Python module containing the wrapped class.

Returns:
fiöe name of this object.

Definition at line 230 of file py_object.h.


Member Data Documentation

PyObject* py_object::Instance [protected]

The python class instance wrapped by py_object.

Definition at line 240 of file py_object.h.


The documentation for this class was generated from the following files:

Generated on Tue Aug 11 15:31:53 2009 for Adonthell by  doxygen 1.5.9