feisty meow concerns codebase 2.140
configurator.h
Go to the documentation of this file.
1#ifndef CONFIGURATOR_CLASS
2#define CONFIGURATOR_CLASS
3
4/*****************************************************************************\
5* *
6* Name : 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 <basis/astring.h>
19#include <basis/contracts.h>
20#include <structures/set.h>
23
24namespace configuration {
25
27
33class configurator : public virtual basis::root_object
34{
35public:
38
43 virtual ~configurator();
44
46 treatment_of_defaults behavior() const { return _behavior; }
48 void behavior(treatment_of_defaults new_behavior) {
49 _behavior = (new_behavior == RETURN_ONLY)? RETURN_ONLY : AUTO_STORE;
50 }
51
52 virtual bool get(const basis::astring &section, const basis::astring &entry,
53 basis::astring &found) = 0;
55
59 virtual bool put(const basis::astring &section, const basis::astring &entry,
60 const basis::astring &to_store) = 0;
62
66 bool store(const basis::astring &section, const basis::astring &entry,
67 const basis::astring &to_store);
69
71
73 basis::astring load(const basis::astring &section, const basis::astring &entry,
74 const basis::astring &default_value);
75
77 bool store(const basis::astring &section, const basis::astring &entry, int value);
79 int load(const basis::astring &section, const basis::astring &entry, int def_value);
80
81 // the various methods below that operate on sections and entries might not
82 // be provided by all configurators. that is why there are empty default
83 // (or simplistic and slow) implementations provided below.
84
85 virtual void sections(structures::string_array &list);
87
90
93 virtual bool delete_entry(const basis::astring & formal(section),
94 const basis::astring & formal(entry)) { return false; }
96
97 virtual bool delete_section(const basis::astring & formal(section) )
98 { return false; }
100
101 virtual bool section_exists(const basis::astring &section);
103
106 virtual bool get_section(const basis::astring & formal(section),
107 structures::string_table & formal(found) ) { return false; }
109
113 virtual bool put_section(const basis::astring & formal(section),
114 const structures::string_table & formal(to_store) ) { return false; }
116
120private:
121 treatment_of_defaults _behavior;
122};
123
124} //namespace.
125
126#endif
127
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Provides a base class for configuration repositories.
bool store(const basis::astring &section, const basis::astring &entry, const basis::astring &to_store)
a synonym for put.
virtual bool put(const basis::astring &section, const basis::astring &entry, const basis::astring &to_store)=0
Places an item into the configuration store.
treatment_of_defaults behavior() const
observes the behavior chosen for the load() function.
void behavior(treatment_of_defaults new_behavior)
modifies the behavior of the load() function.
virtual bool get_section(const basis::astring &formal(section), structures::string_table &formal(found))
retrieves an entire "section", if supported by the derived object.
configurator(treatment_of_defaults behavior=RETURN_ONLY)
virtual bool delete_section(const basis::astring &formal(section))
whacks the entire "section" specified.
virtual bool delete_entry(const basis::astring &formal(section), const basis::astring &formal(entry))
eliminates the entry specified by the "section" and "entry" name.
virtual bool get(const basis::astring &section, const basis::astring &entry, basis::astring &found)=0
Retrieves an item from the configuration store.
void section_set(structures::string_set &list)
similar to above, but stores section names into a set.
virtual void sections(structures::string_array &list)
retrieves the section names into "list".
virtual bool section_exists(const basis::astring &section)
returns true if the "section" is found in the configurator.
basis::astring load(const basis::astring &section, const basis::astring &entry, const basis::astring &default_value)
a synonym for get that implements the auto-store behavior.
virtual bool put_section(const basis::astring &formal(section), const structures::string_table &formal(to_store))
stores an entire "section" from the table in "to_store", if supported.
An array of strings with some additional helpful methods.
A simple object that wraps a templated set of strings.
Definition set.h:168
Provides a symbol_table that holds strings as the content.
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
Definition definitions.h:48