mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
Replace ConfigTag::create with a public constructor.
This commit is contained in:
parent
be3b34fcea
commit
33a987368e
@ -54,6 +54,13 @@ public:
|
||||
const std::string src_name;
|
||||
const int src_line;
|
||||
|
||||
/** Creates a new ConfigTag instance with the specified tag name, file, and line.
|
||||
* @param Tag The name of this config tag (e.g. "foo" for \<foo>).
|
||||
* @param file The file this config tag was read from.
|
||||
* @param line The line of \p file that this config tag exists in.
|
||||
*/
|
||||
ConfigTag(const std::string& Tag, const std::string& file, int line);
|
||||
|
||||
/** Get the value of an option, using def if it does not exist */
|
||||
std::string getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator) const;
|
||||
/** Get the value of an option, using def if it does not exist */
|
||||
@ -104,12 +111,9 @@ public:
|
||||
|
||||
std::string getTagLocation() const;
|
||||
|
||||
/** Retrieves the underlying map of config entries. */
|
||||
inline const Items& GetItems() const { return items; }
|
||||
|
||||
/** Create a new ConfigTag, giving access to the private ConfigItems item list */
|
||||
static std::shared_ptr<ConfigTag> create(const std::string& Tag, const std::string& file, int line, Items*& Items);
|
||||
private:
|
||||
ConfigTag(const std::string& Tag, const std::string& file, int line);
|
||||
inline Items& GetItems() { return items; }
|
||||
};
|
||||
|
||||
/** Defines the server's length limits on various length-limited
|
||||
|
@ -179,7 +179,7 @@ struct Parser
|
||||
unget(ch);
|
||||
}
|
||||
|
||||
bool kv(ConfigTag::Items* items)
|
||||
bool kv()
|
||||
{
|
||||
std::string key;
|
||||
nextword(key);
|
||||
@ -266,10 +266,8 @@ struct Parser
|
||||
value.push_back(ch);
|
||||
}
|
||||
|
||||
if (items->find(key) != items->end())
|
||||
if (!tag->GetItems().insert({key, value}).second)
|
||||
throw CoreException("Duplicate key '" + key + "' found");
|
||||
|
||||
(*items)[key] = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -288,10 +286,8 @@ struct Parser
|
||||
if (name.empty())
|
||||
throw CoreException("Empty tag name");
|
||||
|
||||
ConfigTag::Items* items;
|
||||
tag = ConfigTag::create(name, current.name, current.line, items);
|
||||
|
||||
while (kv(items))
|
||||
tag = std::make_shared<ConfigTag>(name, current.name, current.line);
|
||||
while (kv())
|
||||
{
|
||||
// Do nothing here (silences a GCC warning).
|
||||
}
|
||||
@ -308,12 +304,12 @@ struct Parser
|
||||
}
|
||||
else if (stdalgo::string::equalsci(name, "files"))
|
||||
{
|
||||
for (const auto& [key, value] : *items)
|
||||
for (const auto& [key, value] : tag->GetItems())
|
||||
stack.DoReadFile(key, value, flags, false);
|
||||
}
|
||||
else if (stdalgo::string::equalsci(name, "execfiles"))
|
||||
{
|
||||
for (const auto& [key, value] : *items)
|
||||
for (const auto& [key, value] : tag->GetItems())
|
||||
stack.DoReadFile(key, value, flags, true);
|
||||
}
|
||||
else if (stdalgo::string::equalsci(name, "define"))
|
||||
@ -687,13 +683,6 @@ std::string ConfigTag::getTagLocation() const
|
||||
return src_name + ":" + ConvToStr(src_line);
|
||||
}
|
||||
|
||||
std::shared_ptr<ConfigTag> ConfigTag::create(const std::string& Tag, const std::string& file, int line, Items*& Items)
|
||||
{
|
||||
std::shared_ptr<ConfigTag> rv(new ConfigTag(Tag, file, line));
|
||||
Items = &rv->items;
|
||||
return rv;
|
||||
}
|
||||
|
||||
ConfigTag::ConfigTag(const std::string& Tag, const std::string& file, int line)
|
||||
: tag(Tag), src_name(file), src_line(line)
|
||||
{
|
||||
|
@ -60,14 +60,8 @@ ServerConfig::ServerPaths::ServerPaths(std::shared_ptr<ConfigTag> tag)
|
||||
{
|
||||
}
|
||||
|
||||
static std::shared_ptr<ConfigTag> CreateEmptyTag()
|
||||
{
|
||||
ConfigTag::Items* items;
|
||||
return ConfigTag::create("empty", "<auto>", 0, items);
|
||||
}
|
||||
|
||||
ServerConfig::ServerConfig()
|
||||
: EmptyTag(CreateEmptyTag())
|
||||
: EmptyTag(std::make_shared<ConfigTag>("empty", "<auto>", 0))
|
||||
, Limits(EmptyTag)
|
||||
, Paths(EmptyTag)
|
||||
, CaseMapping("ascii")
|
||||
@ -181,9 +175,8 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
|
||||
if (blk_count == 0)
|
||||
{
|
||||
// No connect blocks found; make a trivial default block
|
||||
ConfigTag::Items* items;
|
||||
auto tag = ConfigTag::create("connect", "<auto>", 0, items);
|
||||
(*items)["allow"] = "*";
|
||||
auto tag = std::make_shared<ConfigTag>("connect", "<auto>", 0);
|
||||
tag->GetItems()["allow"] = "*";
|
||||
config_data.insert(std::make_pair("connect", tag));
|
||||
blk_count = 1;
|
||||
}
|
||||
|
@ -70,8 +70,7 @@ class OperQuery : public SQL::Query
|
||||
res.GetCols(cols);
|
||||
|
||||
// Create the oper tag as if we were the conf file.
|
||||
ConfigTag::Items* items;
|
||||
auto tag = ConfigTag::create("oper", MODNAME, 0, items);
|
||||
auto tag = std::make_shared<ConfigTag>("oper", MODNAME, 0);
|
||||
|
||||
/** Iterate through each column in the SQLOpers table. An infinite number of fields can be specified.
|
||||
* Column 'x' with cell value 'y' will be the same as x=y in an OPER block in opers.conf.
|
||||
@ -79,7 +78,7 @@ class OperQuery : public SQL::Query
|
||||
for (unsigned int i=0; i < cols.size(); ++i)
|
||||
{
|
||||
if (!row[i].IsNull())
|
||||
(*items)[cols[i]] = row[i];
|
||||
tag->GetItems()[cols[i]] = row[i];
|
||||
}
|
||||
const std::string name = tag->getString("name");
|
||||
|
||||
|
@ -1239,9 +1239,7 @@ ConnectClass::ConnectClass(std::shared_ptr<ConfigTag> tag, char t, const std::st
|
||||
// Connect classes can inherit from each other but this is problematic for modules which can't use
|
||||
// ConnectClass::Update so we build a hybrid tag containing all of the values set on this class as
|
||||
// well as the parent class.
|
||||
ConfigTag::Items* items;
|
||||
config = ConfigTag::create(tag->tag, tag->src_name, tag->src_line, items);
|
||||
|
||||
config = std::make_shared<ConfigTag>(tag->tag, tag->src_name, tag->src_line);
|
||||
for (const auto& [key, value] : parent->config->GetItems())
|
||||
{
|
||||
// The class name and parent name are not inherited
|
||||
@ -1250,13 +1248,13 @@ ConnectClass::ConnectClass(std::shared_ptr<ConfigTag> tag, char t, const std::st
|
||||
|
||||
// Store the item in the config tag. If this item also
|
||||
// exists in the child it will be overwritten.
|
||||
(*items)[key] = value;
|
||||
config->GetItems()[key] = value;
|
||||
}
|
||||
|
||||
for (const auto& [key, value] : tag->GetItems())
|
||||
{
|
||||
// This will overwrite the parent value if present.
|
||||
(*items)[key] = value;
|
||||
config->GetItems()[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user