Obj-C to C++

Hi,

Have anyone done this in C++ (Cocos2d-x)?
http://abitofcode.com/2011/07/irregular-touch-detection-when-cgrect-is-not-enough-part-1/

Or can anyone please show me the C++ (Cocos2d-x) of this:

// get the filepath to the Raw data
        NSString *filePath = 
        [[NSBundle mainBundle] pathForResource:@"_20110705_piranah_hotspot" ofType:@"raw"];  
 
        // load it as NSData
        self.lookupData = [NSData dataWithContentsOfFile:filePath];

Is it possible?

Thanks in advance! :slight_smile:

just put your code in an Objective-C++ file instead of Objective-C

@corytrese Thanks for the reply. The code above is not mine. Unfortunately, I have little to no knowledge when it comes to Objective-C or Objective-C++ for that matter. I’m using visual studio as my development environment.

jonah1nine wrote:

@corytrese Thanks for the reply. The code above is not mine. Unfortunately, I have little to no knowledge when it comes to Objective-C or Objective-C++ for that matter. I’m using visual studio as my development environment.

In that case, your question doesn’t make much sense. What you posted is Objective-C, a language you cannot use with MSVC (Visual Studio’s compiler.)

My answer was how to call that code from Cocos2d-x, which is to use an Objective-C++ bridge compiled in XCode – all of this is iOS specific.

NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers – manipulating and parsing those byte buffers from C++ in Visual Studio is possible, but it won’t be easy.

If we were working on the project together I would want to understand what “_20110705_piranah_hotspot” is and why we think we need to parse it with NSData. Was it created with NSData?

@corytrese Thanks for your reply. Sorry if my question doesn’t make sense; English is not my main language. I understand NSData is of Objective-C, I was just hoping someone might have made a C++ version of it. And after a long research, I’ve found this:

 Data FileUtils::getDataFromFile(const std::string& filename)
 {
    return getData(filename, false);
 }

which I suppose is the cocos2d-x version of self.lookupData = [NSData dataWithContentsOfFile:filePath];

Apologies for just dumping random code with some random file name. I assumed people will click on the link and read through the whole thing. I assumed wrong.

Although I’ve found the cocos2d-x version of getting the data from file, unfortunately, I’m still stuck with one problem. This:

// get the data at the offset
    NSRange range = {offset,sizeof(Byte)};
    NSData *pixelValue = [lookupData subdataWithRange:range];

Sadly, cocos2d-x Data class has no equivalent of subdataWithRange function. :frowning:
Hopefully, they will add it soon. But I think I will have to do a lot more research to find the solution I’m after.

Thank you for your time.