There is a software complex - written in Visual C ++: a solution consisting of several projects that are not closely related to each other, but each one has its own state.

I would like to store the state of individual modules in configs. In advance, I do not know how much and what will be stored - just a set of different types of elements string, int, float ... At this stage, I intend to use ini files. (using the https://github.com/benhoyt/inih library)

I have to first specify the types of variables, then the variables themselves, somehow store all this. But at the same time, access to variables should be fast. (So you need to use macros or inline templates ...) The problem seems to me quite voluminous and definitely there are competent implementations.

What is ready ready handling of user variables?

  • one
    Google about serialization - Abyx

2 answers 2

  1. Boost.Program_options

    http://www.boost.org/doc/libs/1_61_0/doc/html/program_options.html

  2. QSettings from Qt (description in Russian from the old version - there are new ones similar)

    http://doc.crossplatform.ru/qt/4.7.x/qsettings.html

    Record:

      QSettings settings("Moose Soft", "Clipper"); settings.beginGroup("MainWindow"); settings.setValue("size", size()); settings.setValue("pos", pos()); settings.endGroup(); 

    Reading:

      QSettings settings("Moose Soft", "Clipper"); settings.beginGroup("MainWindow"); resize(settings.value("size", QSize(400, 400)).toSize()); move(settings.value("pos", QPoint(200, 200)).toPoint()); settings.endGroup(); 
  3. Perhaps there are solutions in WinAPI ...

  • WinAPI doesn’t like large INI files if I don’t confuse anything. Qt is ok with them. - Vladimir Martyanov

To store the state - create a separate class in which all the necessary variables will be stored. Before closing the program, perform a method that saves all the necessary data to this class. After starting the program, execute a method that, on the basis of data from the class, initializes all necessary values.

QList <QString> and QDataStream

Here the technique is described how to quickly write / read the states of this class into a binary file using Qt. If you need a readable config, you can look in the direction of XML. According to personal performance measurements:

  1. Binary serialization - 1x time
  2. Binary serialization using QVarianMap - 10x time
  3. XML serialization - 100x times.

If you need to write-read large amounts of data, it is better to use the first option.

If you do not want to bind to Qt, you can write classes in Xml, for example, using TinyXml. An approximate algorithm like here https://github.com/sashatref/xmlserializer/tree/master/tinyxmlbased