wrapperBuilder.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Filename: wrapperBuilder.h
  2. // Created by: drose (01Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #ifndef WRAPPERBUILDER_H
  6. #define WRAPPERBUILDER_H
  7. #include <dtoolbase.h>
  8. #include <interrogate_interface.h>
  9. #include <vector_string.h>
  10. #include <vector>
  11. class CPPInstance;
  12. class CPPScope;
  13. class CPPStructType;
  14. class CPPType;
  15. class CPPFunctionType;
  16. class ParameterRemap;
  17. ////////////////////////////////////////////////////////////////////
  18. // Class : WrapperBuilder
  19. // Description : Contains all the information necessary to synthesize
  20. // a wrapper around a particular function. This
  21. // includes choosing appropriate parameter types to
  22. // remap from the C++ function's parameter types, as
  23. // well as actually generating wrapper code.
  24. //
  25. // This is an abstract class; it doesn't actually know
  26. // how to choose parameter types and synthesize
  27. // wrappers; see WrapperBuilderC and
  28. // WrapperBuilderPython.
  29. ////////////////////////////////////////////////////////////////////
  30. class WrapperBuilder {
  31. public:
  32. enum Type {
  33. T_normal,
  34. T_constructor,
  35. T_destructor,
  36. T_typecast_method,
  37. T_assignment_method,
  38. T_typecast,
  39. T_getter,
  40. T_setter
  41. };
  42. WrapperBuilder();
  43. virtual ~WrapperBuilder();
  44. void clear();
  45. bool set_function(CPPInstance *function, const string &description,
  46. CPPStructType *struct_type, CPPScope *scope,
  47. const string &function_signature, Type type,
  48. const string &expression,
  49. int num_default_parameters);
  50. bool is_valid() const;
  51. bool return_value_needs_management() const;
  52. FunctionIndex get_return_value_destructor() const;
  53. virtual void
  54. write_wrapper(ostream &out, const string &wrapper_name) const=0;
  55. virtual string
  56. get_wrapper_name(const string &library_hash_name) const=0;
  57. virtual bool supports_atomic_strings() const=0;
  58. enum CallingConvention {
  59. CC_c,
  60. CC_python,
  61. };
  62. virtual CallingConvention get_calling_convention() const=0;
  63. class Parameter {
  64. public:
  65. bool _has_name;
  66. string _name;
  67. ParameterRemap *_remap;
  68. };
  69. typedef vector<Parameter> Parameters;
  70. Parameters _parameters;
  71. ParameterRemap *_return_type;
  72. bool _void_return;
  73. bool _has_this;
  74. Type _type;
  75. CPPInstance *_function;
  76. string _description;
  77. CPPStructType *_struct_type;
  78. CPPScope *_scope;
  79. CPPFunctionType *_ftype;
  80. string _function_signature;
  81. string _expression;
  82. int _num_default_parameters;
  83. string _hash;
  84. int _wrapper_index;
  85. protected:
  86. virtual ParameterRemap *make_remap(CPPType *orig_type);
  87. string manage_return_value(ostream &out, int indent_level,
  88. const string &return_expr) const;
  89. void output_ref(ostream &out, int indent_level, const string &varname) const;
  90. string get_parameter_name(int n) const;
  91. string get_parameter_expr(int n, const vector_string &pexprs) const;
  92. string get_call_str(const vector_string &pexprs = vector_string()) const;
  93. string call_function(ostream &out, int indent_level,
  94. bool convert_result = true,
  95. const vector_string &pexprs = vector_string()) const;
  96. void write_spam_message(ostream &out) const;
  97. void write_quoted_string(ostream &out, const string &str) const;
  98. bool _is_valid;
  99. bool _return_value_needs_management;
  100. FunctionIndex _return_value_destructor;
  101. bool _manage_reference_count;
  102. public:
  103. static ostream &indent(ostream &out, int indent_level);
  104. };
  105. #endif