ClickHouse/dbms/src/Common/Macros.h

52 lines
1.1 KiB
C++
Raw Normal View History

2014-08-11 15:59:01 +00:00
#pragma once
#include <Core/Types.h>
#include <Core/Names.h>
2018-09-28 19:13:16 +00:00
2014-08-11 15:59:01 +00:00
#include <map>
2018-03-13 23:44:23 +00:00
2018-03-13 23:44:23 +00:00
namespace Poco
{
namespace Util
{
class AbstractConfiguration;
}
}
2014-08-11 15:59:01 +00:00
2014-08-11 15:59:01 +00:00
namespace DB
{
/** Apply substitutions from the macros in config to the string.
2014-08-11 15:59:01 +00:00
*/
class Macros
{
public:
Macros();
Macros(const Poco::Util::AbstractConfiguration & config, const String & key);
2014-08-11 15:59:01 +00:00
2017-05-07 20:25:26 +00:00
/** Replace the substring of the form {macro_name} with the value for macro_name, obtained from the config file.
2018-10-01 18:45:39 +00:00
* If {database} and {table} macros aren`t defined explicitly, expand them as database_name and table_name respectively.
2017-05-07 20:25:26 +00:00
* level - the level of recursion.
*/
2018-09-27 10:01:10 +00:00
String expand(const String & s, size_t level = 0, const String & database_name = "", const String & table_name = "") const;
2018-05-07 02:01:11 +00:00
2018-10-01 09:01:50 +00:00
String expand(const String & s, const String & database_name, const String & table_name) const;
2018-04-20 16:09:43 +00:00
/** Apply expand for the list.
*/
Names expand(const Names & source_names, size_t level = 0) const;
2014-08-11 15:59:01 +00:00
using MacroMap = std::map<String, String>;
const MacroMap getMacroMap() const { return macros; }
2014-08-11 15:59:01 +00:00
private:
MacroMap macros;
2014-08-11 15:59:01 +00:00
};
2014-08-11 15:59:01 +00:00
}