• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Obj-C++: instantiating C++ type ivar within an obj-c class [Solved]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obj-C++: instantiating C++ type ivar within an obj-c class [Solved]


  • Subject: Re: Obj-C++: instantiating C++ type ivar within an obj-c class [Solved]
  • From: Ben Dubin-Thaler <email@hidden>
  • Date: Sun, 28 Aug 2005 16:50:46 -0400


On Aug 28, 2005, at 3:07 PM, Chris Hanson wrote:

One thing you can do is encapsulate your C++ constructs even more than you already have, so an SLContour has a pointer to a structure that actually contains them (say a struct SLContourData) defined in SLContourData.mm

Done, a simple solution and the problem is solved!

The key was to be able to name and instantiate the data objects in the header without having to use any C++ specific code until the main class file. By making a type that is just a c struct, SLContourData, that contains the C++ data types, other classes can read the header file SLContour.h and see only the name of the c struct and not the C+ + code that defines the c struct. From my perspective, the slightly tricky concept was naming a struct type in the header file but not define the struct until you're in SLContour.mm.

Thanks a bunch, Chris!
Ben


Here's the .h and the .mm files with the solution worked in:

//////////////////////////////
// SLContour.h
//
#import <Cocoa/Cocoa.h>

@interface SLContour : NSObject
{
NSMutableDictionary* parameters; // holds parameters for the contour
@private
struct SLContourData *contourData; // <<<< name and instantiate the structure
}


- (id) init;
- (id) dealloc;
- (void) loadJakeContourFromMatfile: (NSString*) matFileName;

@end


////////////////////////////// // SLContour.mm // #import "SLContour.h" #include <Array2D.h>

<snip>

struct SLContourData {
    Array2D<double> vnArc;
    Array2D<int> contourXY;
    Array2D<double> area;
};

@implementation SLContour

- (id)init {
if (self = [super init]) {
parameters = [[NSMutableDictionary alloc] init];
contourData = new SLContourData; // <<<<<< initializing structure
} else return null;
return self;
}


- (void) dealloc
{
    [parameters release];
    delete contourData; // <<<<<< deallocating structure
    [super dealloc];
}

- (void) loadJakeContourFromMatfile: (NSString*) matFileName
{

    string matfile = [matFileName UTF8String];

perimMatArray vnMat(matfile); // load non-normalized spreading data
contourData->vnArc = vnMat.getArray2D(); // <<<<<< accessing structture


MatArray areaMat(matfile, "a"); // load area data
contourData->area = areaMat.getArray2D(); // <<<<<< accessing structture
<snip>
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Obj-C++: instantiating C++ type ivar within an obj-c class (From: Ben Dubin-Thaler <email@hidden>)
 >Re: Obj-C++: instantiating C++ type ivar within an obj-c class (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Apple crash reports
  • Next by Date: Re: Apple crash reports
  • Previous by thread: Re: Obj-C++: instantiating C++ type ivar within an obj-c class
  • Next by thread: Re:Obj-C++: instantiating C++ type ivar within an obj-c class
  • Index(es):
    • Date
    • Thread