Re: Saving C++ based data structures
Re: Saving C++ based data structures
- Subject: Re: Saving C++ based data structures
- From: Ricky Sharp <email@hidden>
- Date: Sun, 4 Dec 2005 19:25:44 -0600
On Dec 4, 2005, at 7:13 PM, Dan Price wrote:
I'm writing a rather complex 3D modeling application.
The interface code is standard Cocoa and Obj-C in a
document framework, but the guts of the program is C++
for the sake of speed, and overloaded operators etc
(it's quite Math heavy). I need to come up with a way
to save out the scene data to XML, but object-value
encoding is proving to be too inflexible. I have an
NSObject-based wrapper class, ShapeNode, which
maintains a pointer to a C++ class, Shape. The C++
class handles drawing to OpenGL, transformation etc.
ShapeNode has an NSMutableArray of child ShapeNodes.
The document object has a single ShapeNode, root,
which represents the top of the scene-graph hierarchy.
So I've got Obj-C wrappers, in an cocoa-style
NSMustableArray database, pointing to C++ objects.
Object-value encoding requires NSObject classes to
adhere to the Encoding protocol and must contain
standard accessors to the object data. But other than
basic stuff like name(), my interface code gets and
sets data to the C++ Shape object directly. ShapeNode
is just simple wrapper.
I could just write a routine in the document object
which visits every object and writes it's data
explicitly, but many of the C++ Shape subclasses have
unique properties (like float ratios and
feature-enablers specific to that object) which would
require the document class to know far too much about
them. I need a object-value encoding style system
where every object is simply asked to save itself and
load itself from the XML. Any ideas as to how I could
do this?
Does the data that describes Shape need to be in human-readable form
(i.e. you need to have one XML tag per attribute)? If not, you may
want to consider flattening the object into a block of data (NSData)
and archiving that.
I took a similar approach myself with some of my data. The original C
++ version (Carbon) stored all data in a flat binary file. The Cocoa
version archives many objects which all implement NSCoding. But for
some things, data residing in C structs made the most sense (I didn't
need to overhead of wrapping every last thing in a object). Those
structs are just archived via NSData.
___________________________________________________________
Ricky A. Sharp
mailto:email@hidden
Instant Interactive(tm)
http://www.instantinteractive.com
_______________________________________________
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