PageRenderTime 62ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Lib/guile/std_string.i

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