• 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
Using C++ iostreams for file IO in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using C++ iostreams for file IO in Cocoa


  • Subject: Using C++ iostreams for file IO in Cocoa
  • From: Bert Torfs <email@hidden>
  • Date: Wed, 1 Feb 2006 20:51:58 +0100

First remark : it will make your application harder to universalize because of byte-order stuff.

I did not use streams, but - for historical reasons - the stream classes of PowerPlant. My pure C++ business layer classes (theDocument) still think they write themselves to Powerplant streams. These stream classes read or write from the NSData objects you get in the Cocoa persistency methods.

Opening files is done in the dataRepresentation from file method. All the open and save dialog stuff has been done at that time. My code looks like this

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
    /*
     Create an LStream object that takes its data from 'data'
     */
    long		theLength;
    void		*theData;

    theLength = [data length];
    theData = (void*)[data bytes];
    //    [data getBytes:theBuffer];
    LDataStream *theInputStream = new LDataStream();
    theInputStream->setBuffer(theData ,theLength);
    theDocument->initFromStream(theInputStream);
etc...
LDataStream is an unchanged powerplant class.

Saving files is done  in dataRepresentationOfType

- (NSData *)dataRepresentationOfType:(NSString *)aType
{
	NSMutableData*	theData;
	BTDataStream*	theDataStream;
	theData = [[NSMutableData dataWithCapacity:2000]autorelease];
	theDataStream  = new BTDataStream();
	theDataStream->setDataObject(theData);
	theDocument->DoSave(theDataStream);
	return theData;
}

Here, BTDataStream is an LStream (from PowerPlant) descendant that has its PutBytes method changed to write to the NSMutableData it has been given in the setDataObject method..

Hope this helps,

Bert

_______________________________________________
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


  • Follow-Ups:
    • Re: Using C++ iostreams for file IO in Cocoa
      • From: Dan Price <email@hidden>
  • Prev by Date: Re: About Universal Binaries...
  • Next by Date: NSTableView drag and drop - re-target drop to entire table?
  • Previous by thread: Re: Using C++ iostreams for file IO in Cocoa
  • Next by thread: Re: Using C++ iostreams for file IO in Cocoa
  • Index(es):
    • Date
    • Thread