libconfig & JSON
« on: 26 November 2014, 22:24:22 »
Hello Bruno,

Have you given thought to using XML format?
I am extensively using custom XML config files myself and read and write them with tinyxml http://www.grinninglizard.com/tinyxml2/. It's fast and header-only.
However, tinyxml does not understand DTDs for validation. If you go for XML, check this helpful image:
http://i.stack.imgur.com/hUjpw.png

[spoiler]I still owe you that 0.7 tutorial, I'm a huge slacker
« Last Edit: 26 November 2014, 22:29:25 by Heinrich »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: libconfig & JSON
« Reply #1 on: 27 November 2014, 08:33:35 »
I have though about XML, but I kindof see JSON as its successor.
XML requires you to open and close tags which means you have to write things twice.

I would choose the second or third opposed to the first one. The third one looks best here, but these key-value pairs like now are too limited.
Code: [Select]
<TextSize>5</TextSize>
"TextSize" : 5
TextSize = 5
« Last Edit: 27 November 2014, 08:35:59 by texus »

Re: libconfig & JSON
« Reply #2 on: 28 November 2014, 10:57:35 »
I have though about XML, but I kindof see JSON as its successor.
XML requires you to open and close tags which means you have to write things twice.

I would choose the second or third opposed to the first one. The third one looks best here, but these key-value pairs like now are too limited.
Code: [Select]
<TextSize>5</TextSize>
"TextSize" : 5
TextSize = 5

While 2nd and 3rd are more human-readable, the question is if you would write them manually in the first place. If I wouldn't use the GUI builder, I'd do it programmatically in my .cpp files.
Hm. And file size shouldn't be a concern. If I were not to use xml I'd probably go for JSON  instead of the 3rd option, simply because libconfig uses ascii for strings which is undesirable if you do ButtonText = "MinButtøn".
 

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: libconfig & JSON
« Reply #3 on: 28 November 2014, 15:56:20 »
Quote
the question is if you would write them manually in the first place
That is indeed an interesting question which I haven't thought about much. They will most likely have to be edited manually, but that only requires some small changes and most of the files could indeed be generated.

However, the form builder is unable to create more complex scenes. I'm not even sure if I will add it again in v0.7. It would be a great addition to have, but it takes way too much time to write and maintain and it is extremely hard to support complex things like widgets inside panels or relative positioning. And the way themes are going to work in v0.7 probably don't make it any easier.

The reason why one might write it in a text file instead of directly in the code is to avoid recompilation when e.g. only slightly changing the widget positions. So there is still some use case for writing these files by hand without putting them in the cpp file. Which is why I like it to be as readable as possible.

Quote
And file size shouldn't be a concern.
Neither file size or speed is a concern for me. It is just the readability that bothers me with xml.
But the original idea was to use xml, so maybe I should reconsider it. More people will know how to write xml than json files anyway. But we will see, I still tend to like json better.

Quote
simply because libconfig uses ascii for strings which is undesirable if you do ButtonText = "MinButtøn".
This is a valid concern, but also one that should be made for json. The jsoncons library that I was looking at also works with stings by default. I would have to read the file myself and pass the stream to jsoncons, but I even wonder if std::ifstream supports unicode.