Christopher Botos | 23 May 2013 15:47
Favicon

Fwd: Re: std::vector of class with no default constructor

Thanks so much, Vadim.  There were three such compile errors and this fixed two of them.
Adding the following fixed the third:

    %ignore std::vector<CppClassName>::pop;

With this, it compiled and worked!

Thanks, again.
-Chris

------------------------------------------------------------------------------
From: Vadim Zeitlin <vz-swig <at> ze...> - 2013-05-22 16:14

Hello,

I use the following before the %template directive for the classes without default ctor:

      %ignore std::vector<CppClassName>::vector(size_type);
      %ignore std::vector<CppClassName>::resize;

HTH,

VZ

-------- Original Message -------- Subject: Date: From: To:
std::vector of class with no default constructor
Wed, 22 May 2013 11:30:40 -0400
Botos, Christopher <cbotos <at> aer.com>
swig-user <at> lists.sourceforge.net.


Hi,

I have a struct that contains a member that is a vector of a class with no default constructor that is not compiling.  I condensed the problem into the short example below that gives a few of the following compile errors:
    error: no matching function for call to Instrument::Instrument()
I tried applying what is said about this in  Section 6.6.1 "Constructors and destructors" but without success.
Can someone suggest how I might get around this?
Here's the example code:


//---------------------------------------------------------
%module Band
%feature("autodoc", "1");

//%feature("valuewrapper") Instrument;
//%clearnodefaultctor;
//%nodefaultctor Instrument;
//%feature("notabstract") Instrument;

%{
#define SWIG_FILE_WITH_INIT
#include <vector>

class Instrument
{
   public:
      Instrument(int aNote) : theNote(aNote) {}
      int play() {return theNote;}
   private:
      int theNote;
};

struct Section
{
   std::vector<Instrument> theInstruments;
};
%}

%include "std_vector.i"

typedef std::list<PG::L2::LS::DateTime> DateTimeVector;
typedef std::vector<Instrument> InstrumentVector;
%template(InstrumentVector) std::vector<Instrument>;
//---------------------------------------------------------

Thanks in advance.
Regards,
Chris

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Didier Trosset | 23 May 2013 11:50
Favicon

Can SWIG Python use Python 3 common ABI?

Since Python 3.2, python has a common ABI (PEP 384). This can be used to 
create Python binary extensions that can work with all successors of 
Python 3.2 with no compilation. The exact same binary extension can be 
used, which is very interesting for deployment.

I tried to compile my SWIG generated extension with the corresponding 
macro Py_LIMITED_API but this unfortunately does not compile. Lots of 
errors are generated for undefined functions and undeclared identifiers.

Is there any plan to support this?

Best regards
Didier

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
Botos, Christopher | 22 May 2013 17:30
Favicon

std::vector of class with no default constructor

Hi,

I have a struct that contains a member that is a vector of a class with no default constructor that is not compiling.  I condensed the problem into the short example below that gives a few of the following compile errors:
    error: no matching function for call to Instrument::Instrument()
I tried applying what is said about this in  Section 6.6.1 "Constructors and destructors" but without success.
Can someone suggest how I might get around this?
Here's the example code:


//---------------------------------------------------------
%module Band
%feature("autodoc", "1");

//%feature("valuewrapper") Instrument;
//%clearnodefaultctor;
//%nodefaultctor Instrument;
//%feature("notabstract") Instrument;

%{
#define SWIG_FILE_WITH_INIT
#include <vector>

class Instrument
{
   public:
      Instrument(int aNote) : theNote(aNote) {}
      int play() {return theNote;}
   private:
      int theNote;
};

struct Section
{
   std::vector<Instrument> theInstruments;
};
%}

%include "std_vector.i"

typedef std::list<PG::L2::LS::DateTime> DateTimeVector;
typedef std::vector<Instrument> InstrumentVector;
%template(InstrumentVector) std::vector<Instrument>;
//---------------------------------------------------------

Thanks in advance.
Regards,
Chris

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Hayden Fisher | 16 May 2013 14:56
Picon

Are there any SWIG users within Brisbane?

Hi, I am attempting to wrap a C API for Java. It is an open source database.
This is causing me quite a headache, so are there any developers in the
general Brisbane area that would be interested in helping.

I do not believe the work to be extensive to someone with experience.

--
View this message in context: http://swig.10945.n7.nabble.com/Are-there-any-SWIG-users-within-Brisbane-tp13241.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
Hayden Fisher | 16 May 2013 09:21
Picon

Resolve struct property for BLOB buffer -> Java

Hi, how do I resolve a SWIGTYPE_p_unsigned_char in my SWIG interface file?

This is wrapping C -> Java

I have the following struct and underlined the culprit

*/**
Container for OGC GEOMETRYCOLLECTION Geometry
*/
typedef struct gaiaGeomCollStruct
{
/* OpenGis GEOMETRYCOLLECTION */
/** the SRID */
    int Srid;       /* the SRID value for this GEOMETRY */
/** CPU endian arch */
    char endian_arch;   /* littleEndian - bigEndian arch for target CPU */
/** BLOB Geometry endian arch */
    char endian;        /* littleEndian - bigEndian */
/** BLOB-Geometry buffer */
    const unsigned char *blob;  /* WKB encoded buffer */
//______________________________________________________________________________________
/** BLOB-Geometry buffer size (in bytes) */
    unsigned long size; /* buffer size */
/** current offset [BLOB parsing] */
    unsigned long offset;   /* current offset [for parsing] */
/** pointer to first POINT [linked list]; may be NULL */
    gaiaPointPtr FirstPoint;    /* Points linked list - first */
/** pointer to last POINT [linked list]; may be NULL */
    gaiaPointPtr LastPoint; /* Points linked list - last */
/** pointer to first LINESTRING [linked list]; may be NULL */
    gaiaLinestringPtr FirstLinestring;  /* Linestrings linked list - first
*/
/** pointer to last LINESTRING [linked list]; may be NULL */
    gaiaLinestringPtr LastLinestring;   /* Linestrings linked list - last */
/** pointer to first POLYGON [linked list]; may be NULL */
    gaiaPolygonPtr FirstPolygon;    /* Polygons linked list - first */
/** pointer to last POLYGON [linked list]; may be NULL */
    gaiaPolygonPtr LastPolygon; /* Polygons linked list - last */
/** MBR: min X */
    double MinX;        /* MBR - BBOX */
/** MBR: min Y */
    double MinY;        /* MBR - BBOX */
/** MBR: max X */
    double MaxX;        /* MBR - BBOX */
/** MBR: max Y */
    double MaxY;        /* MBR - BBOX */
/** one of GAIA_XY, GAIA_XY_Z, GAIA_XY_M, GAIA_XY_ZM */
    int DimensionModel; /* (x,y), (x,y,z), (x,y,m) or (x,y,z,m) */
/** any valid Geometry Class type */
    int DeclaredType;   /* the declared TYPE for this Geometry */
/** pointer to next item [linked list] */
    struct gaiaGeomCollStruct *Next;    /* used for linked list */
    } gaiaGeomColl;*

--
View this message in context: http://swig.10945.n7.nabble.com/Resolve-struct-property-for-BLOB-buffer-Java-tp13240.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
Christopher Botos | 14 May 2013 20:32
Favicon

Problem wrapping a struct

Hi all,

I'm trying to wrap several C++ structs, each of which has a constructor 
with an initializer list.
One of them looks something like this:

struct Measurements
{
/// default constructor
Measurements() :
dateStamp(0, 0)
{
}

Date dateStamp;
};

Note that the class "Date" does not have a default constructor.
When I compile it with swig, I get the following error:

In function ‘PyObject* _wrap_Measurements_dateStamp_get(PyObject*, 
PyObject*)’:
error: no matching function for call to ‘Date::Date()’
note: candidates are:PG::L2::LS::DateTime::DateTime(int, int)

There is an identical error for the "setter".

So this is correct ... there is no default constructor for Date, and I 
cannot alter the code.

Any ideas on what might be wrong and how to fix it?

Regards,
Chris Botos

--

-- 
Christopher R. Botos
Sr. Software Engineer
Atmospheric&  Environmental Research (AER)
131 Hartwell Avenue
Lexington, MA 02421
781-761-2347

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
Christopher Botos | 14 May 2013 21:09
Favicon

Problem wrapping a struct - FIXED

Well, adding includes (in this case for "Date") into the .i file usually helps. :-[
Sorry for adding to the email noise.
-Chris


-------- Original Message -------- Subject: Date: From: Reply-To: Organization: To:
Problem wrapping a struct
Tue, 14 May 2013 14:32:54 -0400
Christopher Botos <cbotos <at> aer.com>
cbotos <at> aer.com
Atmospheric & Environmental Research (AER)
swig-user <at> lists.sourceforge.net


Hi all, I'm trying to wrap several C++ structs, each of which has a constructor with an initializer list. One of them looks something like this: struct Measurements { /// default constructor Measurements() : dateStamp(0, 0) { } Date dateStamp; }; Note that the class "Date" does not have a default constructor. When I compile it with swig, I get the following error: In function ‘PyObject* _wrap_Measurements_dateStamp_get(PyObject*, PyObject*)’: error: no matching function for call to ‘Date::Date()’ note: candidates are:PG::L2::LS::DateTime::DateTime(int, int) There is an identical error for the "setter". So this is correct ... there is no default constructor for Date, and I cannot alter the code. Any ideas on what might be wrong and how to fix it? Regards, Chris Botos -- Christopher R. Botos Sr. Software Engineer Atmospheric& Environmental Research (AER) 131 Hartwell Avenue Lexington, MA 02421 781-761-2347
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Martin Felis | 13 May 2013 23:49
Picon

Eigen3 + std::vector + SWIG typemap -> Python

Hello everyone,

I am currently trying to wrap a C++ library[1] that optionally uses 
Eigen3 to Python using SWIG. I would like to be able to expose 
std::vector<>'s that contain Eigen3 vectors to python using std_vector.i.

However there is big catch:

The library uses Eigen3 as linear algebra package. Due to SSE 
requirements some Eigen3 types have to use a special allocator when 
storing them in a std::vector. Eigen3 comes with a handy macro that 
creates a specialization of std::vector<> that allows to use

   std::vector<EigenArrayType>

instead of the more verbose

   std::vector<EigenArrayType, Eigen::aligned_allocator<EigenArrayType> >

Basically the macro makes a specialization of

   std::vector<EigenArrayType, std::allocator<EigenArrayType> >

but uses internally the Eigen::aligned_allocator<> (see [2])

When creating a typemap like

   %template(EigenArrayTypeVectorStdAlloc) std::vector<EigenArrayType>;

I get problems as SWIG has specializations of its own concerning the 
allocator and therefore runs into problems when assigning allocators.

I can get it to work when I replace all occurences of 
std::vector<EigenArrayType> with the more verbose version, however I 
would rather not do this as this would enforce the use of Eigen3 to the 
library. Instead I would like to keep non-Eigen-specific std::vector<>s 
as Eigen is supposed to be a optional dependency.

I have set up a test project located at:
   https://bitbucket.org/MartinFelis/eigen3swig

I have also tried to create a modified version of std_vector.i to fix 
this, but so far without success.

Does anyone know how one could make this work?

Best regards,
Martin

[1] RBDL, the Rigid Body Dynamics Library (https://rbdl.bitbucket.org)
[2] Specialization of std::vector<> done by the Eigen macro
   EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Vector3d):
> namespace std {
> 	template<> class vector<Vector3d, std::allocator<Vector3d> > : public vector<Vector3d,
Eigen::aligned_allocator<Vector3d> > {
> 		typedef vector<Vector3d, Eigen::aligned_allocator<Vector3d> > vector_base;
> 		public:
> 		typedef Vector3d value_type;
> 		typedef vector_base::allocator_type allocator_type;
> 		typedef vector_base::size_type size_type;
> 		typedef vector_base::iterator iterator;
> 		explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {}
> 		template<typename InputIterator> vector(InputIterator first, InputIterator last, const
allocator_type& a = allocator_type()) : vector_base(first, last, a) {}
> 		vector(const vector& c) : vector_base(c) {}
> 		explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {}
> 		vector(iterator start, iterator end) : vector_base(start, end) {}
> 		vector& operator=(const vector& x) {
> 			vector_base::operator=(x); return *this;
> 		}
> 	};
> }

--

-- 
mail  : martin.felis <at> iwr.uni-heidelberg.de
phone : +49 6221 544983
office: IWR | Speyerer Str. 6 | Room 319 | 69115 Heidelberg | Germany

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
Russell E. Owen | 13 May 2013 22:40

wrapper for std::tr1::array

I asked earlier suggestions on wrapping C++ std::tr1::array in Python.

I finally came up with the following, which I present in case anyone 
else finds it useful. I only care about short arrays, so I didn't bother 
with a numpy interface. Suggested improvements would be welcome.

----- array.i -----

%{
#include <tr1/array>
%}

%import "std_except.i"
%include "array.h"

%extend std::tr1::array {
    inline size_t __len__() const { return $self->size(); }

    inline const value_type& _get(size_t i) const 
throw(std::out_of_range) {
        return $self->at(i);
    }

    inline void _set(size_t i, const value_type& v) 
throw(std::out_of_range) {
        $self->at(i) = v;
    }

    %pythoncode {
        def __getitem__(self, key):
            if isinstance(key, slice):
                return tuple(self._get(i) for i in 
range(*key.indices(len(self))))

            if key < 0:
                key += len(self)
            return self._get(key)

        def __setitem__(self, key, v):
            if isinstance(key, slice):
                for i in range(*key.indices(len(self))):
                    self._set(i, v[i])
            else:
                if key < 0:
                    key += len(self)
                self._set(key, v)

        def __repr__(self):
            return "%s(%s)" % (self.__class__.__name__, ", ".join(str(v) 
for v in self[:]))
    }
}

%template (ArrayD3) std::tr1::array<double, 3>;
...

------ and of array.i -----

I found that SWIG could not %include the real array.h file (some of the 
syntax confused it), so I made the following minimal copy of that. It 
could probably be even more minimal (e.g. fewer includes).

------ array.h ------

#pragma once
// minimal version of tr1::array, for SWIG

#include <new>
#include <iterator>
#include <algorithm>
#include <cstddef>
#include <bits/functexcept.h>
#include <ext/type_traits.h>

//namespace std::tr1
namespace std {
namespace tr1 {

  template<typename _Tp, std::size_t _Nm>
    struct array
    {
      typedef _Tp                      value_type;
      typedef value_type&                          reference;
      typedef const value_type&                    const_reference;
      typedef value_type*                    iterator;
      typedef const value_type*              const_iterator;
      typedef std::size_t                             size_type;
      typedef std::ptrdiff_t                          difference_type;
      typedef std::reverse_iterator<iterator>         reverse_iterator;
      typedef std::reverse_iterator<const_iterator>   
const_reverse_iterator;

      void assign(const value_type& __u);

      size_type size() const;

      reference at(size_type __n);
    };

}}

----- end of array.h -----

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
Russell E. Owen | 13 May 2013 22:29

Question: adding python instance variable to C++ class?

I have a SWIG-wrapped C++ class, for sake of argument called Obj.

I'd like to add a few python instance variables that are only visible to 
python code. (these will be point to objects I don't want to wrap in C++ 
and that the C++ code doesn't need to see).

The only way I've thought to do it is to use properties:

%copyctorObj;

%include "obj.h"

%extend Obj {
    %pythoncode {
         <at> property
        def foo(self):
            if not hasattr(self, "_foo"):
                self._foo = Foo()
            return self._foo

         <at> foo.setter
        def foo(self, value):
            self._foo = value

It works, but it's a lot of boilerplate and every read access requires 
an extra check, so it's slower than adding the instance variable at 
construction time.

Also, any suggestions on how to get the copy constructor to copy the 
python-only value(s)?

obj1 = Obj()
obj2 = Obj(obj1)

-- Russell

------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
Rishi Agarwal | 13 May 2013 06:41
Picon

Berkelium

Hi,
Is it possible to extend a extensive library such as Berkelium to Python using swig? I have tried some simpler examples but I am not able to start with Berkelium. Are there any code examples which can help me? Where can I start? I would be grateful for any help.
Thanks and Regards.

--
Rishi Agarwal
Fourth Year Undergraduate
Department of Mathematics
Indian Institute of Technology, Delhi
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane