wiesel wrote:
>
>
> Yes, this is possible. Read the documentation in Java.html and look for
> %javaconst.
>
> William
>
> -------------------------------------------------------------------------
>
>
> Thank you for your advice.
>
> I have read the chapter and I use the "%javaconst(1);" directive. But the
> Problem still exists. The
> reason might be the explanation of my problem. So I try ones more:
>
>
> My simple test example:
>
>
> Header File: example.h
>
> #ifdef SWIG
> %constant const int TEST_01 = 1;
> %constant const int TEST_02 = 2;
> #endif
>
> #ifndef SWIG
> const int TEST_01 = 1;
> const int TEST_02 = 2;
> #endif
>
> __________________________________
>
> SWIG File: example.i
>
> %module example
>
> %javaconst(1);
>
> %{
> #include "example.h"
> %}
>
> %include "example.h";
>
> __________________________________
>
> Java File: example.java, exampleConstants .java
>
> public class example implements exampleConstants {
> }
>
> public interface exampleConstants {
> public final static int TEST_01 = 1;
> public final static int TEST_02 = 2;
> }
>
> _____________________________________
>
>
> How can I create a result like that, without redefinig all const variables?
>
> Because without the %constant the variables are generated as read only
> variable with access by getter methods.
>
>
> with best regards
>From the end of the constants section in Java.html:
"Note: declarations declared as const are wrapped as read-only variables
and will be accessed using a getter as described in the previous
section. They are not wrapped as constants."
Note that C++ compilers assign memory to const int values, so it isn't a
true constant, eg you can cast away the const and reassign it. I think
this is why SWIG does not treat it as such. Note that you can get true
compile time constants using static const integral values defined within
a class. If you want a compile time Java const, your other options are
to change your C++ to either an unnamed enum or a #define.
William
|