diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-12-02 01:45:21 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-12-02 02:42:50 +0300 |
commit | 9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c (patch) | |
tree | 9f88a486917d371d099cd712efd91b4c122d209d /contrib/tools/swig/Lib/std | |
parent | 32fb6dda1feb24f9ab69ece5df0cb9ec238ca5e6 (diff) | |
download | ydb-9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/tools/swig/Lib/std')
-rw-r--r-- | contrib/tools/swig/Lib/std/std_alloc.i | 77 | ||||
-rw-r--r-- | contrib/tools/swig/Lib/std/std_basic_string.i | 276 | ||||
-rw-r--r-- | contrib/tools/swig/Lib/std/std_char_traits.i | 140 | ||||
-rw-r--r-- | contrib/tools/swig/Lib/std/std_common.i | 250 | ||||
-rw-r--r-- | contrib/tools/swig/Lib/std/std_container.i | 169 | ||||
-rw-r--r-- | contrib/tools/swig/Lib/std/std_except.i | 73 | ||||
-rw-r--r-- | contrib/tools/swig/Lib/std/std_string.i | 13 | ||||
-rw-r--r-- | contrib/tools/swig/Lib/std/std_vector.i | 225 |
8 files changed, 1223 insertions, 0 deletions
diff --git a/contrib/tools/swig/Lib/std/std_alloc.i b/contrib/tools/swig/Lib/std/std_alloc.i new file mode 100644 index 0000000000..e460dc3eaf --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_alloc.i @@ -0,0 +1,77 @@ +namespace std +{ + /** + * @brief The "standard" allocator, as per [20.4]. + * + * The private _Alloc is "SGI" style. (See comments at the top + * of stl_alloc.h.) + * + * The underlying allocator behaves as follows. + * - __default_alloc_template is used via two typedefs + * - "__single_client_alloc" typedef does no locking for threads + * - "__alloc" typedef is threadsafe via the locks + * - __new_alloc is used for memory requests + * + * (See @link Allocators allocators info @endlink for more.) + */ + template<typename _Tp> + class allocator + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + template<typename _Tp1> + struct rebind; + + allocator() throw(); + + allocator(const allocator& other) throw(); + template<typename _Tp1> + allocator(const allocator<_Tp1>& other) throw(); + ~allocator() throw(); + + + pointer + address(reference __x) const; + + + const_pointer + address(const_reference __x) const; + + + // NB: __n is permitted to be 0. The C++ standard says nothing + // about what the return value is when __n == 0. + _Tp* + allocate(size_type __n, const void* = 0); + + // __p is not permitted to be a null pointer. + void + deallocate(pointer __p, size_type __n); + + size_type + max_size() const throw(); + + void construct(pointer __p, const _Tp& __val); + void destroy(pointer __p); + }; + + template<> + class allocator<void> + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template<typename _Tp1> + struct rebind; + }; +} // namespace std diff --git a/contrib/tools/swig/Lib/std/std_basic_string.i b/contrib/tools/swig/Lib/std/std_basic_string.i new file mode 100644 index 0000000000..e95cb47653 --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_basic_string.i @@ -0,0 +1,276 @@ +%include <exception.i> +%include <std_container.i> +%include <std_alloc.i> +%include <std_char_traits.i> + +%fragment("<string>"); + +namespace std +{ + %naturalvar basic_string; +} + + +namespace std { + + template <class _CharT, class _Traits = char_traits<_CharT>, typename _Alloc = allocator<_CharT> > + class basic_string + { +#if !defined(SWIG_STD_MODERN_STL) || defined(SWIG_STD_NOMODERN_STL) + %ignore push_back; + %ignore clear; + %ignore compare; + %ignore append; +#endif + + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _CharT value_type; + typedef value_type reference; + typedef value_type const_reference; + typedef _Alloc allocator_type; + + static const size_type npos; + +#ifdef SWIG_EXPORT_ITERATOR_METHODS + class iterator; + class reverse_iterator; + class const_iterator; + class const_reverse_iterator; +#endif + + + %traits_swigtype(_CharT); + %fragment(SWIG_Traits_frag(_CharT)); + + + basic_string(const _CharT* __s, size_type __n); + + // Capacity: + + size_type length() const; + + size_type max_size() const; + + size_type capacity() const; + + void reserve(size_type __res_arg); + %extend { + void shrink_to_fit() { + %#if __cplusplus >= 202002L + self->shrink_to_fit(); + %#else + self->reserve(); + %#endif + } + } + + + // Modifiers: + + basic_string& + append(const basic_string& __str); + + basic_string& + append(const basic_string& __str, size_type __pos, size_type __n); + + basic_string& + append(const _CharT* __s, size_type __n); + + basic_string& + append(size_type __n, _CharT __c); + + basic_string& + assign(const basic_string& __str); + + basic_string& + assign(const basic_string& __str, size_type __pos, size_type __n); + + basic_string& + assign(const _CharT* __s, size_type __n); + + basic_string& + insert(size_type __pos1, const basic_string& __str); + + basic_string& + insert(size_type __pos1, const basic_string& __str, + size_type __pos2, size_type __n); + + basic_string& + insert(size_type __pos, const _CharT* __s, size_type __n); + + basic_string& + insert(size_type __pos, size_type __n, _CharT __c); + + basic_string& + erase(size_type __pos = 0, size_type __n = npos); + + basic_string& + replace(size_type __pos, size_type __n, const basic_string& __str); + + basic_string& + replace(size_type __pos1, size_type __n1, const basic_string& __str, + size_type __pos2, size_type __n2); + + basic_string& + replace(size_type __pos, size_type __n1, const _CharT* __s, + size_type __n2); + + basic_string& + replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c); + + + size_type + copy(_CharT* __s, size_type __n, size_type __pos = 0) const; + + // String operations: + const _CharT* c_str() const; + + size_type + find(const _CharT* __s, size_type __pos, size_type __n) const; + + size_type + find(const basic_string& __str, size_type __pos = 0) const; + + size_type + find(_CharT __c, size_type __pos = 0) const; + + size_type + rfind(const basic_string& __str, size_type __pos = npos) const; + + size_type + rfind(const _CharT* __s, size_type __pos, size_type __n) const; + + size_type + rfind(_CharT __c, size_type __pos = npos) const; + + size_type + find_first_of(const basic_string& __str, size_type __pos = 0) const; + + size_type + find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; + + size_type + find_first_of(_CharT __c, size_type __pos = 0) const; + + size_type + find_last_of(const basic_string& __str, size_type __pos = npos) const; + + size_type + find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; + + size_type + find_last_of(_CharT __c, size_type __pos = npos) const; + + size_type + find_first_not_of(const basic_string& __str, size_type __pos = 0) const; + + size_type + find_first_not_of(const _CharT* __s, size_type __pos, + size_type __n) const; + + size_type + find_first_not_of(_CharT __c, size_type __pos = 0) const; + + size_type + find_last_not_of(const basic_string& __str, size_type __pos = npos) const; + + size_type + find_last_not_of(const _CharT* __s, size_type __pos, + size_type __n) const; + + size_type + find_last_not_of(_CharT __c, size_type __pos = npos) const; + + basic_string + substr(size_type __pos = 0, size_type __n = npos) const; + + int + compare(const basic_string& __str) const; + + int + compare(size_type __pos, size_type __n, const basic_string& __str) const; + + int + compare(size_type __pos1, size_type __n1, const basic_string& __str, + size_type __pos2, size_type __n2) const; + + + %ignore pop_back(); + %ignore front() const; + %ignore back() const; + %ignore basic_string(size_type n); + %std_sequence_methods_val(basic_string); + + + %ignore pop(); + + +#ifdef %swig_basic_string + // Add swig/language extra methods + %swig_basic_string(std::basic_string< _CharT, _Traits, _Alloc >); +#endif + +#ifdef SWIG_EXPORT_ITERATOR_METHODS + + + class iterator; + class reverse_iterator; + class const_iterator; + class const_reverse_iterator; + + + void + insert(iterator __p, size_type __n, _CharT __c); + + basic_string& + replace(iterator __i1, iterator __i2, const basic_string& __str); + + basic_string& + replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n); + + basic_string& + replace(iterator __i1, iterator __i2, size_type __n, _CharT __c); + + + basic_string& + replace(iterator __i1, iterator __i2, const _CharT* __k1, const _CharT* __k2); + + basic_string& + replace(iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2); +#endif + + basic_string& operator +=(const basic_string& v); + + %newobject __add__; + %newobject __radd__; + %extend { + + std::basic_string< _CharT,_Traits,_Alloc >* __add__(const basic_string& v) { + std::basic_string< _CharT,_Traits,_Alloc >* res = new std::basic_string< _CharT,_Traits,_Alloc >(*self); + *res += v; + return res; + } + + std::basic_string< _CharT,_Traits,_Alloc >* __radd__(const basic_string& v) { + std::basic_string< _CharT,_Traits,_Alloc >* res = new std::basic_string< _CharT,_Traits,_Alloc >(v); + *res += *self; + return res; + } + + std::basic_string< _CharT,_Traits,_Alloc > __str__() { + return *self; + } + + std::basic_ostream<_CharT, std::char_traits<_CharT> >& + __rlshift__(std::basic_ostream<_CharT, std::char_traits<_CharT> >& out) { + out << *self; + return out; + } + } + + }; +} + + diff --git a/contrib/tools/swig/Lib/std/std_char_traits.i b/contrib/tools/swig/Lib/std/std_char_traits.i new file mode 100644 index 0000000000..b9b4def32f --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_char_traits.i @@ -0,0 +1,140 @@ +%include <std_common.i> +#if defined(SWIG_WCHAR) +%include <wchar.i> +#endif + +namespace std +{ + + /// 21.1.2 Basis for explicit _Traits specialization + /// NB: That for any given actual character type this definition is + /// probably wrong. + template<class _CharT> + struct char_traits + { + }; + + + /// 21.1.4 char_traits specializations + template<> + struct char_traits<char> { + typedef char char_type; + typedef int int_type; + typedef streampos pos_type; + typedef streamoff off_type; + typedef mbstate_t state_type; + + static void + assign(char_type& __c1, const char_type& __c2); + + static bool + eq(const char_type& __c1, const char_type& __c2); + + static bool + lt(const char_type& __c1, const char_type& __c2); + + static int + compare(const char_type* __s1, const char_type* __s2, size_t __n); + + static size_t + length(const char_type* __s); + + static const char_type* + find(const char_type* __s, size_t __n, const char_type& __a); + + static char_type* + move(char_type* __s1, const char_type* __s2, size_t __n); + + static char_type* + copy(char_type* __s1, const char_type* __s2, size_t __n); + + static char_type* + assign(char_type* __s, size_t __n, char_type __a); + + static char_type + to_char_type(const int_type& __c); + + // To keep both the byte 0xff and the eof symbol 0xffffffff + // from ending up as 0xffffffff. + static int_type + to_int_type(const char_type& __c); + + static bool + eq_int_type(const int_type& __c1, const int_type& __c2); + + static int_type + eof() ; + + static int_type + not_eof(const int_type& __c); + }; + + +#if defined(SWIG_WCHAR) + template<> + struct char_traits<wchar_t> + { + typedef wchar_t char_type; + typedef wint_t int_type; + typedef streamoff off_type; + typedef wstreampos pos_type; + typedef mbstate_t state_type; + + static void + assign(char_type& __c1, const char_type& __c2); + + static bool + eq(const char_type& __c1, const char_type& __c2); + + static bool + lt(const char_type& __c1, const char_type& __c2); + + static int + compare(const char_type* __s1, const char_type* __s2, size_t __n); + + static size_t + length(const char_type* __s); + + static const char_type* + find(const char_type* __s, size_t __n, const char_type& __a); + + static char_type* + move(char_type* __s1, const char_type* __s2, int_type __n); + + static char_type* + copy(char_type* __s1, const char_type* __s2, size_t __n); + + static char_type* + assign(char_type* __s, size_t __n, char_type __a); + + static char_type + to_char_type(const int_type& __c) ; + + static int_type + to_int_type(const char_type& __c) ; + + static bool + eq_int_type(const int_type& __c1, const int_type& __c2); + + static int_type + eof() ; + + static int_type + not_eof(const int_type& __c); + }; +#endif +} + +namespace std { +#ifndef SWIG_STL_WRAP_TRAITS +%template() char_traits<char>; +#if defined(SWIG_WCHAR) +%template() char_traits<wchar_t>; +#endif +#else +%template(char_traits_c) char_traits<char>; +#if defined(SWIG_WCHAR) +%template(char_traits_w) char_traits<wchar_t>; +#endif +#endif +} diff --git a/contrib/tools/swig/Lib/std/std_common.i b/contrib/tools/swig/Lib/std/std_common.i new file mode 100644 index 0000000000..708f3ceedf --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_common.i @@ -0,0 +1,250 @@ +%include <std/std_except.i> + +// +// Use the following macro with modern STL implementations +// +//#define SWIG_STD_MODERN_STL +// +// Use this to deactivate the previous definition, when using gcc-2.95 +// or similar old compilers. +// +//#define SWIG_STD_NOMODERN_STL + +// Here, we identify compilers we know have problems with STL. +%{ +#if defined(__GNUC__) +# if __GNUC__ == 2 && __GNUC_MINOR <= 96 +# define SWIG_STD_NOMODERN_STL +# endif +#endif +%} + +// +// Common code for supporting the C++ std namespace +// + +%fragment("<string>"); +%fragment("<stdexcept>"); +%fragment("<stddef.h>"); + + +%fragment("StdIteratorTraits","header",fragment="<stddef.h>") %{ +#if defined(__SUNPRO_CC) && defined(_RWSTD_VER) +# if !defined(SWIG_NO_STD_NOITERATOR_TRAITS_STL) +# define SWIG_STD_NOITERATOR_TRAITS_STL +# endif +#endif + +#if !defined(SWIG_STD_NOITERATOR_TRAITS_STL) +#include <iterator> +#else +namespace std { + template <class Iterator> + struct iterator_traits { + typedef ptrdiff_t difference_type; + typedef typename Iterator::value_type value_type; + }; + + template <class Iterator, class Category,class T, class Reference, class Pointer, class Distance> + struct iterator_traits<__reverse_bi_iterator<Iterator,Category,T,Reference,Pointer,Distance> > { + typedef Distance difference_type; + typedef T value_type; + }; + + template <class T> + struct iterator_traits<T*> { + typedef T value_type; + typedef ptrdiff_t difference_type; + }; + + template<typename _InputIterator> + inline typename iterator_traits<_InputIterator>::difference_type + distance(_InputIterator __first, _InputIterator __last) + { + typename iterator_traits<_InputIterator>::difference_type __n = 0; + while (__first != __last) { + ++__first; ++__n; + } + return __n; + } +} +#endif +%} + +%fragment("StdTraitsCommon","header",fragment="<string>") %{ +namespace swig { + template <class Type> + struct noconst_traits { + typedef Type noconst_type; + }; + + template <class Type> + struct noconst_traits<const Type> { + typedef Type noconst_type; + }; + + /* + type categories + */ + struct pointer_category { }; + struct value_category { }; + + /* + General traits that provides type_name and type_info + */ + template <class Type> struct traits { }; + + template <class Type> + inline const char* type_name() { + return traits<typename noconst_traits<Type >::noconst_type >::type_name(); + } + + template <class Type> struct traits_info { + static swig_type_info *type_query(std::string name) { + name += " *"; + return SWIG_TypeQuery(name.c_str()); + } + static swig_type_info *type_info() { + static swig_type_info *info = type_query(type_name<Type>()); + return info; + } + }; + + /* + Partial specialization for pointers (traits_info) + */ + template <class Type> struct traits_info<Type *> { + static swig_type_info *type_query(std::string name) { + name += " *"; + return SWIG_TypeQuery(name.c_str()); + } + static swig_type_info *type_info() { + static swig_type_info *info = type_query(type_name<Type>()); + return info; + } + }; + + template <class Type> + inline swig_type_info *type_info() { + return traits_info<Type>::type_info(); + } + + /* + Partial specialization for pointers (traits) + */ + template <class Type> struct traits <Type *> { + typedef pointer_category category; + static std::string make_ptr_name(const char* name) { + std::string ptrname = name; + ptrname += " *"; + return ptrname; + } + static const char* type_name() { + static std::string name = make_ptr_name(swig::type_name<Type>()); + return name.c_str(); + } + }; + + template <class Type, class Category> + struct traits_as { }; + + template <class Type, class Category> + struct traits_check { }; + +} +%} + +/* + Generate the traits for a swigtype +*/ + +%define %traits_swigtype(Type...) +%fragment(SWIG_Traits_frag(Type),"header",fragment="StdTraits") { + namespace swig { + template <> struct traits< Type > { + typedef pointer_category category; + static const char* type_name() { return #Type; } + }; + } +} +%enddef + + + +/* + Generate the typemaps for a class that has 'value' traits +*/ + +%define %typemap_traits(Code,Type...) + %typemaps_asvalfrom(%arg(Code), + %arg(swig::asval< Type >), + %arg(swig::from), + %arg(SWIG_Traits_frag(Type)), + %arg(SWIG_Traits_frag(Type)), + Type); +%enddef + +/* + Generate the typemaps for a class that behaves more like a 'pointer' or + plain wrapped Swigtype. +*/ + +%define %typemap_traits_ptr(Code,Type...) + %typemaps_asptrfrom(%arg(Code), + %arg(swig::asptr), + %arg(swig::from), + %arg(SWIG_Traits_frag(Type)), + %arg(SWIG_Traits_frag(Type)), + Type); +%enddef + + +/* + Equality methods +*/ +%define %std_equal_methods(Type...) +%extend Type { + bool operator == (const Type& v) { + return *self == v; + } + + bool operator != (const Type& v) { + return *self != v; + } +} + +%enddef + +/* + Order methods +*/ + +%define %std_order_methods(Type...) +%extend Type { + bool operator > (const Type& v) { + return *self > v; + } + + bool operator < (const Type& v) { + return *self < v; + } + + bool operator >= (const Type& v) { + return *self >= v; + } + + bool operator <= (const Type& v) { + return *self <= v; + } +} +%enddef + +/* + Comparison methods +*/ + +%define %std_comp_methods(Type...) +%std_equal_methods(Type ) +%std_order_methods(Type ) +%enddef + diff --git a/contrib/tools/swig/Lib/std/std_container.i b/contrib/tools/swig/Lib/std/std_container.i new file mode 100644 index 0000000000..570dfde484 --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_container.i @@ -0,0 +1,169 @@ +%include <std_common.i> +%include <exception.i> +%include <std_alloc.i> + +%{ +#include <algorithm> +%} + +// Common non-resizable container methods + +%define %std_container_methods_non_resizable(container...) + + container(); + container(const container& other); + + bool empty() const; + size_type size() const; + void swap(container& v); + +%enddef + +%define %std_container_methods_forward_iterators(container...) + + #ifdef SWIG_EXPORT_ITERATOR_METHODS + class iterator; + class const_iterator; + iterator begin(); + iterator end(); + #endif + +%enddef + +%define %std_container_methods_reverse_iterators(container...) + + #ifdef SWIG_EXPORT_ITERATOR_METHODS + class reverse_iterator; + class const_reverse_iterator; + reverse_iterator rbegin(); + reverse_iterator rend(); + #endif + +%enddef + +// Common container methods + +%define %std_container_methods(container...) + + %std_container_methods_non_resizable(%arg(container)) + %std_container_methods_forward_iterators(%arg(container)) + %std_container_methods_reverse_iterators(%arg(container)) + + void clear(); + allocator_type get_allocator() const; + +%enddef + +%define %std_container_methods_without_reverse_iterators(container...) + + %std_container_methods_non_resizable(%arg(container)) + %std_container_methods_forward_iterators(%arg(container)) + + void clear(); + allocator_type get_allocator() const; + +%enddef + +// Common sequence + +%define %std_sequence_methods_common(sequence) + + %std_container_methods(%arg(sequence)); + + sequence(size_type size); + void pop_back(); + + void resize(size_type new_size); + + #ifdef SWIG_EXPORT_ITERATOR_METHODS +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator erase(iterator pos) { return $self->erase(pos); } + iterator erase(iterator first, iterator last) { return $self->erase(first, last); } +} + #endif + +%enddef + +%define %std_sequence_methods_non_resizable(sequence) + + %std_container_methods_non_resizable(%arg(sequence)) + %std_container_methods_forward_iterators(%arg(container)) + %std_container_methods_reverse_iterators(%arg(container)) + + const value_type& front() const; + const value_type& back() const; + +%enddef + +%define %std_sequence_methods(sequence) + + %std_sequence_methods_common(%arg(sequence)); + + sequence(size_type size, const value_type& value); + void push_back(const value_type& x); + + const value_type& front() const; + const value_type& back() const; + + void assign(size_type n, const value_type& x); + void resize(size_type new_size, const value_type& x); + + #ifdef SWIG_EXPORT_ITERATOR_METHODS +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator insert(iterator pos, const value_type& x) { return $self->insert(pos, x); } + void insert(iterator pos, size_type n, const value_type& x) { $self->insert(pos, n, x); } +} + #endif + +%enddef + +%define %std_sequence_methods_non_resizable_val(sequence...) + + %std_container_methods_non_resizable(%arg(sequence)) + %std_container_methods_forward_iterators(%arg(container)) + %std_container_methods_reverse_iterators(%arg(container)) + + value_type front() const; + value_type back() const; + +#endif + +%enddef + +%define %std_sequence_methods_val(sequence...) + + %std_sequence_methods_common(%arg(sequence)); + + sequence(size_type size, value_type value); + void push_back(value_type x); + + value_type front() const; + value_type back() const; + + void assign(size_type n, value_type x); + void resize(size_type new_size, value_type x); + + #ifdef SWIG_EXPORT_ITERATOR_METHODS +%extend { + // %extend wrapper used for differing definitions of these methods introduced in C++11 + iterator insert(iterator pos, value_type x) { return $self->insert(pos, x); } + void insert(iterator pos, size_type n, value_type x) { $self->insert(pos, n, x); } +} + #endif + +%enddef + + +// +// Ignore member methods for Type with no default constructor +// +%define %std_nodefconst_type(Type...) +%feature("ignore") std::vector< Type >::vector(size_type size); +%feature("ignore") std::vector< Type >::resize(size_type size); +%feature("ignore") std::deque< Type >::deque(size_type size); +%feature("ignore") std::deque< Type >::resize(size_type size); +%feature("ignore") std::list< Type >::list(size_type size); +%feature("ignore") std::list< Type >::resize(size_type size); +%enddef diff --git a/contrib/tools/swig/Lib/std/std_except.i b/contrib/tools/swig/Lib/std/std_except.i new file mode 100644 index 0000000000..728b9c8b52 --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_except.i @@ -0,0 +1,73 @@ +#if defined(SWIGJAVA) || defined(SWIGCSHARP) +#error "do not use this version of std_except.i" +#endif + +%{ +#include <typeinfo> +#include <stdexcept> +%} + +#if defined(SWIG_STD_EXCEPTIONS_AS_CLASSES) + +namespace std { + struct exception + { + virtual ~exception() throw(); + virtual const char* what() const throw(); + }; + + struct bad_cast : exception + { + }; + + struct bad_exception : exception + { + }; + + struct logic_error : exception + { + logic_error(const string& msg); + }; + + struct domain_error : logic_error + { + domain_error(const string& msg); + }; + + struct invalid_argument : logic_error + { + invalid_argument(const string& msg); + }; + + struct length_error : logic_error + { + length_error(const string& msg); + }; + + struct out_of_range : logic_error + { + out_of_range(const string& msg); + }; + + struct runtime_error : exception + { + runtime_error(const string& msg); + }; + + struct range_error : runtime_error + { + range_error(const string& msg); + }; + + struct overflow_error : runtime_error + { + overflow_error(const string& msg); + }; + + struct underflow_error : runtime_error + { + underflow_error(const string& msg); + }; +} + +#endif diff --git a/contrib/tools/swig/Lib/std/std_string.i b/contrib/tools/swig/Lib/std/std_string.i new file mode 100644 index 0000000000..35fcdd16c6 --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_string.i @@ -0,0 +1,13 @@ +%include <std/std_basic_string.i> + +/* plain strings */ + +namespace std +{ + %std_comp_methods(basic_string<char>); + %naturalvar string; + typedef basic_string<char> string; +} + + +%template(string) std::basic_string<char>; diff --git a/contrib/tools/swig/Lib/std/std_vector.i b/contrib/tools/swig/Lib/std/std_vector.i new file mode 100644 index 0000000000..b35f03bea2 --- /dev/null +++ b/contrib/tools/swig/Lib/std/std_vector.i @@ -0,0 +1,225 @@ +// +// std::vector +// + +%include <std_container.i> + +// Vector + +%define %std_vector_methods(vector...) + %std_sequence_methods(vector) + + void reserve(size_type n); + size_type capacity() const; +%enddef + + +%define %std_vector_methods_val(vector...) + %std_sequence_methods_val(vector) + + void reserve(size_type n); + size_type capacity() const; +%enddef + + +// ------------------------------------------------------------------------ +// std::vector +// +// The aim of all that follows would be to integrate std::vector with +// as much as possible, namely, to allow the user to pass and +// be returned tuples or lists. +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::vector<T>), f(const std::vector<T>&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::vector<T> can be passed. +// -- f(std::vector<T>&), f(std::vector<T>*): +// the parameter may be modified; therefore, only a wrapped std::vector +// can be passed. +// -- std::vector<T> f(), const std::vector<T>& f(): +// the vector is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::vector<T>& f(), std::vector<T>* f(): +// the vector is returned by reference; therefore, a wrapped std::vector +// is returned +// -- const std::vector<T>* f(), f(const std::vector<T>*): +// for consistency, they expect and return a plain vector pointer. +// ------------------------------------------------------------------------ + +%{ +#include <vector> +%} + +// exported classes + + +namespace std { + + template<class _Tp, class _Alloc = allocator< _Tp > > + class vector { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(_Tp); + %traits_enum(_Tp); + + %fragment(SWIG_Traits_frag(std::vector< _Tp, _Alloc >), "header", + fragment=SWIG_Traits_frag(_Tp), + fragment="StdVectorTraits") { + namespace swig { + template <> struct traits<std::vector< _Tp, _Alloc > > { + typedef pointer_category category; + static const char* type_name() { + return "std::vector<" #_Tp "," #_Alloc " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp, _Alloc >); + +#ifdef %swig_vector_methods + // Add swig/language extra methods + %swig_vector_methods(std::vector< _Tp, _Alloc >); +#endif + + %std_vector_methods(vector); + }; + + // *** + // This specialization should disappear or get simplified when + // a 'const SWIGTYPE*&' can be defined + // *** + template<class _Tp, class _Alloc > + class vector< _Tp*, _Alloc > { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(_Tp); + + %fragment(SWIG_Traits_frag(std::vector< _Tp*, _Alloc >), "header", + fragment=SWIG_Traits_frag(_Tp), + fragment="StdVectorTraits") { + namespace swig { + template <> struct traits<std::vector< _Tp*, _Alloc > > { + typedef value_category category; + static const char* type_name() { + return "std::vector<" #_Tp " *," #_Alloc " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp*, _Alloc >); + +#ifdef %swig_vector_methods_val + // Add swig/language extra methods + %swig_vector_methods_val(std::vector< _Tp*, _Alloc >); +#endif + + %std_vector_methods_val(vector); + }; + + // *** + // const pointer specialization + // *** + template<class _Tp, class _Alloc > + class vector< _Tp const *, _Alloc > { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp const * value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(_Tp); + + %fragment(SWIG_Traits_frag(std::vector< _Tp const*, _Alloc >), "header", + fragment=SWIG_Traits_frag(_Tp), + fragment="StdVectorTraits") { + namespace swig { + template <> struct traits<std::vector< _Tp const*, _Alloc > > { + typedef value_category category; + static const char* type_name() { + return "std::vector<" #_Tp " const*," #_Alloc " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp const*, _Alloc >); + +#ifdef %swig_vector_methods_val + // Add swig/language extra methods + %swig_vector_methods_val(std::vector< _Tp const*, _Alloc >); +#endif + + %std_vector_methods_val(vector); + }; + + // *** + // bool specialization + // *** + + template<class _Alloc > + class vector<bool,_Alloc > { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef bool value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef bool const_reference; + typedef _Alloc allocator_type; + + %traits_swigtype(bool); + + %fragment(SWIG_Traits_frag(std::vector<bool, _Alloc >), "header", + fragment=SWIG_Traits_frag(bool), + fragment="StdVectorTraits") { + namespace swig { + template <> struct traits<std::vector<bool, _Alloc > > { + typedef value_category category; + static const char* type_name() { + return "std::vector<bool, _Alloc >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool, _Alloc >); + + +#ifdef %swig_vector_methods_val + // Add swig/language extra methods + %swig_vector_methods_val(std::vector<bool, _Alloc >); +#endif + + %std_vector_methods_val(vector); + +#if defined(SWIG_STD_MODERN_STL) && !defined(SWIG_STD_NOMODERN_STL) + void flip(); +#endif + + }; + +} |