frepple::utils::PythonObject Class Reference

This class handles two-way translation between the data types in C++ and Python. More...

#include <utils.h>

Inheritance diagram for frepple::utils::PythonObject:
frepple::utils::DataElement frepple::utils::PythonFunction

List of all members.

Public Member Functions

bool check (const PythonType &c) const
bool check (const MetaClass *c) const
bool getBool () const
Date getDate () const
double getDouble () const
int getInt () const
long getLong () const
string getString () const
TimePeriod getTimeperiod () const
unsigned long getUnsignedLong () const
 operator bool () const
 operator PyObject * () const
PythonObjectoperator= (const PythonObject &o)
 PythonObject (const Date &val)
 PythonObject (const TimePeriod val)
 PythonObject (const bool val)
 PythonObject (const unsigned long val)
 PythonObject (const long val)
 PythonObject (const int val)
 PythonObject (const double val)
 PythonObject (const string &val)
 PythonObject (Object *p)
 PythonObject (const PyObject *o)
 PythonObject ()

Detailed Description

This class handles two-way translation between the data types in C++ and Python.

This class is basically a wrapper around a PyObject pointer.

When creating a PythonObject from a C++ object, make sure to increment the reference count of the object.
When constructing a PythonObject from an existing Python object, the code that provided us the PyObject pointer should have incremented the reference count already.

Definition at line 2800 of file utils.h.


Constructor & Destructor Documentation

frepple::utils::PythonObject::PythonObject (  )  [inline, explicit]

Default constructor. The default value is equal to Py_None.

Definition at line 2807 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const PyObject *  o  )  [inline]

Constructor from an existing Python object.
The reference count isn't increased.

Definition at line 2812 of file utils.h.

frepple::utils::PythonObject::PythonObject ( Object p  ) 

Constructor from a pointer to an Object.
The metadata of the Object instances allow us to create a Python object that works as a proxy for the C++ object.

Definition at line 429 of file pythonutils.cpp.

frepple::utils::PythonObject::PythonObject ( const string &  val  )  [inline]

Convert a C++ string into a (raw) Python string.

Definition at line 2972 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const double  val  )  [inline]

Convert a C++ double into a Python number.

Definition at line 2984 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const int  val  )  [inline]

Convert a C++ integer into a Python integer.

Definition at line 2990 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const long  val  )  [inline]

Convert a C++ long into a Python long.

Definition at line 2996 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const unsigned long  val  )  [inline]

Convert a C++ unsigned long into a Python long.

Definition at line 3002 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const bool  val  )  [inline]

Convert a C++ boolean into a Python boolean.

Definition at line 3008 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const TimePeriod  val  )  [inline]

Convert a frePPLe TimePeriod into a Python number representing the number of seconds.

Definition at line 3016 of file utils.h.

frepple::utils::PythonObject::PythonObject ( const Date val  ) 

Convert a frePPLe date into a Python datetime.datetime object.

Definition at line 372 of file pythonutils.cpp.


Member Function Documentation

bool frepple::utils::PythonObject::check ( const PythonType c  )  const [inline]

Check whether the Python object is of a certain type.
Subclasses of the argument type will also give a true return value.

Definition at line 2843 of file utils.h.

bool frepple::utils::PythonObject::check ( const MetaClass c  )  const [inline]

Check whether the Python object is of a certain type.
Subclasses of the argument type will also give a true return value.

Definition at line 2833 of file utils.h.

bool frepple::utils::PythonObject::getBool (  )  const [inline, virtual]

Convert a Python number into a C++ bool.

Reimplemented from frepple::utils::DataElement.

Definition at line 2938 of file utils.h.

Date frepple::utils::PythonObject::getDate (  )  const [virtual]

Convert a Python datetime.date or datetime.datetime object into a frePPLe date.

Reimplemented from frepple::utils::DataElement.

Definition at line 394 of file pythonutils.cpp.

double frepple::utils::PythonObject::getDouble (  )  const [inline, virtual]

Convert a Python number or string into a C++ double.

Reimplemented from frepple::utils::DataElement.

Definition at line 2885 of file utils.h.

int frepple::utils::PythonObject::getInt (  )  const [inline, virtual]

Convert a Python number or string into a C++ integer.

Reimplemented from frepple::utils::DataElement.

Definition at line 2900 of file utils.h.

long frepple::utils::PythonObject::getLong (  )  const [inline, virtual]

Convert a Python number into a C++ long.

Reimplemented from frepple::utils::DataElement.

Definition at line 2919 of file utils.h.

string frepple::utils::PythonObject::getString (  )  const [inline, virtual]

Convert a Python string into a C++ string.

Reimplemented from frepple::utils::DataElement.

Definition at line 2851 of file utils.h.

TimePeriod frepple::utils::PythonObject::getTimeperiod (  )  const [inline, virtual]

Convert a Python number as a number of seconds into a frePPLe TimePeriod.
A TimePeriod is represented as a number of seconds in Python.

Reimplemented from frepple::utils::DataElement.

Definition at line 2947 of file utils.h.

unsigned long frepple::utils::PythonObject::getUnsignedLong (  )  const [inline, virtual]

Extract an unsigned long from the Python object.

Reimplemented from frepple::utils::DataElement.

Definition at line 2864 of file utils.h.

frepple::utils::PythonObject::operator bool (  )  const [inline, virtual]

Check for null value.

Reimplemented from frepple::utils::DataElement.

Reimplemented in frepple::utils::PythonFunction.

Definition at line 2819 of file utils.h.

frepple::utils::PythonObject::operator PyObject * (  )  const [inline]

This conversion operator casts the object back to a PyObject pointer.

Definition at line 2816 of file utils.h.

PythonObject& frepple::utils::PythonObject::operator= ( const PythonObject o  )  [inline]

Assignment operator.

Reimplemented in frepple::utils::PythonFunction.

Definition at line 2822 of file utils.h.


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

Generated on 21 Mar 2010 for frePPLe by  doxygen 1.6.1