]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ConfigOption.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ConfigOption.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_CONFIGOPTION_H
10 #define SQUID_CONFIGOPTION_H
11
12 #include <vector>
13
14 class StoreEntry;
15
16 /* cache option parsers */
17
18 class ConfigOption
19 {
20
21 public:
22 virtual ~ConfigOption() {}
23
24 virtual bool parse(char const *option, const char *value, int reconfiguring) = 0;
25 virtual void dump(StoreEntry * e) const = 0;
26 };
27
28 class ConfigOptionVector : public ConfigOption
29 {
30
31 public:
32 virtual ~ConfigOptionVector();
33 virtual bool parse(char const *option, const char *value, int reconfiguring);
34 virtual void dump(StoreEntry * e) const;
35 std::vector<ConfigOption *>options;
36 };
37
38 template <class C>
39 class ConfigOptionAdapter : public ConfigOption
40 {
41
42 public:
43 ConfigOptionAdapter(C& theObject, bool (C::*parseFP)(char const *option, const char *value, int reconfiguring), void (C::*dumpFP)(StoreEntry * e) const) : object(theObject), parser(parseFP), dumper(dumpFP) {}
44
45 bool parse(char const *option, const char *value, int isaReconf) {
46 if (parser)
47 return (object.*parser)(option, value, isaReconf);
48
49 return false;
50 }
51
52 void dump(StoreEntry * e) const {
53 if (dumper)
54 (object.*dumper)(e);
55 }
56
57 private:
58 C &object;
59 bool (C::*parser)(char const *option, const char *value, int reconfiguring) ;
60 void (C::*dumper)(StoreEntry * e) const;
61 };
62
63 #endif /* SQUID_CONFIGOPTION_H */
64