Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

InterfaceMakerPythonObj Class Reference

An InterfaceMaker suitable for generating object-oriented Python code, that can be imported and used directly by Python. More...

#include <interfaceMakerPythonObj.h>

Inheritance diagram for InterfaceMakerPythonObj:

InterfaceMakerPython InterfaceMaker List of all members.

Public Member Functions

 InterfaceMakerPythonObj (InterrogateModuleDef *def)
virtual ~InterfaceMakerPythonObj ()
virtual void write_prototypes (ostream &out)
 Generates the list of function prototypes corresponding to the functions that will be output in write_functions().

virtual void write_functions (ostream &out)
 Generates the list of functions that are appropriate for this interface.

virtual void write_module (ostream &out, InterrogateModuleDef *def)
 Generates whatever additional code is required to support a module file.

virtual bool synthesize_this_parameter ()
 This method should be overridden and redefined to return true for interfaces that require the implicit "this" parameter, if present, to be passed as the first parameter to any wrapper functions.

virtual void write_includes (ostream &out)
 Generates the list of #include ...

virtual void generate_wrappers ()
 Walks through the set of functions in the database and generates wrappers for each function, storing these in the database.

virtual ParameterRemapremap_parameter (CPPType *struct_type, CPPType *param_type)
 Allocates a new ParameterRemap object suitable to the indicated parameter type.

virtual bool separate_overloading ()
 This method should be overridden and redefined to return true for interfaces that require overloaded instances of a function to be defined as separate functions (each with its own hashed name), or false for interfaces that can support overloading natively, and thus only require one wrapper function per each overloaded input function.

void get_function_remaps (vector< FunctionRemap * > &remaps)
 Fills up the indicated vector with all of the FunctionRemap pointers created by this InterfaceMaker.


Static Public Member Functions

string get_builder_name (CPPType *struct_type)
 Returns the name of the InterfaceMaker function generated to define the Python class for the indicated struct type.

ostream & indent (ostream &out, int indent_level)

Protected Types

typedef vector< Function * > Functions
typedef map< TypeIndex, Object * > Objects
typedef map< string, FunctionRemap * > WrappersByHash

Protected Member Functions

virtual string get_wrapper_prefix ()
 Returns the prefix string used to generate wrapper function names.

void test_assert (ostream &out, int indent_level) const
 Outputs code to check to see if an assertion has failed while the C++ code was executing, and report this failure back to Python.

virtual FunctionRemapmake_function_remap (const InterrogateType &itype, const InterrogateFunction &ifunc, CPPInstance *cppfunc, int num_default_parameters)
 Creates a FunctionRemap object corresponding to the particular function wrapper.

virtual string get_wrapper_name (const InterrogateType &itype, const InterrogateFunction &ifunc, FunctionIndex func_index)
 Returns the function name that will be used to wrap the indicated function.

virtual string get_unique_prefix ()
 Returns the prefix string used to generate unique symbolic names, which are not necessarily C-callable function names.

Function * record_function (const InterrogateType &itype, FunctionIndex func_index)
 Records the indicated function, along with all of its FunctionRemap flavors and FunctionWriter helpers, for future output.

virtual void record_function_wrapper (InterrogateFunction &ifunc, FunctionWrapperIndex wrapper_index)
 Associates the function wrapper with its function in the appropriate structures in the database.

Object * record_object (TypeIndex type_index)
 Records the indicated type, which may be a struct type, along with all of its associated methods, if any.

void hash_function_signature (FunctionRemap *remap)
 Generates a unique string that corresponds to the function signature for the indicated FunctionRemap object, and stores the generated string in the _hash member of the FunctionRemap.

string manage_return_value (ostream &out, int indent_level, FunctionRemap *remap, const string &return_expr) const
 Does any additional processing that we might want to do on the return value for the function, just before we return it.

void output_ref (ostream &out, int indent_level, FunctionRemap *remap, const string &varname) const
 Outputs the code to increment the reference count for the indicated variable name.

void write_spam_message (ostream &out, FunctionRemap *remap) const
 Generates a string to output a spammy message to notify indicating we have just called this function.


Protected Attributes

Functions _functions
Objects _objects
WrappersByHash _wrappers_by_hash
InterrogateModuleDef_def
FunctionWriters _function_writers

Private Types

typedef map< CPPType *, FunctionWriter * > PtrConverter

Private Member Functions

void write_class_wrapper (ostream &out, Object *object)
 Writes a function that will define the Python class.

void write_prototype_for (ostream &out, Function *func)
 Writes the prototype for the indicated function.

void write_function_for (ostream &out, Function *func)
 Writes the definition for a function that will call the indicated C++ function or method.

void write_function_instance (ostream &out, int indent_level, Function *func, FunctionRemap *remap, string &expected_params)
 Writes out the part of a function that handles a single instance of an overloaded function.

void pack_return_value (ostream &out, int indent_level, FunctionRemap *remap, string return_expr)
 Outputs a command to pack the indicated expression, of the return_type type, as a Python return value.

FunctionWriterPtrFromPythonget_ptr_from_python (CPPType *type)
 Returns a FunctionWriter pointer suitable for converting from a Python wrapper of the indicated type to the corresponding C++ pointer.

FunctionWriterPtrToPythonget_ptr_to_python (CPPType *type)
 Returns a FunctionWriter pointer suitable for converting from a C++ pointer of the indicated type to the corresponding Python wrapper.


Private Attributes

PtrConverter _from_python
PtrConverter _to_python

Detailed Description

An InterfaceMaker suitable for generating object-oriented Python code, that can be imported and used directly by Python.

Definition at line 50 of file interfaceMakerPythonObj.h.


Member Typedef Documentation

typedef vector<Function *> InterfaceMaker::Functions [protected, inherited]
 

Definition at line 103 of file interfaceMaker.h.

typedef map<TypeIndex, Object *> InterfaceMaker::Objects [protected, inherited]
 

Definition at line 118 of file interfaceMaker.h.

typedef map<CPPType *, FunctionWriter *> InterfaceMakerPythonObj::PtrConverter [private]
 

Definition at line 80 of file interfaceMakerPythonObj.h.

typedef map<string, FunctionRemap *> InterfaceMaker::WrappersByHash [protected, inherited]
 

Definition at line 121 of file interfaceMaker.h.


Constructor & Destructor Documentation

InterfaceMakerPythonObj::InterfaceMakerPythonObj InterrogateModuleDef def  ) 
 

Definition at line 44 of file interfaceMakerPythonObj.cxx.

InterfaceMakerPythonObj::~InterfaceMakerPythonObj  )  [virtual]
 

Definition at line 57 of file interfaceMakerPythonObj.cxx.

References InterfaceMaker::_functions, write_prototype_for(), and InterfaceMaker::write_prototypes().


Member Function Documentation

void InterfaceMaker::generate_wrappers  )  [virtual, inherited]
 

Walks through the set of functions in the database and generates wrappers for each function, storing these in the database.

No actual code should be output yet; this just updates the database with the wrapper information.

Definition at line 157 of file interfaceMaker.cxx.

References FunctionIndex.

string InterfaceMakerPythonObj::get_builder_name CPPType struct_type  )  [static]
 

Returns the name of the InterfaceMaker function generated to define the Python class for the indicated struct type.

Definition at line 191 of file interfaceMakerPythonObj.cxx.

Referenced by synthesize_this_parameter(), and FunctionWriterPtrToPython::write_prototype().

void InterfaceMaker::get_function_remaps vector< FunctionRemap * > &  remaps  )  [inherited]
 

Fills up the indicated vector with all of the FunctionRemap pointers created by this InterfaceMaker.

It is the user's responsibility to empty the vector before calling this function; the new pointers will simply be added to the end.

Definition at line 408 of file interfaceMaker.cxx.

FunctionWriterPtrFromPython * InterfaceMakerPythonObj::get_ptr_from_python CPPType type  )  [private]
 

Returns a FunctionWriter pointer suitable for converting from a Python wrapper of the indicated type to the corresponding C++ pointer.

Definition at line 599 of file interfaceMakerPythonObj.cxx.

FunctionWriterPtrToPython * InterfaceMakerPythonObj::get_ptr_to_python CPPType type  )  [private]
 

Returns a FunctionWriter pointer suitable for converting from a C++ pointer of the indicated type to the corresponding Python wrapper.

Definition at line 626 of file interfaceMakerPythonObj.cxx.

string InterfaceMaker::get_unique_prefix  )  [protected, virtual, inherited]
 

Returns the prefix string used to generate unique symbolic names, which are not necessarily C-callable function names.

Reimplemented in InterfaceMakerC, and InterfaceMakerPythonSimple.

Definition at line 529 of file interfaceMaker.cxx.

References InterfaceMaker::_objects, InterrogateDatabase::get_ptr(), and NULL.

Referenced by InterfaceMaker::synthesize_this_parameter().

string InterfaceMaker::get_wrapper_name const InterrogateType itype,
const InterrogateFunction ifunc,
FunctionIndex  func_index
[protected, virtual, inherited]
 

Returns the function name that will be used to wrap the indicated function.

This is the name for the overall wrapper function, including all of the overloaded instances. Interfaces that must define a different wrapper for each FunctionRemap object (i.e. for each instance of an overloaded function) need not define a name here.

Definition at line 490 of file interfaceMaker.cxx.

References InterfaceMaker::Function::_has_this, FunctionRemap::_has_this, InterfaceMaker::Function::_remaps, FunctionWrapperIndex, FunctionRemap::make_wrapper_entry(), NULL, InterfaceMaker::record_function_wrapper(), and InterrogateDatabase::update_function().

string InterfaceMakerPythonObj::get_wrapper_prefix  )  [protected, virtual]
 

Returns the prefix string used to generate wrapper function names.

Reimplemented from InterfaceMaker.

Definition at line 207 of file interfaceMakerPythonObj.cxx.

void InterfaceMaker::hash_function_signature FunctionRemap remap  )  [protected, inherited]
 

Generates a unique string that corresponds to the function signature for the indicated FunctionRemap object, and stores the generated string in the _hash member of the FunctionRemap.

Definition at line 824 of file interfaceMaker.cxx.

Referenced by InterfaceMaker::synthesize_this_parameter().

ostream & InterfaceMaker::indent ostream &  out,
int  indent_level
[static, inherited]
 

Definition at line 428 of file interfaceMaker.cxx.

Referenced by FunctionRemap::get_parameter_name(), ParameterRemapBasicStringToString::pass_parameter(), write_function_for(), and InterfaceMakerPython::write_includes().

FunctionRemap * InterfaceMaker::make_function_remap const InterrogateType itype,
const InterrogateFunction ifunc,
CPPInstance cppfunc,
int  num_default_parameters
[protected, virtual, inherited]
 

Creates a FunctionRemap object corresponding to the particular function wrapper.

Definition at line 446 of file interfaceMaker.cxx.

References InterfaceMaker::_functions, InterrogateFunction::Instances, and NULL.

string InterfaceMaker::manage_return_value ostream &  out,
int  indent_level,
FunctionRemap remap,
const string &  return_expr
const [protected, inherited]
 

Does any additional processing that we might want to do on the return value for the function, just before we return it.

Returns the string representing the new return value after processing.

Definition at line 740 of file interfaceMaker.cxx.

References InterfaceMaker::_wrappers_by_hash, and nout.

void InterfaceMaker::output_ref ostream &  out,
int  indent_level,
FunctionRemap remap,
const string &  varname
const [protected, inherited]
 

Outputs the code to increment the reference count for the indicated variable name.

Definition at line 786 of file interfaceMaker.cxx.

Referenced by InterfaceMaker::record_function_wrapper().

void InterfaceMakerPythonObj::pack_return_value ostream &  out,
int  indent_level,
FunctionRemap remap,
string  return_expr
[private]
 

Outputs a command to pack the indicated expression, of the return_type type, as a Python return value.

Definition at line 542 of file interfaceMakerPythonObj.cxx.

References _from_python.

InterfaceMaker::Function * InterfaceMaker::record_function const InterrogateType itype,
FunctionIndex  func_index
[protected, inherited]
 

Records the indicated function, along with all of its FunctionRemap flavors and FunctionWriter helpers, for future output.

Returns the new Function pointer.

Definition at line 546 of file interfaceMaker.cxx.

References InterfaceMaker::_objects.

Referenced by InterfaceMaker::~InterfaceMaker().

void InterfaceMaker::record_function_wrapper InterrogateFunction ifunc,
FunctionWrapperIndex  wrapper_index
[protected, virtual, inherited]
 

Associates the function wrapper with its function in the appropriate structures in the database.

Reimplemented in InterfaceMakerC, and InterfaceMakerPythonSimple.

Definition at line 628 of file interfaceMaker.cxx.

References InterfaceMaker::output_ref().

Referenced by InterfaceMaker::get_wrapper_name().

InterfaceMaker::Object * InterfaceMaker::record_object TypeIndex  type_index  )  [protected, inherited]
 

Records the indicated type, which may be a struct type, along with all of its associated methods, if any.

Definition at line 644 of file interfaceMaker.cxx.

Referenced by InterfaceMaker::~InterfaceMaker().

ParameterRemap * InterfaceMaker::remap_parameter CPPType struct_type,
CPPType param_type
[virtual, inherited]
 

Allocates a new ParameterRemap object suitable to the indicated parameter type.

If struct_type is non-NULL, it is the type of the enclosing class for the function (method) in question.

The return value is a newly-allocated ParameterRemap object, if the parameter type is acceptable, or NULL if the parameter type cannot be handled.

Definition at line 287 of file interfaceMaker.cxx.

bool InterfaceMaker::separate_overloading  )  [virtual, inherited]
 

This method should be overridden and redefined to return true for interfaces that require overloaded instances of a function to be defined as separate functions (each with its own hashed name), or false for interfaces that can support overloading natively, and thus only require one wrapper function per each overloaded input function.

Definition at line 387 of file interfaceMaker.cxx.

Referenced by InterfaceMaker::synthesize_this_parameter().

bool InterfaceMakerPythonObj::synthesize_this_parameter  )  [virtual]
 

This method should be overridden and redefined to return true for interfaces that require the implicit "this" parameter, if present, to be passed as the first parameter to any wrapper functions.

Reimplemented from InterfaceMaker.

Definition at line 174 of file interfaceMakerPythonObj.cxx.

References InterrogateType::_cpptype, InterfaceMaker::Object::_itype, InterrogateBuilder::clean_identifier(), get_builder_name(), CPPType::get_simple_name(), and NULL.

void InterfaceMakerPython::test_assert ostream &  out,
int  indent_level
const [protected, inherited]
 

Outputs code to check to see if an assertion has failed while the C++ code was executing, and report this failure back to Python.

Definition at line 71 of file interfaceMakerPython.cxx.

void InterfaceMakerPythonObj::write_class_wrapper ostream &  out,
InterfaceMaker::Object object
[private]
 

Writes a function that will define the Python class.

Definition at line 220 of file interfaceMakerPythonObj.cxx.

Referenced by write_prototypes().

void InterfaceMakerPythonObj::write_function_for ostream &  out,
InterfaceMaker::Function func
[private]
 

Writes the definition for a function that will call the indicated C++ function or method.

Definition at line 315 of file interfaceMakerPythonObj.cxx.

References FunctionRemap::_cppfunc, FunctionRemap::_parameters, CPPType::get_local_name(), FunctionRemap::get_parameter_name(), CPPInstance::get_simple_name(), InterfaceMaker::indent(), TypeManager::is_char_pointer(), parser, and FunctionRemap::write_orig_prototype().

Referenced by write_prototypes().

void InterfaceMakerPythonObj::write_function_instance ostream &  out,
int  indent_level,
InterfaceMaker::Function func,
FunctionRemap remap,
string &  expected_params
[private]
 

Writes out the part of a function that handles a single instance of an overloaded function.

Definition at line 363 of file interfaceMakerPythonObj.cxx.

void InterfaceMakerPythonObj::write_functions ostream &  out  )  [virtual]
 

Generates the list of functions that are appropriate for this interface.

This function is called *before* write_prototypes(), above.

Reimplemented from InterfaceMaker.

Definition at line 97 of file interfaceMakerPythonObj.cxx.

References InterfaceMaker::_objects, and InterfaceMaker::write_module().

void InterfaceMakerPython::write_includes ostream &  out  )  [virtual, inherited]
 

Generates the list of #include ...

whatever that's required by this particular interface to the indicated output stream.

Reimplemented from InterfaceMaker.

Definition at line 52 of file interfaceMakerPython.cxx.

References InterfaceMaker::indent().

void InterfaceMakerPythonObj::write_module ostream &  out,
InterrogateModuleDef def
[virtual]
 

Generates whatever additional code is required to support a module file.

Reimplemented from InterfaceMaker.

Definition at line 126 of file interfaceMakerPythonObj.cxx.

void InterfaceMakerPythonObj::write_prototype_for ostream &  out,
InterfaceMaker::Function func
[private]
 

Writes the prototype for the indicated function.

Definition at line 299 of file interfaceMakerPythonObj.cxx.

Referenced by ~InterfaceMakerPythonObj().

void InterfaceMakerPythonObj::write_prototypes ostream &  out  )  [virtual]
 

Generates the list of function prototypes corresponding to the functions that will be output in write_functions().

Reimplemented from InterfaceMaker.

Definition at line 73 of file interfaceMakerPythonObj.cxx.

References InterfaceMaker::_functions, InterfaceMaker::_objects, write_class_wrapper(), write_function_for(), and InterfaceMaker::write_functions().

void InterfaceMaker::write_spam_message ostream &  out,
FunctionRemap remap
const [protected, inherited]
 

Generates a string to output a spammy message to notify indicating we have just called this function.

Definition at line 896 of file interfaceMaker.cxx.


Member Data Documentation

InterrogateModuleDef* InterfaceMaker::_def [protected, inherited]
 

Definition at line 158 of file interfaceMaker.h.

Referenced by InterfaceMaker::synthesize_this_parameter().

PtrConverter InterfaceMakerPythonObj::_from_python [private]
 

Definition at line 81 of file interfaceMakerPythonObj.h.

Referenced by pack_return_value().

FunctionWriters InterfaceMaker::_function_writers [protected, inherited]
 

Definition at line 160 of file interfaceMaker.h.

Functions InterfaceMaker::_functions [protected, inherited]
 

Definition at line 104 of file interfaceMaker.h.

Referenced by InterfaceMaker::make_function_remap(), InterfaceMakerPythonSimple::write_functions(), InterfaceMakerPythonSimple::write_prototypes(), write_prototypes(), InterfaceMakerC::write_prototypes(), InterfaceMakerC::~InterfaceMakerC(), ~InterfaceMakerPythonObj(), and InterfaceMakerPythonSimple::~InterfaceMakerPythonSimple().

Objects InterfaceMaker::_objects [protected, inherited]
 

Definition at line 119 of file interfaceMaker.h.

Referenced by InterfaceMaker::get_unique_prefix(), InterfaceMaker::record_function(), write_functions(), and write_prototypes().

PtrConverter InterfaceMakerPythonObj::_to_python [private]
 

Definition at line 82 of file interfaceMakerPythonObj.h.

WrappersByHash InterfaceMaker::_wrappers_by_hash [protected, inherited]
 

Definition at line 122 of file interfaceMaker.h.

Referenced by InterfaceMaker::manage_return_value().


The documentation for this class was generated from the following files:
Generated on Thu May 1 22:13:35 2003 for DTool by doxygen1.3