Is there a C++ cross platform key/value API or library for C++? - c++

We want to persist some user settings int he GUI part of our code. I used to do Win32 programming exclusively and the typical way this was done was with registry settings.
I assume that this should be done with configuration files, but was wondering if there was a library or cross platform wrapper that made key/value pair persistence very easy.

Qt's QSettings class handles this:
http://doc.qt.nokia.com/4.6/qsettings.html

Boost.PropertyTree supports XML, JSON, INI config files.

There is also JSON for a lighter alternative of XML. Lots of implementations on that page too.

Qt 4 has a class for it, named QSettings. Looks exactly like what you need.

Why not use an XML as the configuration file. Then you only have to find a cross platform XML library which is easier IMO.
Here is a list of nice XML parsing solutions for C++.

Old school Berkley DB comes to mind.

Have a look at Tokyo Cabinet or at Embedded InnoDB.

In the old days we used .ini files in windows. Here is a portable version of an ini file read/write library
It will work on Windows as well as Linux.

Related

Using OpenStreetMap in my c++ program

I have a gpx file. I need a open source library that i can give it the gpx file and that it will present the route on a map. Does anyone know such a thing?
I'm writing in c++ on windows xp.
thanks in advance!!
There exists a bunch of Frameworks to map the OSM APIs to different languages.
Please check out this wiki-page from OSM: http://wiki.openstreetmap.org/wiki/Develop/Frameworks
I think what you search for can be found under Widgets like for example "COSMCtrl 1.1.3"

C++, console Application, reading files from directory

I have a directory and I want to read all the text files in it using C++ and having windows OS also using console application
I don't know the files' names or their number
thanks in advance
Take a look at Boost.Filesystem, especially the basic_directory_iterator.
If you want the C++ and portable way, follow the solution by #Space_C0wb0y and use boost.Filesystem, otherwise, if you want to get your hands dirty with the Windows APIs, you can use the FindFirstFile/FindNextFile/FindClose functions.
You can find here an example related to them.

Is there some common way to write and read config files?

I need my program to create and edit a config file, which would contain information about set of objects, and than read it at every execution. Is there some sort of guideline for config style that i can use?
I'm using C++ on windows.
I recommend checking out boost::property_tree.
The Property Tree library provides a data structure that stores an arbitrarily deeply nested tree of values, indexed at each level by some key. Each node of the tree stores its own value, plus an ordered list of its subnodes and their keys. The tree allows easy access to any of its nodes by means of a path, which is a concatenation of multiple keys.
Additionally, it contains parsers and generators for XML, INI, and JSON, so you can save/load in the format of your choice.
It largely depends on the language, platform and the scope of your config files. There's for example the properties files in Java world for configuration, and others already mentioned here such as YAML.
XML is generally frowned upon for configuration, since it's very verbose. You still find it in many applications, Web frameworks, etc.
I think the best practice would be to choose the right configuration format for the job at hand. You can evaluate and try them for yourself, while considering these pointers:
What's the standard? (e.g. ini files in Windows, properties files in Java)
Is there native support in my language, or do I have to roll my own implementation?
Can my configuration format easily describe what I want to store as configuration?
I'm sure you could think of other considerations. If you update your question to clarify the scope, you'll get more useful answers.
YAML is a very popular solution for creating configuration files. It is used prominently by Ruby on Rails and Google AppEngine, for instance. YAML libraries are available for many if not most languages.
If you're working with Qt (based on your other questions),
look at the QSettings class. I've been using these to set a lot of persistent info, such as last visited directory, and which options were last used.
boost::program_options has some capacity to read ini files.
What is nice is that is allow to unify reading ini file and command line options. As Windows program goes, that may not be seen as such an interresting future, but for my unix app it was a killer feature.
However, boost::po does not allow editing or writing of ini files, hence you'll probably be better off with boost::property_tree.
The most common format is the INI File format. Most mdoern languages should have something built in to handle these, otherwise I'm sure you'd be able to find a third-party library.
Failing this, you could use XML, and if your language supports it, serializing to and deserializing from these XML files. If you don't want to/can't use XML, most languages will have a default format they use, such as a pure binary dump of the data in an object.
There is a free, cross-platform library for configuration file management, called libconfig. It supports very nice Yaml-based grammar, and supports user-defined grammar too. It also has many other computing language bindings. See it's homepage: http://www.hyperrealm.com/libconfig/ .
In the Java world, a properties file is pretty easy to use:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html
The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.
As the others have said, you would need to describe your environment to get the best recommendation.

How to encrypt and decrypt a file with Qt/C++?

I want to create a program, which can encrypt and decrypt a complete file with an individual password. Is there any way to manage this in Qt and/or C++ and how?
I've never used it myself, but I've heard great things about QCA. It's cross platfrom, uses a Qt-style API and Qt datatypes.
www.cryptopp.com is a very complete C++ library with implementations of most algorithms.
The actual program (select file, read, obtain key, encrypt etc) should be piece of cake.
Old, I know, but try Botan. It's actually used internally by Qt Creator 2.0. If you download the Qt Creator 2.0 sources you can find a copy of Botan 1.8.8 all set up for the Qt build system (qmake).
Neither Qt nor the C++ standard library have encryption built-in. You'll need another external library to handle encryption.
Qt doesn't provide functionality to encrypt/decrypt.
QCryptographicHash only generates hashes. It is not what you are looking for.

C++ Library to render ODF documents?

I am unable to find any open source libraries to render ODF documents using C++. I found ODKit suporting Java and AODL for .NET C#.
Does any one have any idea or provide me any pointers.
I found a Qt source to parse ODF. Qt already has built in ODF writer.
KOffice supports ODF and is written in C++. I suspect they may have solved whatever it is you are trying to solve. http://www.koffice.org
It may not be the most elegant solution but OpenOffice itself is capable of rendering and the OOoSDK can be used from C++ as seen here for writer and here for spreadsheet.
There is none. You're better AODL or any of the other libs available (python, perl, java, etc) and doing a binding to it
KOffice can be an idea, but if I just want to display an odt file in a nice Qt QWidget, but I don't want to depends on DBus and a lots of Kde feature.
The Idea is to take a look a Flake and KoText libs as Thomas Zanders says on this Forum.