(C++) Class for reading Windows-INI-like files
addKeyToSection will add the key even if it exists.
Call setValue to change the value of an already existing key.
Going to change this behavior of addKeyToSection.
I didn't take a look on the empty lines yet but I defenetly will
Call setValue to change the value of an already existing key.
Going to change this behavior of addKeyToSection.
I didn't take a look on the empty lines yet but I defenetly will
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Yay! it works. Now just those empty lines and its all done.
Thanks a LOT! I can finally complete this part of my project.
Edit:
I just don't like to see 800X600 and I prefer 800x600 so I changed in get and set 2d value to read and write "x" instead of "X". Are there any more places I should change so it will follow this?
Thanks a LOT! I can finally complete this part of my project.
Edit:
I just don't like to see 800X600 and I prefer 800x600 so I changed in get and set 2d value to read and write "x" instead of "X". Are there any more places I should change so it will follow this?
There is another problem that if I wanna save a u32 value (Bits for example from the SIrrlichtCreationParameters struct) I need to cast it which a proper method can help me avoid it..
CIniFileReaderStub::setValue(..,..,u32 value)...
Edit:
And if we're at it, the tutorials at your site needs an update as they wont compile, simple typo reasons but still..
By the way, when was the last time you updated the docs?
Do I see a "Release 2.1 (Bug Fix)"..?
CIniFileReaderStub::setValue(..,..,u32 value)...
Edit:
And if we're at it, the tutorials at your site needs an update as they wont compile, simple typo reasons but still..
By the way, when was the last time you updated the docs?
Do I see a "Release 2.1 (Bug Fix)"..?
Just as I promised release 2.1 is out.
It can be found at http://btbsoft.org (I change the hoster because of these annoying ads.
Thanks MasterGod for the bug reports.
And no I didn't fix this empty line "bug". I'm trying to remove the stdlib dependencies in the next release so that the class could probably be included in Irrlicht so it doesn't make sense to fix this now.
It can be found at http://btbsoft.org (I change the hoster because of these annoying ads.
Thanks MasterGod for the bug reports.
And no I didn't fix this empty line "bug". I'm trying to remove the stdlib dependencies in the next release so that the class could probably be included in Irrlicht so it doesn't make sense to fix this now.
Last edited by Sylence on Sat Dec 27, 2008 8:07 pm, edited 1 time in total.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Np. Listen, I have a suggestion about the design. I think that if you're serious about inserting this class into Irrlicht this change has to come.
Making a template class tValue for values and then every time you work with a value its tValue type. You see where I'm heading? Cause lets say I wanna make methods to work with 12 more types, its gonna be insane to add it this way.
And it would help logically to have 1 method to Get, 1 method to Set and 1 method to Create (e.g addKeyToSection which creates new one if one doesn't exist and edit an existing one instead of having both that and setValue which now has no reason to be used - why using it if I can create and edit with addKeyToSection...)
I'm sure the chances of getting This class into irrlicht are much more greater.
P.S
Considering myself a beginner in C++ "Vs" the irrlicht community I'll still be glad to help if I can.
Also I think I'll do it anyways not just to practice templates but for the benefits I've talked about -While I'll be glad to submit and if you agree with some changes make it official.
Making a template class tValue for values and then every time you work with a value its tValue type. You see where I'm heading? Cause lets say I wanna make methods to work with 12 more types, its gonna be insane to add it this way.
And it would help logically to have 1 method to Get, 1 method to Set and 1 method to Create (e.g addKeyToSection which creates new one if one doesn't exist and edit an existing one instead of having both that and setValue which now has no reason to be used - why using it if I can create and edit with addKeyToSection...)
I'm sure the chances of getting This class into irrlicht are much more greater.
P.S
Considering myself a beginner in C++ "Vs" the irrlicht community I'll still be glad to help if I can.
Also I think I'll do it anyways not just to practice templates but for the benefits I've talked about -While I'll be glad to submit and if you agree with some changes make it official.
As far as my understanding of templates goes (which is not very far) you would still have to create a get method for every single type because the compiler can't know wheather you want the returned value to be an int or a float for example.
However the idea sounds nice. If this can be done it would be super to have the class designed that way
However the idea sounds nice. If this can be done it would be super to have the class designed that way
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Well, as far is My understanding of templates goes (which is also not very far) that is exactly what it fixes, by returning value of type tValue, in run-time it gets the right type so it has nothing to do with the compiler.Sylence wrote:As far as my understanding of templates goes (which is not very far) you would still have to create a get method for every single type because the compiler can't know wheather you want the returned value to be an int or a float for example.
Edit: I think I'm wrong about the run-time thing but I'm pretty sure the compiler wont be the problem.
Can someone with better knowledge of template clarify that?
Yes. It will NOT be runtime. Also, if you code it properly, it'll return the proper type. But you know, there's a better way
Declare 2 template var above the function, and, pass them BOTH to the function (which you'll make void). Is it ugly? yeah. Functional and efficient? yeah. Plus you can always mask it. Just pass result as a reference and modify it in the function
Declare 2 template var above the function, and, pass them BOTH to the function (which you'll make void). Is it ugly? yeah. Functional and efficient? yeah. Plus you can always mask it. Just pass result as a reference and modify it in the function
As I previously said I don't know templates very well and I thought about the idea today.
I figured out one problem: How to convert the data that comes from the file into templates if you don't know what type the user wants to have.
float int double etc. are not that problem but I can't image how to convert the data into dimension2d or other types that have more than one value.
I figured out one problem: How to convert the data that comes from the file into templates if you don't know what type the user wants to have.
float int double etc. are not that problem but I can't image how to convert the data into dimension2d or other types that have more than one value.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
-
- Posts: 58
- Joined: Tue Apr 10, 2007 7:49 pm
- Location: Karlsruhe
I wrote a Makefile for the Ini File Reader, that builds a static library.
If you like it, please feel free to distribute it with your code.
Please note, i didn't respected your directory structure, but rather threw
everything in one single directory.
If you like it, please feel free to distribute it with your code.
Code: Select all
all:
$(CXX) -I../irrlicht-1.4/include/ -c *.cpp
ar r libinireader.a *.o
everything in one single directory.
I cant get it to work here! Im using the following code to generate a ini file:
The problem is that every time on the second addKeyToSection, my game crashes. If I only set one addKeyToSection, everything works fine and the ini file appears with their values. So the array push_back call makes problems after every second addKeyToSection:
Any suggestion Sylence ?
Code: Select all
...
// checking rocket.ini for different parameters
IIniFileReader* ini = createIniFileReader("rocket.ini");
// if ini file doesnt excists, create a new one with standard parameters
if (!ini->load()) {
ini->drop();
ini = createIniFileReaderEmpty();
ini->setSaveFileName("rocket.ini");
// device section
ini->addSection("video");
ini->addKeyToSection("video", "AA", "0");
ini->addKeyToSection("video", "Bits", "32");
ini->save();
ini->drop();
}
...
Code: Select all
Sections[i]->Keys.push_back(k);
There is still no ini file at the beginning, so it couldnt be a matter of a missing empty line. What I want is to create a new ini file, and put all standard parameters in it. So if I comment the line:
out it works perfect and I get the following ini file:
But with the second addKeyToSection it crashes.
Code: Select all
ini->addKeyToSection("video", "Bits", "32");
Code: Select all
[video]
AA=0
uh bad typo in the addKeyToSection() method
this is what it should be.
wrote an i instead of an j
The archive on my website is updated too
Code: Select all
void CIniFileReaderStub::addKeyToSection(const c8 *section, const c8 *name, const c8 *value)
{
SKey* k = new SKey;
strncpy(k->Name,name,64);
if(value)
strncpy(k->Value,value,64);
for(u32 i=0; i<Sections.size(); ++i)
{
if( strcmp(Sections[i]->Name,section) == 0)
{
for(u32 j=0; j<Sections[i]->Keys.size(); ++j)
{
if( strcmp(Sections[i]->Keys[j]->Name,name) == 0)
{
strncpy(Sections[i]->Keys[j]->Value,value,64);
return;
}
}
Sections[i]->Keys.push_back(k);
break;
}
}
}
wrote an i instead of an j
The archive on my website is updated too
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.