Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / DGDK File Commands

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 13th Jun 2008 04:22
The documentation is lacking in description of the file commands. These may be stupid questions, but, I don't quite understand the usage of some of the commands. For instance, say I would like to save some values in a file called "test.test". So, I start the code like so:



Then, I want to save a vector of vectors of integers ( multi-dimensional vector of integers ) to the file. The documentation doesn't give any information about exactly how the information is saved, so, I don't really know how it will work if I implement the following code:



Will I just be able to read the values with this loop?



If anyone can verify this working, or give details to how the functions work, I would greatly appreciate it.
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 13th Jun 2008 19:09 Edited at: 13th Jun 2008 19:12
Here are my thoughts:

Integers are 32-bit types...I think you are assuming that they are short integers (16-bit), so use dbRead/WriteLong, or make your vector a WORD vector, or a short int vector.

Generally, I test for existence and delete the file if it exists, rather than error out later. I understand that is pseudocode, but still, test for existence and make it work first on the positive result, rather than the negative one. That way, your code can take a common path after the existence issue is taken care of, or avoid the code to write if you want it that way, too.

GDK/DBPro file routines are not as useful as the Windows ones are. If you are up for it, check out the Windows file functions. There are two basic types, stream oriented and handle oriented. The handle oriented functions are very nice. (So are the stream ones, but they can be more difficult to work with at first, and there are several types of them, too.)

I'd recommend that you research CreateFile, ReadFile and WriteFile, which give you many options, and are not too difficult to use in most cases. Also, there is sample code in the documentation that came with VS. There is a file create attribute that takes care of overwriting files that exist, too...CREATE_ALWAYS. In addition, you can append a file and open it with complete control. Also, you can seek in both directions. (True random access.)

You can't name a vector with the name vector, but I assume you knew that already. Also, GDK cannot do that read code directly into the vector because it is not an addressable variable, it is the value at that element of the vector. You would want to read it into a variable, and assign the vector element that value using the member function push_back(). (You are growing the vector at that point, and they do not work exactly like fixed arrays do.)

When using the size member of the vector container, you can avoid a warning if you cast it to the type you are using...
x < (int)myvector.size()

size returns a type called size_t, or size_type, which is actually an unsigned integer, but casting it makes the compiler happier.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 13th Jun 2008 22:10
My other thread is here ( you may see why I steered away from the standard C++ functions for now ):

http://forum.thegamecreators.com/?m=forum_view&t=131201&b=22

I will look into CreateFile and such. Thank you for the time to fill in the lacking documentation. TGC should really release better documentation for the GDK.

Login to post a reply

Server time is: 2024-11-20 13:42:08
Your offset time is: 2024-11-20 13:42:08