config/Data: pass new items by rvalue reference
This commit is contained in:
parent
9ff2606bb8
commit
57729683b6
@ -56,9 +56,9 @@ Append(std::forward_list<T> &list, T &&src)
|
|||||||
|
|
||||||
void
|
void
|
||||||
ConfigData::AddParam(ConfigOption option,
|
ConfigData::AddParam(ConfigOption option,
|
||||||
std::unique_ptr<ConfigParam> param) noexcept
|
ConfigParam &¶m) noexcept
|
||||||
{
|
{
|
||||||
Append(GetParamList(option), std::move(*param));
|
Append(GetParamList(option), std::move(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@ -144,9 +144,9 @@ ConfigData::GetBool(ConfigOption option, bool default_value) const
|
|||||||
|
|
||||||
ConfigBlock &
|
ConfigBlock &
|
||||||
ConfigData::AddBlock(ConfigBlockOption option,
|
ConfigData::AddBlock(ConfigBlockOption option,
|
||||||
std::unique_ptr<ConfigBlock> block) noexcept
|
ConfigBlock &&block) noexcept
|
||||||
{
|
{
|
||||||
return *Append(GetBlockList(option), std::move(*block));
|
return *Append(GetBlockList(option), std::move(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConfigBlock *
|
const ConfigBlock *
|
||||||
@ -172,8 +172,8 @@ ConfigData::MakeBlock(ConfigBlockOption option,
|
|||||||
{
|
{
|
||||||
auto *block = const_cast<ConfigBlock *>(FindBlock(option, key, value));
|
auto *block = const_cast<ConfigBlock *>(FindBlock(option, key, value));
|
||||||
if (block == nullptr) {
|
if (block == nullptr) {
|
||||||
auto new_block = std::make_unique<ConfigBlock>();
|
ConfigBlock new_block;
|
||||||
new_block->AddBlockParam(key, value);
|
new_block.AddBlockParam(key, value);
|
||||||
block = &AddBlock(option, std::move(new_block));
|
block = &AddBlock(option, std::move(new_block));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
struct ConfigParam;
|
struct ConfigParam;
|
||||||
struct ConfigBlock;
|
struct ConfigBlock;
|
||||||
@ -47,8 +46,7 @@ struct ConfigData {
|
|||||||
return params[size_t(option)];
|
return params[size_t(option)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddParam(ConfigOption option,
|
void AddParam(ConfigOption option, ConfigParam &¶m) noexcept;
|
||||||
std::unique_ptr<ConfigParam> param) noexcept;
|
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
const ConfigParam *GetParam(ConfigOption option) const noexcept {
|
const ConfigParam *GetParam(ConfigOption option) const noexcept {
|
||||||
@ -102,7 +100,7 @@ struct ConfigData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConfigBlock &AddBlock(ConfigBlockOption option,
|
ConfigBlock &AddBlock(ConfigBlockOption option,
|
||||||
std::unique_ptr<ConfigBlock> block) noexcept;
|
ConfigBlock &&block) noexcept;
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
const ConfigBlock *GetBlock(ConfigBlockOption option) const noexcept {
|
const ConfigBlock *GetBlock(ConfigBlockOption option) const noexcept {
|
||||||
|
@ -32,8 +32,6 @@
|
|||||||
#include "fs/io/BufferedReader.hxx"
|
#include "fs/io/BufferedReader.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static constexpr char CONF_COMMENT = '#';
|
static constexpr char CONF_COMMENT = '#';
|
||||||
@ -74,10 +72,10 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
|
|||||||
block.AddBlockParam(name, std::move(value), line);
|
block.AddBlockParam(name, std::move(value), line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<ConfigBlock>
|
static ConfigBlock
|
||||||
config_read_block(BufferedReader &reader)
|
config_read_block(BufferedReader &reader)
|
||||||
{
|
{
|
||||||
std::unique_ptr<ConfigBlock> block(new ConfigBlock(reader.GetLineNumber()));
|
ConfigBlock block(reader.GetLineNumber());
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
char *line = reader.ReadLine();
|
char *line = reader.ReadLine();
|
||||||
@ -101,7 +99,7 @@ config_read_block(BufferedReader &reader)
|
|||||||
|
|
||||||
/* parse name and value */
|
/* parse name and value */
|
||||||
|
|
||||||
config_read_name_value(*block, line,
|
config_read_name_value(block, line,
|
||||||
reader.GetLineNumber());
|
reader.GetLineNumber());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,8 +148,8 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
|
|||||||
|
|
||||||
/* now parse the block or the value */
|
/* now parse the block or the value */
|
||||||
|
|
||||||
config_data.AddParam(o, std::make_unique<ConfigParam>(ExpectValueAndEnd(tokenizer),
|
config_data.AddParam(o, ConfigParam(ExpectValueAndEnd(tokenizer),
|
||||||
reader.GetLineNumber()));
|
reader.GetLineNumber()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user