1#pragma once
2
3#include <Core/Types.h>
4#include <Core/Names.h>
5
6#include <map>
7
8
9
10namespace Poco
11{
12 namespace Util
13 {
14 class AbstractConfiguration;
15 }
16}
17
18
19namespace DB
20{
21
22/** Apply substitutions from the macros in config to the string.
23 */
24class Macros
25{
26public:
27 Macros();
28 Macros(const Poco::Util::AbstractConfiguration & config, const String & key);
29
30 /** Replace the substring of the form {macro_name} with the value for macro_name, obtained from the config file.
31 * If {database} and {table} macros aren`t defined explicitly, expand them as database_name and table_name respectively.
32 * level - the level of recursion.
33 */
34 String expand(const String & s, size_t level = 0, const String & database_name = "", const String & table_name = "") const;
35
36 String expand(const String & s, const String & database_name, const String & table_name) const;
37
38
39 /** Apply expand for the list.
40 */
41 Names expand(const Names & source_names, size_t level = 0) const;
42
43 using MacroMap = std::map<String, String>;
44 const MacroMap getMacroMap() const { return macros; }
45
46 String getValue(const String & key) const;
47
48private:
49 MacroMap macros;
50};
51
52
53}
54