diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 59b0a84f0..9d07bc830 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -4,14 +4,14 @@ * SWIG typemaps for std::map< K, T, C > * * The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>. - * + * * Using this wrapper is fairly simple. For example, to create a map from integers to doubles use: * * %include * %template(MapIntDouble) std::map * * Notes: - * 1) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with + * 1) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with * C++ std::map wrappers. * * Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents! @@ -55,8 +55,8 @@ } public bool IsReadOnly { - get { - return false; + get { + return false; } } @@ -84,7 +84,7 @@ return vals; } } - + public void Add(global::System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) { Add(item.Key, item.Value); } @@ -143,7 +143,7 @@ /// whenever the collection is modified. This has been done for changes in the size of the /// collection but not when one of the elements of the collection is modified as it is a bit /// tricky to detect unmanaged code that modifies the collection under our feet. - public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator, + public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator, global::System.Collections.Generic.IEnumerator> { private $csclassname collectionRef; @@ -206,7 +206,7 @@ currentObject = null; } } - + %} public: @@ -251,7 +251,7 @@ if (iter != $self->end()) { $self->erase(iter); return true; - } + } return false; } @@ -285,12 +285,12 @@ %csmethodmodifiers std::map::destroy_iterator "private" // Default implementation -namespace std { +namespace std { template > class map { SWIG_STD_MAP_INTERNAL(K, T, C) }; } - + // Legacy macros (deprecated) %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 52a865e67..0d1476f7f 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -5,9 +5,9 @@ * C# implementation * The C# wrapper is made to look and feel like a C# System.Collections.Generic.List<> collection. * - * Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with + * Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with * C++ std::vector wrappers. The IList<> interface is also implemented to provide enhanced functionality - * whenever we are confident that the required C++ operator== is available. This is the case for when + * whenever we are confident that the required C++ operator== is available. This is the case for when * T is a primitive type or a pointer. If T does define an operator==, then use the SWIG_STD_VECTOR_ENHANCED * macro to obtain this enhanced functionality, for example: * @@ -33,14 +33,14 @@ this.Add(element); } } - + public $csclassname(global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)> c) : this() { if (c == null) throw new global::System.ArgumentNullException("c"); foreach ($typemap(cstype, CTYPE) element in c) { this.Add(element); } - } + } public bool IsFixedSize { get { @@ -332,7 +332,7 @@ std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value); if (it != $self->end()) { $self->erase(it); - return true; + return true; } return false; } diff --git a/Lib/d/std_map.i b/Lib/d/std_map.i index 0e8574b8a..d2ba04118 100644 --- a/Lib/d/std_map.i +++ b/Lib/d/std_map.i @@ -16,44 +16,41 @@ #include %} -// exported class - namespace std { - template class map { - // add typemaps here - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - map(); - map(const map &); + template class map { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; + map(); + map(const map &); - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - const T& get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, const T& x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + const T& get(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); } - }; + void set(const K& key, const T& x) { + (*self)[key] = x; + } + void del(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(const K& key) { + std::map::iterator i = self->find(key); + return i != self->end(); + } + } + }; } diff --git a/Lib/java/std_map.i b/Lib/java/std_map.i index e7812f38a..2405571fa 100644 --- a/Lib/java/std_map.i +++ b/Lib/java/std_map.i @@ -16,47 +16,44 @@ #include %} -// exported class - namespace std { - template class map { - // add typemaps here - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - map(); - map(const map &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - const T& get(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, const T& x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map::iterator i = self->find(key); - return i != self->end(); - } + template class map { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; + map(); + map(const map &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + const T& get(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); } - }; + void set(const K& key, const T& x) { + (*self)[key] = x; + } + void del(const K& key) throw (std::out_of_range) { + std::map::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(const K& key) { + std::map::iterator i = self->find(key); + return i != self->end(); + } + } + }; // Legacy macros (deprecated) %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) diff --git a/Lib/java/std_vector.i b/Lib/java/std_vector.i index 3a76ec891..99fbd3e9a 100644 --- a/Lib/java/std_vector.i +++ b/Lib/java/std_vector.i @@ -20,11 +20,11 @@ // them, in order to achieve this. namespace { int size_as_int(std::size_t sz) { - if (sz > static_cast(INT_MAX)) { - throw std::out_of_range("vector size is too big to be representable as int"); - } + if (sz > static_cast(INT_MAX)) { + throw std::out_of_range("vector size is too big to be representable as int"); + } - return static_cast(sz); + return static_cast(sz); } } // anonymous namespace @@ -82,74 +82,74 @@ int size_as_int(std::size_t sz) { } %} - public: - typedef size_t size_type; - typedef CTYPE value_type; - typedef CREF_TYPE const_reference; - vector(); - vector(size_type n); - size_type capacity() const; - void reserve(size_type n); - %rename(isEmpty) empty; - bool empty() const; - void clear(); - %extend { - int doSize() const { - return size_as_int(self->size()); - } + public: + typedef size_t size_type; + typedef CTYPE value_type; + typedef CREF_TYPE const_reference; + vector(); + vector(size_type n); + size_type capacity() const; + void reserve(size_type n); + %rename(isEmpty) empty; + bool empty() const; + void clear(); + %extend { + int doSize() const { + return size_as_int(self->size()); + } - void doAdd(const value_type& value) { - self->push_back(value); - } + void doAdd(const value_type& value) { + self->push_back(value); + } - void doAdd(int index, const value_type& value) throw (std::out_of_range) { - const int size = size_as_int(self->size()); - if (0 <= index && index <= size) { - self->insert(self->begin() + index, value); - } else { - throw std::out_of_range("vector index out of range"); - } - } - - value_type doRemove(int index) throw (std::out_of_range) { - const int size = size_as_int(self->size()); - if (0 <= index && index < size) { - CTYPE const old_value = (*self)[index]; - self->erase(self->begin() + index); - return old_value; - } else { - throw std::out_of_range("vector index out of range"); - } - } - - CREF_TYPE doGet(int i) throw (std::out_of_range) { - const int size = size_as_int(self->size()); - if (i>=0 && isize()); - if (i>=0 && isize()); - if (0 <= fromIndex && fromIndex <= toIndex && toIndex <= size) { - self->erase(self->begin() + fromIndex, self->begin() + toIndex); - } else { - throw std::out_of_range("vector index out of range"); - } - } + void doAdd(int index, const value_type& value) throw (std::out_of_range) { + const int size = size_as_int(self->size()); + if (0 <= index && index <= size) { + self->insert(self->begin() + index, value); + } else { + throw std::out_of_range("vector index out of range"); } + } + + value_type doRemove(int index) throw (std::out_of_range) { + const int size = size_as_int(self->size()); + if (0 <= index && index < size) { + CTYPE const old_value = (*self)[index]; + self->erase(self->begin() + index); + return old_value; + } else { + throw std::out_of_range("vector index out of range"); + } + } + + CREF_TYPE doGet(int i) throw (std::out_of_range) { + const int size = size_as_int(self->size()); + if (i>=0 && isize()); + if (i>=0 && isize()); + if (0 <= fromIndex && fromIndex <= toIndex && toIndex <= size) { + self->erase(self->begin() + fromIndex, self->begin() + toIndex); + } else { + throw std::out_of_range("vector index out of range"); + } + } + } %enddef %javamethodmodifiers std::vector::doSize "private"; @@ -160,7 +160,7 @@ int size_as_int(std::size_t sz) { %javamethodmodifiers std::vector::doRemoveRange "private"; namespace std { - + template class vector { SWIG_STD_VECTOR_MINIMUM_INTERNAL(T, const T&) };