namespace alias in C++ to C#

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

namespace alias in C++ to C#

by tlackey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am new to using swig and I am having a problem accessing a class in an
aliased namespace correctly.

the header file:

namespace bar=foo;

namespace foo {
   class Handle
     public:
      ....
   };
}

swig file:


class Handle
    public:
      ....
};

When the swig wrapper is created  the code is like:

bar::Handle;

and it creates a generic swig pointer for it:
SWIGTYPE_p_bar_Handle

It also creates the C# proxy class for the generic pointer
SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.

How do I get the generic swig pointer and the Handle to be the same?

Thanks,

Truman Lackey



------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: namespace alias in C++ to C#

by lacktrum () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

tlackey wrote:
I am new to using swig and I am having a problem accessing a class in an
aliased namespace correctly.

the header file:

namespace bar=foo;

namespace foo {
   class Handle
     public:
      ....
   };
}

swig file:


class Handle
    public:
      ....
};

When the swig wrapper is created  the code is like:

bar::Handle;

and it creates a generic swig pointer for it:
SWIGTYPE_p_bar_Handle

It also creates the C# proxy class for the generic pointer
SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.

How do I get the generic swig pointer and the Handle to be the same?

Thanks,

Truman Lackey



------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
To answer my own question I placed the following in my .i file:

namespace foo {
   class Handle
     public:
      ....
   };
}

class Handle
    public:
      ....
};

This handles both namespaced references to Handle and non namespace references.
Is there possible a more elegant way to resolve this?  

As it is right now I have a lot of class code replication in my SWIG file.



Re: namespace alias in C++ to C#

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

tlackey@... wrote:

> I am new to using swig and I am having a problem accessing a class in an
> aliased namespace correctly.
>
> the header file:
>
> namespace bar=foo;
>
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
>
> swig file:
>
>
> class Handle
>     public:
>       ....
> };
>
> When the swig wrapper is created  the code is like:
>
> bar::Handle;
>
> and it creates a generic swig pointer for it:
> SWIGTYPE_p_bar_Handle
>
> It also creates the C# proxy class for the generic pointer
> SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.
>
> How do I get the generic swig pointer and the Handle to be the same?
>
Give SWIG valid C++ code that will compile with a C++ compiler, for example:

%inline %{

namespace foo {
    class Handle {
      public:
//      ....
    };
}
namespace bar=foo;
void func(bar::Handle) {}

%}

William

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: namespace alias in C++ to C#

by David Piepgrass :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> To answer my own question I placed the following in my .i file:
>
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
>
> class Handle
>     public:
>       ....
> };
>
> This handles both namespaced references to Handle and non namespace
> references.
> Is there possible a more elegant way to resolve this?

Might I suggest:

namespace foo {
   class Handle
     public:
      ....
   };
}
typedef foo::Handle Handle;

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: namespace alias in C++ to C#

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

lacktrum wrote:

>
> tlackey wrote:
>> I am new to using swig and I am having a problem accessing a class in an
>> aliased namespace correctly.
>>
>> the header file:
>>
>> namespace bar=foo;
>>
>> namespace foo {
>>    class Handle
>>      public:
>>       ....
>>    };
>> }
>>
>> swig file:
>>
>>
>> class Handle
>>     public:
>>       ....
>> };
>>
>> When the swig wrapper is created  the code is like:
>>
>> bar::Handle;
>>
>> and it creates a generic swig pointer for it:
>> SWIGTYPE_p_bar_Handle
>>
>> It also creates the C# proxy class for the generic pointer
>> SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.
>>
>> How do I get the generic swig pointer and the Handle to be the same?
>>
>> Thanks,
>>
>> Truman Lackey
>>
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Swig-user mailing list
>> Swig-user@...
>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>
>>
>
> To answer my own question I placed the following in my .i file:
>
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
>
> class Handle
>     public:
>       ....
> };
>
> This handles both namespaced references to Handle and non namespace
> references.
> Is there possible a more elegant way to resolve this?  
>
> As it is right now I have a lot of class code replication in my SWIG file.
>
Did you see my reply? If you give SWIG the correct C++ code it should do
the right thing. You can do this by replicating the classes *exactly* in
your interface file or more simply use %include of the original headers.

William

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: namespace alias in C++ to C#

by lacktrum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


wsfulton wrote:
lacktrum wrote:
>
> tlackey wrote:
>> I am new to using swig and I am having a problem accessing a class in an
>> aliased namespace correctly.
>>
>> the header file:
>>
>> namespace bar=foo;
>>
>> namespace foo {
>>    class Handle
>>      public:
>>       ....
>>    };
>> }
>>
>> swig file:
>>
>>
>> class Handle
>>     public:
>>       ....
>> };
>>
>> When the swig wrapper is created  the code is like:
>>
>> bar::Handle;
>>
>> and it creates a generic swig pointer for it:
>> SWIGTYPE_p_bar_Handle
>>
>> It also creates the C# proxy class for the generic pointer
>> SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.
>>
>> How do I get the generic swig pointer and the Handle to be the same?
>>
>> Thanks,
>>
>> Truman Lackey
>>
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Swig-user mailing list
>> Swig-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>
>>
>
> To answer my own question I placed the following in my .i file:
>
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
>
> class Handle
>     public:
>       ....
> };
>
> This handles both namespaced references to Handle and non namespace
> references.
> Is there possible a more elegant way to resolve this?  
>
> As it is right now I have a lot of class code replication in my SWIG file.
>
Did you see my reply? If you give SWIG the correct C++ code it should do
the right thing. You can do this by replicating the classes *exactly* in
your interface file or more simply use %include of the original headers.

William

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Thanks for the input.  But I still have a problem with the aliased namespace.  I can get it halfway working.  Meaning I can either get bar::Handle to work or foo::Handle but not both.

The way the code works is that i have a namespace of say foo that is wrapped by other code that aliases foo to bar.  When I look at the c++ code created by swig for these header files I have foo::Handle and bar::Handle in the wrapper code.  I have tried various means to get them to be the same types including using %include on the header files.  When I use a typedef it seems to ignore it. Do you have any other ideas on how I can get this working?

Thanks,

Truman

Re: namespace alias in C++ to C#

by lacktrum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


lacktrum wrote:
wsfulton wrote:
lacktrum wrote:
>
> tlackey wrote:
>> I am new to using swig and I am having a problem accessing a class in an
>> aliased namespace correctly.
>>
>> the header file:
>>
>> namespace bar=foo;
>>
>> namespace foo {
>>    class Handle
>>      public:
>>       ....
>>    };
>> }
>>
>> swig file:
>>
>>
>> class Handle
>>     public:
>>       ....
>> };
>>
>> When the swig wrapper is created  the code is like:
>>
>> bar::Handle;
>>
>> and it creates a generic swig pointer for it:
>> SWIGTYPE_p_bar_Handle
>>
>> It also creates the C# proxy class for the generic pointer
>> SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.
>>
>> How do I get the generic swig pointer and the Handle to be the same?
>>
>> Thanks,
>>
>> Truman Lackey
>>
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Swig-user mailing list
>> Swig-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>
>>
>
> To answer my own question I placed the following in my .i file:
>
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
>
> class Handle
>     public:
>       ....
> };
>
> This handles both namespaced references to Handle and non namespace
> references.
> Is there possible a more elegant way to resolve this?  
>
> As it is right now I have a lot of class code replication in my SWIG file.
>
Did you see my reply? If you give SWIG the correct C++ code it should do
the right thing. You can do this by replicating the classes *exactly* in
your interface file or more simply use %include of the original headers.

William

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Thanks for the input.  But I still have a problem with the aliased namespace.  I can get it halfway working.  Meaning I can either get bar::Handle to work or foo::Handle but not both.

The way the code works is that i have a namespace of say foo that is wrapped by other code that aliases foo to bar.  When I look at the c++ code created by swig for these header files I have foo::Handle and bar::Handle in the wrapper code.  I have tried various means to get them to be the same types including using %include on the header files.  When I use a typedef it seems to ignore it. Do you have any other ideas on how I can get this working?

Thanks,

Truman
I got it working.  I realized I was not %including the .h file that aliased the namespace.
When I used %include on the header with the alias, it worked.

Thanks,

Truman