config_parser: Allow modifying Parser map
This makes it possible to mutate the map owned by the parser. This will
eventually be used for implementing write updates.
Change-Id: I89deb4073a0a3bd59528c6b70fc55b49bc6cd944
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/config_parser.cpp b/src/config_parser.cpp
index 867d611..cd9960d 100644
--- a/src/config_parser.cpp
+++ b/src/config_parser.cpp
@@ -147,7 +147,7 @@
struct Parse
{
std::reference_wrapper<const fs::path> filename;
- SectionMap sections;
+ SectionMap map;
KeyValuesMap* section;
std::vector<std::string> warnings;
size_t lineno;
@@ -179,10 +179,10 @@
}
}
auto s = line.substr(0, cpos);
- auto it = sections.find(s);
- if (it == sections.end())
+ auto it = map.find(s);
+ if (it == map.end())
{
- std::tie(it, std::ignore) = sections.emplace(
+ std::tie(it, std::ignore) = map.emplace(
Section(Section::unchecked(), s), KeyValuesMapList{});
}
section = &it->second.emplace_back();
@@ -270,8 +270,8 @@
fmt::format("{}: Read error: {}", filename.native(), e.what()));
}
+ this->map = std::move(parse.map);
this->filename = filename;
- this->sections = std::move(parse.sections);
this->warnings = std::move(parse.warnings);
}
diff --git a/src/config_parser.hpp b/src/config_parser.hpp
index 6b633e9..8ec693a 100644
--- a/src/config_parser.hpp
+++ b/src/config_parser.hpp
@@ -160,6 +160,8 @@
class Parser
{
public:
+ SectionMap map;
+
Parser() = default;
/** @brief Constructor
@@ -167,12 +169,6 @@
*/
Parser(const fs::path& filename);
- /** @brief Retrieve the map of all values in the file */
- inline const SectionMap& getMap() const noexcept
- {
- return sections;
- }
-
/** @brief Determine if there were warnings parsing the file
* @return The number of parsing issues in the file
*/
@@ -196,7 +192,6 @@
private:
fs::path filename;
- SectionMap sections;
std::vector<std::string> warnings;
};
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index ef0a6a6..6684713 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -85,7 +85,7 @@
config::Parser parser(config::pathForIntfConf(manager.getConfDir(),
*interfaceStrList.begin()));
- auto value = parser.getMap().getLastValueString("DHCP", prop);
+ auto value = parser.map.getLastValueString("DHCP", prop);
if (value == nullptr)
{
auto msg = fmt::format("Missing config section DHCP[{}]", prop);
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 99ec98a..a3b2519 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -111,7 +111,7 @@
MacAddressIntf::macAddress(getMACAddress(intfName));
}
EthernetInterfaceIntf::ntpServers(
- config.getMap().getValueStrings("Network", "NTP"));
+ config.map.getValueStrings("Network", "NTP"));
EthernetInterfaceIntf::linkUp(linkUp());
EthernetInterfaceIntf::mtu(mtu());
@@ -786,7 +786,7 @@
{
EthernetInterfaceIntf::nameservers(getNameServerFromResolvd());
EthernetInterfaceIntf::staticNameServers(
- config.getMap().getValueStrings("Network", "DNS"));
+ config.map.getValueStrings("Network", "DNS"));
}
ServerList EthernetInterface::getNameServerFromResolvd()
diff --git a/src/util.cpp b/src/util.cpp
index 724eae6..cad1ed8 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -366,7 +366,7 @@
bool getIPv6AcceptRA(const config::Parser& config)
{
- auto value = config.getMap().getLastValueString("Network", "IPv6AcceptRA");
+ auto value = config.map.getLastValueString("Network", "IPv6AcceptRA");
if (value == nullptr)
{
auto msg = fmt::format(
@@ -391,7 +391,7 @@
EthernetInterfaceIntf::DHCPConf getDHCPValue(const config::Parser& config)
{
- const auto value = config.getMap().getLastValueString("Network", "DHCP");
+ const auto value = config.map.getLastValueString("Network", "DHCP");
if (value == nullptr)
{
auto msg =