File: rtini.h

package info (click to toggle)
robotour 3.1.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,596 kB
  • ctags: 2,972
  • sloc: cpp: 17,705; sh: 3,060; ansic: 2,778; makefile: 144
file content (120 lines) | stat: -rwxr-xr-x 4,066 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * rtini.h
 * 
 * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
 * and Martin Trautmann (martintrautmann@gmx.de) 
 * 
 * This file may be distributed and/or modified under the terms of the 
 * GNU General Public License version 2 as published by the Free Software 
 * Foundation. 
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */

/** \file
  * Contains support for the INI file format, a text-mode configuration
  * file format.
  * @see IniFile
  * @see IniSection
  */

#ifndef __LRT_INI__
#define __LRT_INI__

#include "rtmap.h"

namespace lrt {

/** An IniSection is a subsection of an INI file. It contains 
  * several key-value string mappings. Currently, it is just implemented
  * by a linear map of Strings. 
  * @see StringMap 
  */
class IniSection : public StringMap<String> {
public:
	/** Creates an empty IniSection. Ensures that it is not case sensitive. */
	IniSection() : StringMap<String>(false) {}

	/** Copies all data from the given IniSection. */
	IniSection(const IniSection& is) : StringMap<String>(is) {}

	virtual ~IniSection() {}
};

/** IniFile implements an interface to a configuration file in INI format.
  * (This format is a well known text-mode configuration file format from 
  * the Windows world.) While the format of INI files varies
  * with different Windows programs, for our purposes, its structure is
  * as follows:
  * -	Each INI file consists of any number of sections. 
  * -	Every section is addressed by its name (a String), and itself contains
  * 	any number of INI entries.
  * -	Every INI entry is just a key-value pair of <tt>String</tt>s.
  */
class IniFile {
public:
	typedef StringMap<IniSection>::Iterator Iterator;

	/** Creates an empty IniFile. It will not contain any sections nor entries. */
	IniFile();
	/** Creates an IniFile and fills it with sections and entries from an INI 
	  * file on your disk. 
	  * @param filename The INI file to read. */
	IniFile(const String& filename);

	/** Checks if a section with the given name is present in this IniFile. */
	bool hasSection(const String& name) const;
	
	/** Gets an IniSection by its name from this IniFile.
	  * If the section does not yet exist, an empty section will be created and returned. 
	  * @param name The section's name.
	  * @return A reference to the section through which its contents can be modified.
	  */ 
	IniSection& getSection(const String& name);

	/** Gets an IniSection by its name from this IniFile. 
	  * If the section does not yet exist, some nonsense value is returned; use hasSection()
	  * beforewards to check. */
	const IniSection& getSectionConst(const String& name) const;
	
	/** Adds an IniSection to this IniFile.
	  * The section's contents will be copied over to the IniFile.
	  * If a section with the same name was already present in this IniFile,
	  * its contents will be discarded.
	  */
	void addSection(const String& name, const IniSection& section);

	/** Removes the given section (by its name), if it is present.
	  * @return <tt>True</tt> if there was actually a section to remove, <tt>false</tt> otherwise.
	  */
	bool removeSection(const String& name);

	/** Returns an iterator to the begin of the IniFile. You can use it to 
	  * traverse all IniSections that are present in it. 
	  */
	Iterator begin();

	/** Returns an unmodifyable iterator to the begin of the IniFile. */
	Iterator begin() const;

	/** Reads an INI file from your disk and inserts its contents into this IniFile.
	  * @return <tt>True</tt> if reading succeeded.
	  */
	bool read(const String& filename);

	/** Writes the contents of this IniFile to your disk.
	  * @param filename The file to write to.
	  * @return <tt>True</tt> if writing succeeded.
	  */
	bool write(const String& filename);

private:
	StringMap<IniSection> data;
};

} // namespace

#endif