parameterRemapBasicStringToString.cxx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Filename: parameterRemapBasicStringToString.cxx
  2. // Created by: drose (09Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #include "parameterRemapBasicStringToString.h"
  15. #include "interfaceMaker.h"
  16. #include "interrogate.h"
  17. ////////////////////////////////////////////////////////////////////
  18. // Function: ParameterRemapBasicStringToString::Constructor
  19. // Access: Public
  20. // Description:
  21. ////////////////////////////////////////////////////////////////////
  22. ParameterRemapBasicStringToString::
  23. ParameterRemapBasicStringToString(CPPType *orig_type) :
  24. ParameterRemapToString(orig_type)
  25. {
  26. static CPPType *const_char_star_type = (CPPType *)NULL;
  27. if (const_char_star_type == (CPPType *)NULL) {
  28. const_char_star_type = parser.parse_type("const char *");
  29. }
  30. _new_type = const_char_star_type;
  31. }
  32. ////////////////////////////////////////////////////////////////////
  33. // Function: ParameterRemapBasicStringToString::pass_parameter
  34. // Access: Public, Virtual
  35. // Description: Outputs an expression that converts the indicated
  36. // variable from the original type to the new type, for
  37. // passing into the actual C++ function.
  38. ////////////////////////////////////////////////////////////////////
  39. void ParameterRemapBasicStringToString::
  40. pass_parameter(ostream &out, const string &variable_name) {
  41. out << "std::string(" << variable_name << ")";
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: ParameterRemapBasicStringToString::prepare_return_expr
  45. // Access: Public, Virtual
  46. // Description: This will be called immediately before
  47. // get_return_expr(). It outputs whatever lines the
  48. // remapper needs to the function to set up its return
  49. // value, e.g. to declare a temporary variable or
  50. // something. It should return the modified expression.
  51. ////////////////////////////////////////////////////////////////////
  52. string ParameterRemapBasicStringToString::
  53. prepare_return_expr(ostream &out, int indent_level, const string &expression) {
  54. InterfaceMaker::indent(out, indent_level)
  55. << "static string string_holder = " << expression << ";\n";
  56. return "string_holder";
  57. }
  58. ////////////////////////////////////////////////////////////////////
  59. // Function: ParameterRemapBasicStringToString::get_return_expr
  60. // Access: Public, Virtual
  61. // Description: Returns an expression that evalutes to the
  62. // appropriate value type for returning from the
  63. // function, given an expression of the original type.
  64. ////////////////////////////////////////////////////////////////////
  65. string ParameterRemapBasicStringToString::
  66. get_return_expr(const string &expression) {
  67. return "string_holder.c_str()";
  68. }
  69. ////////////////////////////////////////////////////////////////////
  70. // Function: ParameterRemapBasicWStringToWString::Constructor
  71. // Access: Public
  72. // Description:
  73. ////////////////////////////////////////////////////////////////////
  74. ParameterRemapBasicWStringToWString::
  75. ParameterRemapBasicWStringToWString(CPPType *orig_type) :
  76. ParameterRemapToWString(orig_type)
  77. {
  78. static CPPType *const_wchar_star_type = (CPPType *)NULL;
  79. if (const_wchar_star_type == (CPPType *)NULL) {
  80. const_wchar_star_type = parser.parse_type("const wchar_t *");
  81. }
  82. _new_type = const_wchar_star_type;
  83. }
  84. ////////////////////////////////////////////////////////////////////
  85. // Function: ParameterRemapBasicWStringToWString::pass_parameter
  86. // Access: Public, Virtual
  87. // Description: Outputs an expression that converts the indicated
  88. // variable from the original type to the new type, for
  89. // passing into the actual C++ function.
  90. ////////////////////////////////////////////////////////////////////
  91. void ParameterRemapBasicWStringToWString::
  92. pass_parameter(ostream &out, const string &variable_name) {
  93. out << "std::wstring(" << variable_name << ")";
  94. }
  95. ////////////////////////////////////////////////////////////////////
  96. // Function: ParameterRemapBasicWStringToWString::prepare_return_expr
  97. // Access: Public, Virtual
  98. // Description: This will be called immediately before
  99. // get_return_expr(). It outputs whatever lines the
  100. // remapper needs to the function to set up its return
  101. // value, e.g. to declare a temporary variable or
  102. // something. It should return the modified expression.
  103. ////////////////////////////////////////////////////////////////////
  104. string ParameterRemapBasicWStringToWString::
  105. prepare_return_expr(ostream &out, int indent_level, const string &expression) {
  106. InterfaceMaker::indent(out, indent_level)
  107. << "static wstring string_holder = " << expression << ";\n";
  108. return "string_holder";
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // Function: ParameterRemapBasicWStringToWString::get_return_expr
  112. // Access: Public, Virtual
  113. // Description: Returns an expression that evalutes to the
  114. // appropriate value type for returning from the
  115. // function, given an expression of the original type.
  116. ////////////////////////////////////////////////////////////////////
  117. string ParameterRemapBasicWStringToWString::
  118. get_return_expr(const string &expression) {
  119. return "string_holder.c_str()";
  120. }