PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/guile/std_string.i

#
Swig | 86 lines | 65 code | 16 blank | 5 comment | 0 complexity | fb216f4e37e96578ba2765ec943a56ba MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * std_string.i
  3. *
  4. * SWIG typemaps for std::string
  5. * ----------------------------------------------------------------------------- */
  6. // ------------------------------------------------------------------------
  7. // std::string is typemapped by value
  8. // This can prevent exporting methods which return a string
  9. // in order for the user to modify it.
  10. // However, I think I'll wait until someone asks for it...
  11. // ------------------------------------------------------------------------
  12. %include <exception.i>
  13. %{
  14. #include <string>
  15. %}
  16. namespace std {
  17. %naturalvar string;
  18. class string;
  19. %typemap(typecheck) string = char *;
  20. %typemap(typecheck) const string & = char *;
  21. %typemap(in) string (char * tempptr) {
  22. if (gh_string_p($input)) {
  23. tempptr = SWIG_scm2str($input);
  24. $1.assign(tempptr);
  25. if (tempptr) SWIG_free(tempptr);
  26. } else {
  27. SWIG_exception(SWIG_TypeError, "string expected");
  28. }
  29. }
  30. %typemap(in) const string & (std::string temp, char *tempptr) {
  31. if (gh_string_p($input)) {
  32. tempptr = SWIG_scm2str($input);
  33. temp.assign(tempptr);
  34. if (tempptr) SWIG_free(tempptr);
  35. $1 = &temp;
  36. } else {
  37. SWIG_exception(SWIG_TypeError, "string expected");
  38. }
  39. }
  40. %typemap(in) string * (char *tempptr) {
  41. if (gh_string_p($input)) {
  42. tempptr = SWIG_scm2str($input);
  43. $1 = new std::string(tempptr);
  44. if (tempptr) SWIG_free(tempptr);
  45. } else {
  46. SWIG_exception(SWIG_TypeError, "string expected");
  47. }
  48. }
  49. %typemap(out) string {
  50. $result = gh_str02scm($1.c_str());
  51. }
  52. %typemap(out) const string & {
  53. $result = gh_str02scm($1->c_str());
  54. }
  55. %typemap(out) string * {
  56. $result = gh_str02scm($1->c_str());
  57. }
  58. %typemap(varin) string {
  59. if (gh_string_p($input)) {
  60. char *tempptr = SWIG_scm2str($input);
  61. $1.assign(tempptr);
  62. if (tempptr) SWIG_free(tempptr);
  63. } else {
  64. SWIG_exception(SWIG_TypeError, "string expected");
  65. }
  66. }
  67. %typemap(varout) string {
  68. $result = gh_str02scm($1.c_str());
  69. }
  70. }