Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 10:47:13 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)crossplatform ini library
Pages: [1]
Print
Author Topic: crossplatform ini library  (Read 1198 times)
Chris Koźmik
Level 5
*****


Silver Lemur Games


View Profile WWW
« 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

Stellar Monarch 2 (dev log, IN DEVELOPMENT)
Stellar Monarch (dev log, released)
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

Chris Koźmik
Level 5
*****


Silver Lemur Games


View Profile WWW
« 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

Stellar Monarch 2 (dev log, IN DEVELOPMENT)
Stellar Monarch (dev log, released)
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

Chris Koźmik
Level 5
*****


Silver Lemur Games


View Profile WWW
« 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

Stellar Monarch 2 (dev log, IN DEVELOPMENT)
Stellar Monarch (dev log, released)
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

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
« 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



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
« 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

Klaim
Level 10
*****



View Profile WWW
« Reply #15 on: November 10, 2012, 02:01:10 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.

Ok, just for the sake of explaining why I find more useful to use boost property tree than this kind of implementation, here is the same but with more the example data:


Quote
boost::property_tree::ptree config;

using boost::property_tree;
void read_config( const std::string& filename )
{
   // actually you can also just provide your own stream instead of a filename
   read_ini( filename, config );

}

void write_config( const std::string& filename )
{
   write_ini( filename, config );
}

void initialize()
{
   read_config();
   const auto volume_level = config.get<float>("audio.volume");
   const auto is_debug_mode = config.get<bool>("debug_mode");
   const auto use_cheats = config.get<bool>("cheats");
   const auto username = config.get<std::string>("user.name");
   // you can also use / instead of . like "user/name"

   //...
}
void terminate()
{
   //...
    
   config.put("audio.volume", audio_volume() ); // let's assume it's a float or whatever
        // etc.

   write_config();
}


Notice how harder it is to make errors with this kind of code.
To be clear, I'm not arguing everybody should use it. I just find this useful and safer, at least in my context.
« Last Edit: November 10, 2012, 02:11:19 AM by Klaim » Logged

_Tommo_
Level 8
***


frn frn frn


View Profile WWW
« Reply #16 on: November 10, 2012, 05:36:50 AM »

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.

IF you already have Boost available obviously this makes sense (but honestly I don't like Boost at all), but still this is a problem that is so simple & basic that you should really be able to solve it by yourself in 10 minutes.
It should take less time to write that code than to download boost, imo.

So yeah, I'm not against Boost per-se in this case, rather I'm with those who say that the OP should really learn to do this first.

Also sorry, I wasn't hating on you... but I really think that C++ is a dangerous tool, and you should *really* know what you're doing before to kludge libraries together Smiley

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?

Serialization = writing/reading native language objects from a standard language protocol. It doesn't matter if and how you write it down, the serialization part is when you store stuff in a property tree (which not by chance has the same structure as XML), imo.
Logged

Klaim
Level 10
*****



View Profile WWW
« Reply #17 on: November 10, 2012, 07:19:00 AM »

IF you already have Boost available obviously this makes sense (but honestly I don't like Boost at all), but still this is a problem that is so simple & basic that you should really be able to solve it by yourself in 10 minutes.

Well I think it's even shorter to use boost property tree (if boost is installed and ready) than writing it myself, as I have automatic cast and parsing done in one function, so it's a good tool to me.

Quote
It should take less time to write that code than to download boost, imo.

Yes, I agree. It also requires some additional knowledge about boost and maybe C++ too.

Quote
So yeah, I'm not against Boost per-se in this case, rather I'm with those who say that the OP should really learn to do this first.

I agree it's better to learn how to do it first, but still the question was about a library to not have to do it (again) so to me it's a meta discussion, valid but not answering the question I tried to answer.
Anyway I get your point.

Quote
Also sorry, I wasn't hating on you... but I really think that C++ is a dangerous tool, and you should *really* know what you're doing before to kludge libraries together Smiley

I see, no offense taken.  Wink

Just a side note for readers: boost isn't a library, it's a (huge) set of library that share only one common thing: they are reviewed by very experienced developers. Soon (in relative time...) we will be able to get one library separate from the others.
Boost is a label.

Quote
Serialization = writing/reading native language objects from a standard language protocol. It doesn't matter if and how you write it down, the serialization part is when you store stuff in a property tree (which not by chance has the same structure as XML), imo.


I do not agree: I also use the property tree to manipulate dynamic data like if it was json, but in C++ (very useful to bind easily with script data). That's the primary goal of the lib actually, with serialization as a bonus.
Anyway it's another subject and not very important.

What I wanted to mean is that boost property tree does something actually simple, compared to boost serialization which, if I understand correctly, is the kind of library you were talking about (which I agree are rarely worth).

Logged

impulse9
Guest
« Reply #18 on: November 10, 2012, 07:31:50 AM »

Personally I would just code one from scratch. It's really not a very hard task. Also there are handful of libs available.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic