ConfigOption.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 <iosfwd>
13 #include <vector>
14 
15 class StoreEntry;
16 class ConfigParser;
17 
18 namespace Configuration {
19 
29 template <class T>
30 class Component
31 {
32 public:
33  /* the code adding "TYPE: T" to cf.data.pre must specialize these */
34 
36  static T Parse(ConfigParser &);
37 
39  static void Print(std::ostream &, const T &);
40 
42  static void Free(T);
43 };
44 
45 } // namespace Configuration
46 
47 /*
48  * Deprecated squid.conf option wrappers used by cache_dir handling code. These
49  * classes are similar to Configuration::Component<T>, but they merge T with T
50  * parsing API, making them ill-suited for handling SquidConfig data members
51  * with built-in C++ types and, more importantly, forcing SquidConfig users to
52  * know about parsing/dumping/freeing capabilities of each SquidConfig
53  * component. They also do not hide T details from the generic squid.conf
54  * parsing code -- one has to provide a type-specific parse_T() for each T.
55  */
56 
58 {
59 
60 public:
61  virtual ~ConfigOption() {}
62 
63  virtual bool parse(char const *option, const char *value, int reconfiguring) = 0;
64  virtual void dump(StoreEntry * e) const = 0;
65 };
66 
68 {
69 
70 public:
71  virtual ~ConfigOptionVector();
72  virtual bool parse(char const *option, const char *value, int reconfiguring);
73  virtual void dump(StoreEntry * e) const;
74  std::vector<ConfigOption *>options;
75 };
76 
77 template <class C>
79 {
80 
81 public:
82  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) {}
83 
84  bool parse(char const *option, const char *value, int isaReconf) {
85  if (parser)
86  return (object.*parser)(option, value, isaReconf);
87 
88  return false;
89  }
90 
91  void dump(StoreEntry * e) const {
92  if (dumper)
93  (object.*dumper)(e);
94  }
95 
96 private:
98  bool (C::*parser)(char const *option, const char *value, int reconfiguring) ;
99  void (C::*dumper)(StoreEntry * e) const;
100 };
101 
102 #endif /* SQUID_CONFIGOPTION_H */
103 
bool parse(char const *option, const char *value, int isaReconf)
Definition: ConfigOption.h:84
virtual bool parse(char const *option, const char *value, int reconfiguring)=0
static T Parse(ConfigParser &)
creates a new T instance using the given parser; never returns nil
virtual ~ConfigOption()
Definition: ConfigOption.h:61
virtual void dump(StoreEntry *e) const =0
virtual void dump(StoreEntry *e) const
Definition: ConfigOption.cc:38
virtual ~ConfigOptionVector()
Definition: ConfigOption.cc:14
virtual bool parse(char const *option, const char *value, int reconfiguring)
Definition: ConfigOption.cc:23
ConfigOptionAdapter(C &theObject, bool(C::*parseFP)(char const *option, const char *value, int reconfiguring), void(C::*dumpFP)(StoreEntry *e) const)
Definition: ConfigOption.h:82
static void Print(std::ostream &, const T &)
reports the current T instance configuration in squid.conf format
std::vector< ConfigOption * > options
Definition: ConfigOption.h:74
static void Free(T)
destroys Parse() result
int reconfiguring
static uint32 C
Definition: md4.c:43
void dump(StoreEntry *e) const
Definition: ConfigOption.h:91
void(C::* dumper)(StoreEntry *e) const
Definition: ConfigOption.h:99
bool(C::* parser)(char const *option, const char *value, int reconfiguring)
Definition: ConfigOption.h:98

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors