SoftwareSphere Home

The Settings library

Introduction

Almost all computer applications need a settings file and a settings editor. Why spend time to compose ad-hoc forms for settings ? Ok, dialog forms are nice to see, and they can be easily remembered by people that have used them some times, but when the number of variables is large, or you are not sure of what settings variables will be needed, the generic settings editor is better.

Instead of creating a specific editor each time we have made a generic and reusable settings editor. We have developed a programming library to load the settings definition, load the settings, edit and save them. Finally we have made another library to build a settings editor with graphical user interface.This component can be used as a universal setting editor.

Description

The settings are defined in a file that provides the following information:

The settings definition uses an XML format. The settings document instead uses a simpler format because there are no nested elements. The format is similar to the "ini" files, a file contains multiple sections and a section contains multiple parameters. The section names in a settings definition must be all different, and the parameter names must be unique inside a section.

Parameter types

Each setting parameter has a specific type. There are predefined types and enumerated types. The predefined types are the following:

There are some other predefined types that are similar to the string type but are treated differently, they are:

The enumerated types are lists of possible strings. The enumerated types are defined in the settings definition file.

Finally the programmer's can define additional parameter types by adding derived classes.

Validators

Often parameter types aren't enough to express the constraints on the acceptable values of a parameter. For example an integer parameter without any additional constraints can have any integer value representable by the computer.

For this reason there are validators, which are functions or classes that can check the value of a parameter.

The boolean type doesn't need a validator because it is entirely specified.

The enumerated types are validators themselves because they allow only values taken from a list.

The predefined types int, double, date, time, datetime, money can be considered numeric types and they can have some simple validators like Max, Min, Interval.

The string type can have some simple validators like the following:

All these validators are applied to the single parameter definitions.

Default values of parameters

Each parameter can have a default value. This fact is specified in the settings definition. If the parameter can have a default value, the default value is also specified in the settings definition.

Missing sections and parameters

A given settings document does not need to contain every possible section specified in its settings definition, and the sections do not need to contain every possible parameter specified in the section definitions.

When a settings document doesn't contain all the sections defined in its settings definition, the settings editor allows to add the missing sections. In the same way, when a section hasn't got all its possible parameters the settings editor allows to add the missing parameters.

Required sections and parameters

The settings definition can tell if a section or a parameter are strictly required in the settings document. When a section or parameter is marked as required the settings document must have them otherwise it is considered invalid.

The settings editor user interface

The library provides many user interfaces for the settings editor. The first solution is a tab window with a tab for each section and a table to show and edit the parameters of that section. The tables uses different controls for parameters editing:

This user interface doesn't show the descriptions of the parameters and the sections.

The second solution offered uses a tree control to display the section names and their lists of parameters and shows a panel with all the information about the selected section or parameter.

Both the available user interfaces are customizable by choosing colors, fonts and other properties.

Using the settings editor

The settings editor loads the settings file entirely in the memory structure. When the user changes a parameter the change is performed on the value in memory. When the user closes the settings editor the program asks if to save the changes and if confirmed it rewrites the settings file with the new values.

Characters allowed in names and values

Names of sections and parameters must be formed with alphanumeric characters without spaces.
Values of enumerated types also must be alphanumeric without spaces.
Values of parameters of type string can contain spaces but no newlines or carriage returns.

Differences relative to standard XML

This component is not made to load documents containing generic data, it uses a subset of the XML Schema types and has some restrictions.

Main classes

CSettingsDef Represents a complete settings definition
CSettSectionDef Represents a section definition
CSettParamDef Represents a parameter definition
CSettParamType Base class for parameter types
CSettingsDefLoader Loads a settings definition from its XML file
CSettings Represents a settings document
CSettSection Represents a concrete section of a settings document
CSettParam Represents a concrete parameter
CSettingsLoader Loads a settings document and validates it
CSettingsSaver Saves a settings document

Summary

The SoftwareSphere Settings Library provides the following advantages:

Demo

The demo program is a complete settings editor that loads the settings document and the settings definition. This demo loads only the settings definition file named settdef.txt placed in the same directory of the executable, and load the settings file settings.ini placed in the same directory. You can modify the settings definition with any text editor, add new sections or parameters, and then reopen the program to see how it works. You can download the demo program from here.

Additional functionalities

The following functionalities are under development and will be released soon:

More information

The SoftwareSphere Settings Library is available complete of its source code and documentation.

For more information write to mail@softwaresphere.com or leave a message with this form.