Thanks for your feedback William. I will do that.

On Tue, Mar 31, 2009 at 1:09 PM, William S Fulton <wsf@fultondesigns.co.uk> wrote:
I don't personally know objective-c but it looks like something that might work :-). I suggest you put this in your application in the detailed design area along with a use case in objective-c as to how you would use it.

I suggest you also add in something similar for handling other C++ features and put that into your application. Consider static methods, enums, exception handling, global variables/methods (use something like the the type wrapper classes in C#/Java??), overloaded methods and inheritance.

Ashish Sharma wrote:
   Here is the code for accessing the C++ class as objective c class by
   wrapping the C++ class. The value types are mapped directly here.
   For string types, arrays, custom types the corresponding conversions
   can be done.  Please let me know if you have any questions over
   these conversions or if anything else is needed.

   C++ class: .h file

   class Foo {
           int ii;
          public:
           Foo(int i) : ii(i) {}
           int getI() const {
             return ii;
           }
           static Foo* makeFoo(int i) {
             return new Foo(i);
           }
           static void modify(Foo& f, int i) {
             f.i = i;
           }
   };

   Objective C interface: ObjFoo.h file

   @interface ObjFoo : NSObject
   - (id) init: (int) i;
   - (int) getl;
   + (ObjFoo*) makeFoo: (int)i;
   + (void) modify: (ObjFoo*) f (int)i;
   @end


   Objective C implementation: ObjFoo.mm file (objective c++)

   #import "ObjFoo.h"
   @implementation ObjFoo
   {
   Foo *foo; //this should really be a smart pointer to allow automatic
   memory management
   }
   - (id) init: (int)i    {
   if (self = [super init]) {
   foo = new Foo(i);
   }
   return self;
   }

   - (id)initWithFoo: (Foo*)f
   {
   if(self = [super init] {
   foo = f;
   }
   return self;
   }

   - (Foo*)foo
   {
   return foo;
   }

   - (int) getl
   {
   return foo->getl();
   }

   + (ObjFoo*) makeFoo: (int) i
   {
   return [[[ObjFoo alloc] initWithFoo: (Foo::makeFoo(i))] autorelease];
   }

   + (void) modify: (ObjFoo*) f (int)i
   {
   Foo::modify([ObjFoo foo] ,i);
   }

   @end


   Thanks!


   On Tue, Mar 31, 2009 at 1:23 AM, William S Fulton
       The ii member is private, so why is it put into the obective-c
       interface? I was really asking for all the code required for the
       marshalling from C++ to objective-c and vice versa?

       Ashish Sharma wrote:

           forgot replying to all...
           On Mon, Mar 30, 2009 at 7:19 AM, Ashish Sharma
           <ashishs99@gmail.com <mailto:ashishs99@gmail.com>
           <mailto:ashishs99@gmail.com <mailto:ashishs99@gmail.com>>>

           wrote:

              Hi Fulton!

              For this class, the interface would look as below:

              @interface Foo
              {

              int ii;

              }

              - (id) init: (int) i;  // id is like void*, and init is a
           formal
              constructor for any class

              - (int) getl; // there are no const functions in
           objective c as yet

              + (Foo*) makeFoo: (int) i; // + for static, - for
           instance member
              function

              + (void) modify: (Foo*) f (int)i;

              @end



              On Mon, Mar 30, 2009 at 1:24 AM, William S Fulton
              <wsf@fultondesigns.co.uk <mailto:wsf@fultondesigns.co.uk>
           <mailto:wsf@fultondesigns.co.uk
           <mailto:wsf@fultondesigns.co.uk>>> wrote:

                  Ashish Sharma wrote:

                      Hi all!

                      I am a computer science graduate student at
           University of
                      Minnesota -Twin Cities and I am willing to
           discuss a project
                      idea for SWIG Google summer of code.
                      I have an idea to build an objective C wrapper
           generator
                      over C++ using SWIG i.e obj-c as the target
           language to
                      SWIG. This  could be extended to, for example,
           automatically
                      generating Objective C interfaces over MICO
                      <http://www.mico.org> CORBA bindings. I have done
           this once
                      with my self-written code generation framework
           but that is
                      owned by the company I worked with plus since
           that framework
                      was in Perl it was difficult to share it and
           maintain it.
                      SWIG seems to be a mature generator meant
           specifically for
                      wrapper and interface generation so it provides
           an exactly
                      ground for this idea. Doing this would
           essentially mean that
                      objective c users would have a descent CORBA solution
                      available in objective C with powerful MICO c++
           bindings
                      underneath - a combination not yet available.


                      I have discussed this idea on the swig-gsoc IRC
           channel and
                      was given the suggestion to post this idea here.
           Could I get
                      some thoughts of experts/mentors on this group
           about this
                      project. I would appreciate any suggestions/ideas
           on this.

                  I understand that Objective C is used a lot in Mac OSX
                  programming. We'd be interested in hearing from any
           Mac people
                  who would find having Objective C wrappers useful and
           if anyone
                  familiar with Objective C could help bring this to
           life by using
                  their Objective C skills in mentoring this project
           (for which
                  there is a payment).

                  Ashish, do you have a use case, how would it work?
           Say the
                  following C++ code needs to be made available to
           Objective C
                  users, what would the interface code look like?

                  class Foo {
                   int ii;
                  public:
                   Foo(int i) : ii(i) {}
                   int getI() const {
                     return ii;
                   }
                   static Foo* makeFoo(int i) {
                     return new Foo(i);
                   }
                   static void modify(Foo& f, int i) {
                     f.i = i;
                   }
                  };

                  William







------------------------------------------------------------------------

------------------------------------------------------------------------------



------------------------------------------------------------------------

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