Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1026498 Posts in 41148 Topics- by 32748 Members - Latest Member: VashtaNerada

July 24, 2014, 07:39:02 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)crossplatform ini library
Pages: [1] 2
Print
Author Topic: crossplatform ini library  (Read 722 times)
Archibald
Level 4
****


View Profile WWW Email
« on: November 09, 2012, 05:36:53 AM »

I look for a crossplatform .ini library. I tried "simpleini" but it's no good at all, it has tons of useless features (like Unicode support) and no basic stuff (like read integer, it can only read strings). I just want to read the "sound volume" from the config file and other trivial things. Preferably I would want it to be identical or almost identical to the Microsoft's ini functions (it's a rare thing to say, but they did it the right way this time).

Required licence usable for commercial game.

Anything you could recommend?
Logged

Europe1300 - Realistic Historical Medieval Sim
Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #1 on: November 09, 2012, 06:30:07 AM »

Just use simpleini.  If you can't convert from a string to an integer on your own, you have bigger problems.
Logged
Scott
Level 2
**


View Profile WWW
« Reply #2 on: November 09, 2012, 06:35:45 AM »

... it has tons of useless features (like Unicode support) ...

Also, are you so certain you will never, ever need to save a file path in your config file?

Once file paths come into play, unicode support is a must if you want people with different languages to be able to play your game. You can not even guarantee that a standard system path for that country does not use non-basic-latin characters. I could probably even tweak that stuff on my own quite-english computer.
Logged

Archibald
Level 4
****


View Profile WWW Email
« Reply #3 on: November 09, 2012, 06:52:41 AM »

Just use simpleini.  If you can't convert from a string to an integer on your own, you have bigger problems.
Yeah, I have bigger problems. And I would not want to add to these problems the need to make "enchancements" for something as simple as ini file parser Smiley
I just hope there is one that has all I need...
Logged

Europe1300 - Realistic Historical Medieval Sim
Scott
Level 2
**


View Profile WWW
« Reply #4 on: November 09, 2012, 07:06:42 AM »

Yeah, I have bigger problems. And I would not want to add to these problems the need to make "enchancements" for something as simple as ini file parser Smiley
I just hope there is one that has all I need...
Not simple.

Do you want customizable i/o? Or just read a file stream? But what if you decide to keep your config file in a packed file? You will have to be able to load it from memory... maybe you don't need this I don't know.

Will file paths be stored? Can the user enter their own name anywhere? What about support for save games? What if the person's username on the computer has Japanese characters, and you keep a list of save game files? The paths to those save game files will have Japanese characters in them on any windows system!

Okay, so you want to read strings, and integer values. What about a list of integer values. List of strings? Should it do floating point values too? How is the ini library writer supposed to know what format you want your data in? It's all text anyway - why not just read it and convert it yourself? I don't use boost myself, but here is an example:
Code:
int volume = boost::lexical_cast<int>(someIniFileValueString);

(And wanting cross platform but not unicode... that would mean the library works differently on different systems. Not a good sign for a library. For instance, in linux, unicode is basically automatic because of its favoritism towards utf8.)

Anyway - sorry to not have been more help for what you're looking for, specifically. Hopefully the above arguments help you in a different way though!
Logged

Archibald
Level 4
****


View Profile WWW Email
« Reply #5 on: November 09, 2012, 07:20:18 AM »

Do you want customizable i/o? Or just read a file stream? But what if you decide to keep your config file in a packed file? You will have to be able to load it from memory... maybe you don't need this I don't know.

Will file paths be stored? Can the user enter their own name anywhere? What about support for save games? What if the person's username on the computer has Japanese characters, and you keep a list of save game files? The paths to those save game files will have Japanese characters in them on any windows system!

Okay, so you want to read strings, and integer values. What about a list of integer values. List of strings? Should it do floating point values too? How is the ini library writer supposed to know what format you want your data in? It's all text anyway - why not just read it and convert it yourself? I don't use boost myself, but here is an example:

No, no, no Smiley I don't need any of these. I have absolutely simple needs. I want to read a string (latin chars only) and read an integer. Nothing more. I look for extreme simplicity, no need for flexibility in my case.

Preferably by just 2 functions like MS's GetPrivateProfileString() and GetPrivateProfileInt().
Logged

Europe1300 - Realistic Historical Medieval Sim
Xienen
Level 3
***


Greater Good Games


View Profile WWW
« Reply #6 on: November 09, 2012, 08:34:50 AM »

I have a cross platform INI Parser built into Paper Engine 2, but it's in straight C and is set up in such a way as to allow developers to loop through sections of the INI, for example, which may prove to be overkill for you(thus, not worth the setup time to integrate it).  It also uses Unicode which, in my opinion, is a must for a cross platform INI Parser.  The engine's open source, so you're certainly welcome to use it.

Here's the header for the config system: https://sourceforge.net/p/paperengine2/code/38/tree/trunk/Source/Core/Config.h

Here's an example of how it's used:
   peConfig config;
   peConfigSection* section;
   peConfigInit(&config, TEXT("Settings.ini"));
   section = peConfigGetSection(&g_peEngine.m_peMainConfig, TEXT("MySection"));
   myvar = peConfigSectionGetString(section, TEXT("MyVar"), myvarDefault);
Logged

rivon
Level 10
*****



View Profile
« Reply #7 on: November 09, 2012, 08:40:28 AM »

minIni
Logged
Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #8 on: November 09, 2012, 10:14:32 AM »

Yeah, I have bigger problems. And I would not want to add to these problems the need to make "enchancements" for something as simple as ini file parser Smiley
I just hope there is one that has all I need...

In the time it took you to respond to bitchily reply to my post, you could have written a function to wrap the getting of a string and converting it to an integer.
Logged
Klaim
Level 10
*****



View Profile WWW
« Reply #9 on: November 09, 2012, 03:11:37 PM »

Using C++? For ini files I tend to just use boost::property_tree, which kind of support it and you can switch to xml or info format if it's better (actually I use the info format only because I prefer it).

The 5 minute tutorial is pretty explicit.

If I must not use boost (which never happened) I tend to switch to XML or JSON libraries because they are more reliable. But if you need a ini file then I don't know what other than boost is reliable.

rivon> Didn't know this, will try sometime... (if I don't have boost available)
« Last Edit: November 09, 2012, 03:22:40 PM by Klaim » Logged

http://www.klaimsden.net | Game : NetRush | Digital Story-Telling Technologies : Art Of Sequence
rivon
Level 10
*****



View Profile
« Reply #10 on: November 09, 2012, 03:17:21 PM »

I have used minIni at first but then I discoverd pugixml and am using XML since... But if you want INI files, then minIni is very good IMO. It's just three files you add to your project.
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW Email
« Reply #11 on: November 09, 2012, 06:41:32 PM »

Weren't ini files deprecated well over a decade ago?  I swear this was the case.
Logged

Franchise - The restaurant wars begin!

What would John Carmack do?
_Tommo_
Level 8
***


frn frn frn


View Profile WWW
« Reply #12 on: November 09, 2012, 08:21:46 PM »

I don't see why you should use a library to read a string from a file, just use  std::fstream, grab line by line and parse them... it is even UTF-8 compatible.
I can't believe someone actually proposed Boost for this Facepalm

Obviously, if you ever want to extend this functionality to anything more complex than a list of key-values, using a library makes sense.
But actually I've found out that all the serialization libraries are pretty bloated & bad on the internal representation side, so I've ended up writing my own anyway.
Logged

Evan Balster
Level 10
*****


I live in this head.


View Profile WWW Email
« Reply #13 on: November 10, 2012, 12:19:19 AM »

Seconding Tommo here.

Quote
std::ifstream in(fname);

std::map<std::string, float> values;

values["volume"] = 1.0f; //default

while (in.good())
{
  std::string k;
  float v;
  in >> k >> v;
  values[k] = v;
}

volume = values["volume"];

Would parse a file like this:

Code:
volume 1.0
debug_mode 1
cheats 1

Obviously this is oversimplification.  But if you don't expect other people to edit the file there's no reason it needs to be an INI, per se.  So don't waste your time.
Logged

Creativity births expression.  Curiosity births exploration.
Our work is as soil to these seeds; our art is what grows from them...


Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
Klaim
Level 10
*****



View Profile WWW
« Reply #14 on: November 10, 2012, 01:45:48 AM »

I don't see why you should use a library to read a string from a file, just use  std::fstream, grab line by line and parse them... it is even UTF-8 compatible.
I can't believe someone actually proposed Boost for this Facepalm

Wow what's with the hate? I explained how I tends to do this.
Did you read my full message? It's useful if you already have boost available and you can change to something else (like xml). Boost property tree is about tree structures, not ini files, so you can do more complex organizations if you wish (which is why I use info files which are close to YAML).

It's stupid to say you can't believe a good potential solution is proposed. It's what he asked for. Also, I don't agree with "just use  std::fstream, grab line by line and parse them", any way to not having to write parsing code yourself is helping avoiding potential errors. So I don't agree.

Quote
Obviously, if you ever want to extend this functionality to anything more complex than a list of key-values, using a library makes sense.
But actually I've found out that all the serialization libraries are pretty bloated & bad on the internal representation side, so I've ended up writing my own anyway.

Boost property tree isn't a "serialization library", it's basically done to setup data (any type you want) in tree-like structure. You can write it in a stream if you want or use it as a dynamic properties container or both. Did you take a look at the 5 minutes tutorial?
Logged

http://www.klaimsden.net | Game : NetRush | Digital Story-Telling Technologies : Art Of Sequence
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic