feisty meow concerns codebase 2.140
ini_configurator.h
Go to the documentation of this file.
1#ifndef INI_CONFIGURATOR_CLASS
2#define INI_CONFIGURATOR_CLASS
3
4/*****************************************************************************\
5* *
6* Name : ini_configurator *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2000-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
18#include "configurator.h"
19#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
20 #include "ini_parser.h"
21 #include <basis/utf_conversion.h>
22#endif
23
24#include <basis/contracts.h>
26#include <filesystem/filename.h>
27
28namespace configuration {
29
31
33{
34public:
36
48
49 ini_configurator(const basis::astring &ini_filename,
53
57 virtual ~ini_configurator();
58
59 DEFINE_CLASS_NAME("ini_configurator");
60
61 void refresh();
63
64//hmmm: where are:
65// save_to_file()
66// is_modified()
67//?
68
69 basis::astring name() const;
71 void name(const basis::astring &name);
73
74 virtual bool get(const basis::astring &section, const basis::astring &entry,
75 basis::astring &found);
77
80 virtual void sections(structures::string_array &list);
82
83 virtual bool section_exists(const basis::astring &section);
85
87 virtual bool put(const basis::astring &section, const basis::astring &entry,
88 const basis::astring &to_store);
90
91 virtual bool delete_section(const basis::astring &section);
93
94 virtual bool delete_entry(const basis::astring &section, const basis::astring &entry);
96
97 virtual bool get_section(const basis::astring &section, structures::string_table &info);
99
101 virtual bool put_section(const basis::astring &section, const structures::string_table &info);
103
106 // dictates whether the stored entries will have spaces between '='
107 // and the key name and value. only applicable on linux.
108 bool add_spaces() const { return _add_spaces; }
109 void add_spaces(bool add_them) { _add_spaces = add_them; }
110
111private:
112 filesystem::filename *_ini_name;
113#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
114 ini_parser *_parser;
115#endif
116 file_location_default _where;
117 bool _add_spaces;
118
119/*
120#ifdef _MSC_VER
121 bool put_profile_string(const basis::astring &section, const basis::astring &entry,
122 const basis::astring &to_store);
124 void get_profile_string(const basis::astring &section, const basis::astring &entry,
125 const basis::astring &default_value, basis::flexichar *return_buffer,
126 int buffer_size);
128#else
129*/
130 void read_ini_file();
132 void write_ini_file();
134//#endif
135
136 // not to be called.
138 ini_configurator &operator =(const ini_configurator &);
139
140 static const basis::astring &ini_str_fake_default();
141};
142
143} //namespace.
144
145#endif
146
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Provides a base class for configuration repositories.
treatment_of_defaults behavior() const
observes the behavior chosen for the load() function.
Supports a configurator-based interface on text initialization files.
DEFINE_CLASS_NAME("ini_configurator")
virtual bool section_exists(const basis::astring &section)
returns true if the "section" was found in the file.
virtual bool delete_entry(const basis::astring &section, const basis::astring &entry)
removes the entry specified by the "section" and "entry" name.
file_location_default
chooses where the ini file is located if no path to it is provided.
@ OS_DIRECTORY
config files live in operating system directory.
@ APPLICATION_DIRECTORY
config files live with application.
@ ALL_USERS_DIRECTORY
config files live in the "all users" account.
virtual void sections(structures::string_array &list)
retrieves the section names into "list".
basis::astring name() const
observes the name of the file used for ini entries.
virtual bool get(const basis::astring &section, const basis::astring &entry, basis::astring &found)
implements the configurator retrieval function.
virtual bool delete_section(const basis::astring &section)
removes the entire "section" specified.
virtual bool put_section(const basis::astring &section, const structures::string_table &info)
writes a table called "info" into the "section" in the INI file.
virtual bool get_section(const basis::astring &section, structures::string_table &info)
reads the entire "section" into a table called "info".
virtual bool put(const basis::astring &section, const basis::astring &entry, const basis::astring &to_store)
implements the configurator storage function.
void refresh()
useful mainly on unix/linux, where the file is parsed and held in memory.
Parses strings in the fairly well-known INI file format.
Definition ini_parser.h:74
Provides operations commonly needed on file names.
Definition filename.h:64
An array of strings with some additional helpful methods.
Provides a symbol_table that holds strings as the content.
Support for unicode builds.