Commit graph

37 commits

Author SHA1 Message Date
Brad Kotsopoulos
55e835e0ae Java std::vector constructor performance improvement
Reserve before loop of push_back
Refactor li_std_vector testcase

This is a squash merge of #1552
2019-06-06 19:29:11 +01:00
William S Fulton
d67c133c4a Java/C# std::vector<bool> workarounds for clang
Workaround clang++ 9.1.0 error not knowing std::vector<bool>::const_reference
is actually typedef to bool:

  li_std_vector_wrap.cxx:1838:40: error: no matching constructor for initialization of 'std::vector<bool>::const_reference'

Workaround is use

  const value_type& getitem(int index) throw (std::out_of_range) { ...
  // bool specialization:
  bool getitem(int index) throw (std::out_of_range) { ...

instead of

  const_reference_type getitem(int index) throw (std::out_of_range) { ...

Although the following would be better, it would require a more
complicated implementation:

  const_reference_type getitem(int index) throw (std::out_of_range) { ...
  // bool specialization:
  bool getitem(int index) throw (std::out_of_range) { ...
2019-04-20 11:32:42 +01:00
William S Fulton
05c8c972cc Improve backwards compatibility in Java std::vector wrappers
For users who have typemaps for the parameters in the add and set methods
(now called doAdd and doSet).
Also for users who have typemaps for the get method - revert the return
type for get (now called doGet) back to the same return type as
std::vector::at. Correct definitions of const_reference to match the
those in the (C++11) standard.
2019-04-18 23:24:43 +01:00
William S Fulton
be491506a4 Java std::vector improvements for types that do not have a default constructor.
The std::vector wrappers have been changed to work by default for elements that are
not default insertable, i.e. have no default constructor. This has been achieved by
not wrapping:

  vector(size_type n);

Previously the above had to be ignored via %ignore.

If the above constructor is still required it can be added back in again via %extend:

  %extend std::vector {
    vector(size_type count) { return new std::vector< T >(count); }
  }

Alternatively, the following wrapped constructor could be used as it provides near-enough
equivalent functionality:

  vector(jint count, const value_type& value);

The equivalent change to std::list has also been made (std::list
wrappers were not in the previous release [3.0.12] though).
2019-03-01 18:01:14 +00:00
William S Fulton
6d27ead9c0 Add STL container copy constructors where missing
Also provide consistent copy constructor declarations.
2019-02-14 18:53:05 +00:00
William S Fulton
e26f6bb4e2 Add missing typedefs to std::vector + typedef corrections
Tests for std::vector of pointers added which check
 std::vector<T*>::const_reference and std::vector<T*>::reference
usage which gave compilation errors in Python and Perl which had
specialized these vectors incorrectly.
2019-02-13 22:46:28 +00:00
William S Fulton
6551d0fead Java vector wrappers cast correction
64 bit windows, fixes:
  warning C4267: 'initializing': conversion from 'size_t' to 'jint'
2018-05-06 09:46:37 +01:00
William S Fulton
06c275935b Add readme info for Java container wrappers 2017-07-18 07:17:03 +01:00
William S Fulton
abe53e39a9 Java std::vector minor improvement 2017-06-29 20:19:59 +01:00
William S Fulton
f4aa8b3321 Add missing typedefs to Java std::vector 2017-06-26 15:28:43 +01:00
William S Fulton
3af40e7423 Handle length_error exceptions in Java std::vector::reserve 2017-06-26 12:46:22 +01:00
William S Fulton
a8e948e96d Java std::vector std::list: add missing exception handling 2017-06-24 22:53:11 +01:00
William S Fulton
ea55c5bba0 Java std::vector std::list enhancements
- Add missing vector copy constructor
- Add constructor to initialize the containers. Note that Java's
  equivalent constructor for ArrayList just sets the capacity, whereas
  the wrappers behave like the C++ constructor and set the size. I've
  done this mainly because there has been a vector(size_type) constructor
  in the Java wrappers for many years, so best to keep this unchanged.
2017-06-24 14:30:03 +01:00
William S Fulton
5eb9f735da Add generic approach in fragments for converting size_t to Java int 2017-06-05 18:49:54 +01:00
William S Fulton
32e7074d9b Whitespace fixes in STL wrappers 2017-06-03 18:36:59 +01:00
William S Fulton
fdca8e9829 Better variable naming consistency in STL containers 2017-05-26 22:37:29 +01:00
William S Fulton
b51f32a915 Java std::vector tweaks
- Replace javacode typemap with %proxycode to make this typemap available to users
- Make doSize private.
2017-05-26 22:37:22 +01:00
William S Fulton
0bafadea5a Fix potential STL std::vector wrappers <: digraphs problems. 2017-05-26 18:55:52 +01:00
Vadim Zeitlin
eba70ed16f Add runtime checks for vector size in Java
It doesn't seem to be possible to have a Java collection with more than 2^31-1
items, but it is perfectly possible to have an std::vector with more elements
than that in C++, so add runtime checks verifying that we don't lose count of
elements in the Java wrappers.
2016-11-29 17:47:01 +01:00
Vadim Zeitlin
c79dd9d420 Make std::vector<> wrappers conform to List interface in Java
Derive the class wrapping std::vector<> in Java from java.util.AbstractList<>.
This makes it possible to use it with various algorithms working with Java
collections and, maybe even more importantly, makes it possible to iterate
over the wrapped vectors using for-each loops.

This commit is based on the original patch by Volker Diels-Grabsch from
https://sourceforge.net/p/swig/patches/278/
2016-11-29 17:46:38 +01:00
Vadim Zeitlin
7c4109c701 Add helper macro to avoid duplication in Java vector typemaps
No real changes yet, just use a C#-like macro in Java std::vector<> typemaps
too to avoid having to repeat almost exactly the same class declaration for
the general case and for the bool specialization.
2016-11-29 17:45:56 +01:00
Marvin Greenberg
843aa7cd65 Work around differences in clang libc++ std::vector<bool>::const_reference
clang++ using -stdlib=libc++ defines const_reference as a class,
to map boolean vectors onto a bit set.  Because swig does
not "see" the type as "const &" it generates incorrect code for this case,
generating a declaration like:

  const_reference result;

When const_reference is a typedef to 'bool' as is the case with stdlibc++
this works.  When this is actually a constant reference, this is clearly
invalid since it is not initialized.  For libc++, this is a class
which cannot be default constructed, resulting in an error.  The fix
is to explicitly define the various accessor extensions as having a
bool return type for this specialization.
2014-02-04 16:00:12 -05:00
William S Fulton
4308dd03cf SWIG license change - The Examples and Lib move to a very permissive license in the LICENSE file, removing the BSD license restrictions as agreed by committers since it was inadvertently introduced. Remove some examples where the impact of the license change is not clear.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11874 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-02-27 23:26:02 +00:00
William S Fulton
956c57bb03 add in correct specialization for std::vector<bool> to follow C++ standard - to create compileable wrappers with vc++ and recent return by reference changes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11153 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2009-03-16 19:33:38 +00:00
William S Fulton
2b93511d17 complete last commit
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9873 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2007-07-20 22:35:07 +00:00
William S Fulton
176984f338 std::vector parameter name changes so that these parameters can be individually singled out with typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9856 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2007-06-25 21:30:13 +00:00
William S Fulton
49be05f4fd Common template for head of each file detailing licence, distribution and authors information
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8973 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2006-03-07 00:14:10 +00:00
William S Fulton
c81c25f671 fix to set method
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8081 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2005-12-27 10:46:54 +00:00
William S Fulton
3db5c253df Fix for vector of bool
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8076 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2005-12-27 01:50:49 +00:00
William S Fulton
03a67698a9 use exception specification instead of %exception to handle STL error checking
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7352 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2005-07-27 20:09:42 +00:00
William S Fulton
effe88404d Stop using SWIG_exception. It is flawed.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7343 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2005-07-22 21:33:32 +00:00
William S Fulton
17e443899d JVM link failure on some systems fixed when using std_vector.i.
Also adds default vector constructor for use from Java.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5915 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2004-05-18 20:46:13 +00:00
Luigi Ballabio
5e161fa7cd Char and unsigned-char specialization added
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5348 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-11-19 08:38:27 +00:00
William S Fulton
2f38702eb6 Reworked std::string typemaps.
Fixes various string in std namespace problems.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5010 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-08-19 12:42:09 +00:00
William S Fulton
61e4fa4202 vector<std::string> specialization added
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5008 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-08-19 09:55:49 +00:00
William S Fulton
a63f480109 Fix for push_back as suggested by Gualtiero Chiaia
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4715 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-04-26 12:54:52 +00:00
Dave Beazley
12a43edc2d The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2002-11-30 22:01:28 +00:00