PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 218 lines | 175 code | 34 blank | 9 comment | 0 complexity | 35d26f6a6f2c9559c0701fed9bc22f9c 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. %warnfilter(404) std::string;
  17. %warnfilter(404) std::wstring;
  18. %{
  19. #include <string>
  20. // #include <vector>
  21. // using std::vector;
  22. using std::string;
  23. %}
  24. // %include <std_vector.i>
  25. // %naturalvar std::string;
  26. // %naturalvar std::wstring;
  27. namespace std {
  28. typedef unsigned long size_t;
  29. typedef signed long ptrdiff_t;
  30. template <class charT> class basic_string {
  31. public:
  32. typedef charT *pointer;
  33. typedef charT &reference;
  34. typedef const charT &const_reference;
  35. typedef size_t size_type;
  36. typedef ptrdiff_t difference_type;
  37. basic_string();
  38. basic_string( charT *str );
  39. size_type size();
  40. charT operator []( int pos ) const;
  41. charT *c_str() const;
  42. basic_string<charT> &operator = ( const basic_string &ws );
  43. basic_string<charT> &operator = ( const charT *str );
  44. basic_string<charT> &append( const basic_string<charT> &other );
  45. basic_string<charT> &append( const charT *str );
  46. void push_back( charT c );
  47. void clear();
  48. void reserve( size_type t );
  49. void resize( size_type n, charT c = charT() );
  50. int compare( const basic_string<charT> &other ) const;
  51. int compare( const charT *str ) const;
  52. basic_string<charT> &insert( size_type pos,
  53. const basic_string<charT> &str );
  54. size_type find( const basic_string<charT> &other, int pos = 0 ) const;
  55. size_type find( charT c, int pos = 0 ) const;
  56. %extend {
  57. bool operator == ( const basic_string<charT> &other ) const {
  58. return self->compare( other ) == 0;
  59. }
  60. bool operator != ( const basic_string<charT> &other ) const {
  61. return self->compare( other ) != 0;
  62. }
  63. bool operator < ( const basic_string<charT> &other ) const {
  64. return self->compare( other ) == -1;
  65. }
  66. bool operator > ( const basic_string<charT> &other ) const {
  67. return self->compare( other ) == 1;
  68. }
  69. bool operator <= ( const basic_string<charT> &other ) const {
  70. return self->compare( other ) != 1;
  71. }
  72. bool operator >= ( const basic_string<charT> &other ) const {
  73. return self->compare( other ) != -1;
  74. }
  75. }
  76. };
  77. %template(string) basic_string<char>;
  78. %template(wstring) basic_string<wchar_t>;
  79. %apply char * { string };
  80. %apply wchar_t * { wstring };
  81. typedef basic_string<char> string;
  82. typedef basic_string<wchar_t> wstring;
  83. // automatically convert constant std::strings to cl:strings
  84. %typemap(ctype) string "char *";
  85. %typemap(in) string "$1.assign($input);";
  86. %typemap(out) string "$result = (char *)(&$1)->c_str();";
  87. %typemap(lisptype) string "cl:string";
  88. %typemap(lout) string "(cl::setq ACL_ffresult $body)";
  89. %typemap(ctype) const string *"char *";
  90. %typemap(in) const string * "$1.assign($input);";
  91. %typemap(out) const string * "$result = (char *)($1)->c_str();";
  92. %typemap(lisptype) const string * "cl:string";
  93. %typemap(lout) const string * "(cl::setq ACL_ffresult $body)";
  94. %typemap(ctype) wstring "wchar_t *";
  95. %typemap(in) wstring "$1.assign($input);";
  96. %typemap(out) wstring "$result = (wchar_t *)(&$1)->c_str();";
  97. %typemap(lisptype) wstring "cl:string";
  98. %typemap(lout) wstring "(cl::setq ACL_ffresult (excl:native-to-string $body
  99. :external-format #+little-endian :fat-le #-little-endian :fat))";
  100. %typemap(ctype) const wstring *"char *";
  101. %typemap(in) const wstring * "$1.assign($input);";
  102. %typemap(out) const wstring * "$result = (char *)($1)->c_str();";
  103. %typemap(lisptype) const wstring * "cl:string";
  104. %typemap(lout) const wstring * "(cl::setq ACL_ffresult $body)";
  105. /* Overloading check */
  106. // %typemap(in) string {
  107. // if (caml_ptr_check($input))
  108. // $1.assign((char *)caml_ptr_val($input,0),
  109. // caml_string_len($input));
  110. // else
  111. // SWIG_exception(SWIG_TypeError, "string expected");
  112. // }
  113. // %typemap(in) const string & (std::string temp) {
  114. // if (caml_ptr_check($input)) {
  115. // temp.assign((char *)caml_ptr_val($input,0),
  116. // caml_string_len($input));
  117. // $1 = &temp;
  118. // } else {
  119. // SWIG_exception(SWIG_TypeError, "string expected");
  120. // }
  121. // }
  122. // %typemap(in) string & (std::string temp) {
  123. // if (caml_ptr_check($input)) {
  124. // temp.assign((char *)caml_ptr_val($input,0),
  125. // caml_string_len($input));
  126. // $1 = &temp;
  127. // } else {
  128. // SWIG_exception(SWIG_TypeError, "string expected");
  129. // }
  130. // }
  131. // %typemap(in) string * (std::string *temp) {
  132. // if (caml_ptr_check($input)) {
  133. // temp = new std::string((char *)caml_ptr_val($input,0),
  134. // caml_string_len($input));
  135. // $1 = temp;
  136. // } else {
  137. // SWIG_exception(SWIG_TypeError, "string expected");
  138. // }
  139. // }
  140. // %typemap(free) string * (std::string *temp) {
  141. // delete temp;
  142. // }
  143. // %typemap(argout) string & {
  144. // caml_list_append(swig_result,caml_val_string_len((*$1).c_str(),
  145. // (*$1).size()));
  146. // }
  147. // %typemap(directorout) string {
  148. // $result.assign((char *)caml_ptr_val($input,0),
  149. // caml_string_len($input));
  150. // }
  151. // %typemap(out) string {
  152. // $result = caml_val_string_len($1.c_str(),$1.size());
  153. // }
  154. // %typemap(out) string * {
  155. // $result = caml_val_string_len((*$1).c_str(),(*$1).size());
  156. // }
  157. }
  158. // #ifdef ENABLE_CHARPTR_ARRAY
  159. // char **c_charptr_array( const std::vector <string > &str_v );
  160. // %{
  161. // SWIGEXT char **c_charptr_array( const std::vector <string > &str_v ) {
  162. // char **out = new char *[str_v.size() + 1];
  163. // out[str_v.size()] = 0;
  164. // for( int i = 0; i < str_v.size(); i++ ) {
  165. // out[i] = (char *)str_v[i].c_str();
  166. // }
  167. // return out;
  168. // }
  169. // %}
  170. // #endif
  171. // #ifdef ENABLE_STRING_VECTOR
  172. // %template (StringVector) std::vector<string >;
  173. // %insert(ml) %{
  174. // (* Some STL convenience items *)
  175. // let string_array_to_vector sa =
  176. // let nv = _new_StringVector C_void in
  177. // array_to_vector nv (fun x -> C_string x) sa ; nv
  178. // let c_string_array ar =
  179. // _c_charptr_array (string_array_to_vector ar)
  180. // %}
  181. // %insert(mli) %{
  182. // val c_string_array: string array -> c_obj
  183. // %}
  184. // #endif