lib45d
45Drives C++ Library Development Documentation
ConfigSubsectionGuard.hpp
1 // -*- C++ -*-
2 /*
3  * Copyright (C) 2021 Joshua Boudreau <jboudreau@45drives.com>
4  *
5  * This file is part of lib45d.
6  *
7  * lib45d is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * lib45d is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with lib45d. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <45d/config/ConfigParser.hpp>
24 
25 namespace ffd {
50  public:
57  ConfigSubsectionGuard(ConfigParser &config, const std::string &section) : config_(config) {
58  if (config_.guarded_)
60  "Tried to guard config when ConfigSubsectionGuard already in scope"));
61  config_.guarded_ = true;
62  config_.set_subsection(section);
63  }
70  config_.guarded_ = false;
71  }
72  private:
74  };
75 } // namespace ffd
ffd::ConfigSubsectionGuard
Use this to switch to a certain config subsection to get a group of values.
Definition: ConfigSubsectionGuard.hpp:49
ffd
45Drives namespace
Definition: Bytes.hpp:27
ffd::ConfigSubsectionGuard::config_
ConfigParser & config_
Reference to ConfigParser or inhereting class.
Definition: ConfigSubsectionGuard.hpp:73
ffd::ConfigParser::guarded_
bool guarded_
true if a ConfigSubsectionGuard is in scope Set in ConfigSubsectionGuard::ConfigSubsectionGuard() Cle...
Definition: ConfigParser.hpp:437
ffd::ConfigGuardException
Throw this exception when a ConfigGuard is constructed or get_from() is called when the config is alr...
Definition: Exceptions.hpp:58
ffd::ConfigParser::set_subsection
void set_subsection(const std::string &section)
Update config_map_ptr_ to the subconfig map for section.
Definition: ConfigParser.hpp:479
ffd::ConfigSubsectionGuard::~ConfigSubsectionGuard
~ConfigSubsectionGuard(void)
Destroy the Config Subsection Guard object.
Definition: ConfigSubsectionGuard.hpp:68
ffd::ConfigParser::reset_subsection
void reset_subsection(void) noexcept
Set config_map_ptr_ back to the address of config_map_.
Definition: ConfigParser.hpp:493
ffd::ConfigSubsectionGuard::ConfigSubsectionGuard
ConfigSubsectionGuard(ConfigParser &config, const std::string &section)
Construct a new Config Subsection Guard object.
Definition: ConfigSubsectionGuard.hpp:57
ffd::ConfigParser
Main configuration parser class to inherit from in your code.
Definition: ConfigParser.hpp:68