File: SettingsIORegistry.cpp

package info (click to toggle)
ausaxs 1.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 72,592 kB
  • sloc: cpp: 49,853; ansic: 6,901; python: 730; makefile: 18
file content (27 lines) | stat: -rw-r--r-- 994 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-License-Identifier: LGPL-3.0-or-later
// Author: Kristian Lytje

#include <settings/SettingsIORegistry.h>
#include <utility/Exceptions.h>
#include <utility/observer_ptr.h>

using namespace ausaxs;
using namespace ausaxs::settings::io;

std::vector<observer_ptr<SettingSection>>& SettingSection::get_sections() {
    static std::vector<observer_ptr<SettingSection>> sections;
    return sections;
}

SettingSection::SettingSection(std::string_view name, std::initializer_list<std::shared_ptr<detail::ISettingRef>> settings) : name(name), settings(settings) {
    auto& stored_settings = detail::ISettingRef::get_stored_settings();
    for (auto& setting : settings) {
        for (auto& name : setting->names) {
            if (stored_settings.contains(name)) {
                throw std::runtime_error("Settings::add: Duplicate setting name: \"" + name + "\".");
            }
            stored_settings[name] = std::move(setting);
        }
    }
    get_sections().push_back(this);
}