Problem in Swig using Enums for Java

View: New views
2 Messages — Rating Filter:   Alert me  

Problem in Swig using Enums for Java

by Dwarak123 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm new to SWIG and I've been trying to create Java wrappers for some existing C++ code which I have.
While doing so I ran into this problem of using Enums. for example .say we have the following classes:


/* FIlename example.h */
enum color { RED, BLUE, GREEN };

class Foo {
 public:
  Foo() { }
  static const int testenum = GREEN;
  enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
  void enum_test(speed s);
};

void enum_test(color c, Foo::speed s);


If I create a java wrappers for this file, then I get this error in Foo.java after SWIG has created the JAVA wrappers:

Foo.java:43: ';' expected
  public final static int testenum = Foo::testenum;
                                        ^
Foo.java:43: <identifier> expected
  public final static int testenum = Foo::testenum;
                                                  ^

This is actually from the java enum example that come with the SWIG package. The only line I added was "static const int testenum = GREEN" in example.h.

Can anyone please help me with this problem.

Thanks a lot.

Regards
Dwarak






-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Problem in Swig using Enums for Java

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dwarkanath Radhakrishnan wrote:

> Hi,
>
> I'm new to SWIG and I've been trying to create Java wrappers for some
> existing C++ code which I have.
> While doing so I ran into this problem of using Enums. for example .say
> we have the following classes:
>
>
> /* FIlename example.h */
> enum color { RED, BLUE, GREEN };
>
> class Foo {
>  public:
>   Foo() { }
>   static const int testenum = GREEN;
>   enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
>   void enum_test(speed s);
> };
>
> void enum_test(color c, Foo::speed s);
>
>
> If I create a java wrappers for this file, then I get this error in
> Foo.java after SWIG has created the JAVA wrappers:
>
> Foo.java:43: ';' expected
>   public final static int testenum = Foo::testenum;
>                                         ^
> Foo.java:43: <identifier> expected
>   public final static int testenum = Foo::testenum;
>                                                   ^
>
> This is actually from the java enum example that come with the SWIG
> package. The only line I added was "static const int testenum = GREEN"
> in example.h.
>
> Can anyone please help me with this problem.

If you'd put your code into a standalone interface file you'd see that
it compiles fine. I suggest you read
http://www.swig.org/Doc1.3/Java.html#constants. You probably have a
javaconst(1) in your code somewhere.

William

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user