Sign in to follow this  

Reading random files at run-time

This topic is 4749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all. i will explain my situation briefly. i have an openGL program where i read in different types of terrain. some for land, some a little different with some water etc etc. this will used in testing out some information. the problem is that reading in the data is in different random formats and i am trying to build my class around this concept. right now my constructor is sent a flag from the main program, that represents what type of file it is so i know how to read in the certain file. lets say i didnt send it a flag. what would be the best way to set up my class to be able to read any file at run time. basiically all i want to be to do is this: myClass a(file_name); myClass b(file_name); etc etc and from there and can somehow read ahead in the file to determine how the data format is written out.. thanks all in advance!

Share this post


Link to post
Share on other sites
You mark the data with it's format, i.e. some bytes in the beginning of the file will say what type it is. Or in the simplest form, the file extension of the file tells it's type.. This is not a question of how to design your classes, but a question of how to design your file formats.

Share this post


Link to post
Share on other sites
yeah but i dont design the file formats.. i get the files from the web. they are not always the same though depending on what was decided to be left out or added each time. there is also no header file. the extensions are the same.

Share this post


Link to post
Share on other sites
If the differences between the file formats are such that you can't deduce the file format, there's nothing to do but to denote the formats by hand. Programs can't do magic.

But maybe there's some dissimilarity that can be used to deduce the format. Such that if the format of file "Foo.dat" were X, byte 10101010 at position 3 would result in a crash in the loader, but for format Y that byte is OK. You just need to compare the formats to each other yourself.

Share this post


Link to post
Share on other sites
Quote:
Original post by OpenGL_Guru
yeah but i dont design the file formats.. i get the files from the web. they are not always the same though depending on what was decided to be left out or added each time. there is also no header file. the extensions are the same.


Not a "header file", a file header. The first few bytes of the file. Most file formats are self-identifying; the beginning of the file includes "meta-data" which indicates the format of the data, the size of the thing being represented, etc.

Share this post


Link to post
Share on other sites

This topic is 4749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this