Best/simplest way to load data from disk
I feel really stupid asking this because it's probably the first thing you get taught if you have a formal education in programming, but since I'm self taught and I've always hated learning about I/O... 
I want to store my data for maps, animations and so on as text files so that I can edit them by hand. My first thought is to use either C++ streams or C stdio in text mode. I can read my books and look up tutorials to discover how to actually do it, but I wondered if anyone can give pros and cons for choosing one over the other.
I've also been using the Core Foundation XML parser for data files, but I find it rather cumbersome. Is there anything else that would be a better solution for loading really simple text data?

I want to store my data for maps, animations and so on as text files so that I can edit them by hand. My first thought is to use either C++ streams or C stdio in text mode. I can read my books and look up tutorials to discover how to actually do it, but I wondered if anyone can give pros and cons for choosing one over the other.
I've also been using the Core Foundation XML parser for data files, but I find it rather cumbersome. Is there anything else that would be a better solution for loading really simple text data?
Expat is a good XML parser if that's what you want.
C's stdio is probably the easiest way to read files.
C's stdio is probably the easiest way to read files.
Thanks, I'll look into Expat (possibly with a C++ wrapper). I'm also doing some experiment with C's stdio right now... hopefully I'll have figured it out in a few days.
If anyone else has any other thoughts or opinions, I'm still keen to hear them!
If anyone else has any other thoughts or opinions, I'm still keen to hear them!
also check out tiny xml
<http://www.grinninglizard.com/tinyxml/>
<http://sourceforge.net/projects/tinyxml>
<http://www.grinninglizard.com/tinyxml/>
<http://sourceforge.net/projects/tinyxml>
I went through the same thing, and found Navigation Services to be a little overwhelming. I ended up using fopen(), etc., which seems to work fine.
Quote:Originally posted by codemattic
also check out tiny xml
That looks very good, especially in terms of being pretty simple and written in C++! I may well end up using tinyxml.
Quote:Originally posted by Jesse
I went through the same thing, and found Navigation Services to be a little overwhelming. I ended up using fopen(), etc., which seems to work fine.
Well, Navigation Services is supposed to help you locate the file using a dialog - it doesn't actually open the file for you. Are you referring to FSOpenFork(), FSRead() etc.?
Incidentally, how are you storing your data in your files? Do you have a sort of formal syntax or is it just a sequence of unlabelled data?
Quote:Well, Navigation Services is supposed to help you locate the file using a dialog - it doesn't actually open the file for you. Are you referring to FSOpenFork(), FSRead() etc.?Yeah, I know. But stdio still seems easier.
Quote:Incidentally, how are you storing your data in your files? Do you have a sort of formal syntax or is it just a sequence of unlabelled data?Most of what I've done so far has been loading other file formats - Quake levels, 3DS models, etc. What I hope to do, though, is implement stream constructors for a lot of my classes, in which case the data will be in a block mirroring the member data of the class. (As always, I could be wrong about whether this is a good way to go about it...)
Careful about byte-swapping...
Quote:Originally posted by Jesse
...the data will be in a block mirroring the member data of the class.
Be careful about member data layout as well. You probably shouldn't be trying to load a block of data directly over an instantiated object in C++ unless you know exactly what you're doing.
I'm going to keep experimenting with cstdio, but I reckon I'm going to carry on using XML because its built in support for hierarchic structure is better than anything I can be bothered to write! My plan when loading from XML is like this:
When I encounter an element which represents an C++ object, I create (new) one of those objects. I then configure the newly created object by calling methods on it for each of the attributes it supports. I use attributes for singular parameters and child elements when I either want to support multiple occurrences of the same thing or if I want something processed in sequence. For example, I might use child elements of a 'shape' element to apply a series of transforms or something.
The important idea I'm trying to apply is that the objects I'm creating don't need to know anything about what kind of data file they're being loaded from. Instead, they're created and configured by a separate loader class.
Does that sound sensible?
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| unable to load app with loader | sefiroths | 2 | 2,544 |
Nov 29, 2011 01:12 PM Last Post: sefiroths |
|
| Sound from disk in Carbon? | Fenris | 6 | 3,771 |
Feb 12, 2003 10:43 PM Last Post: Fenris |
|

