Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
settings_parsers.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/io/parsers.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/io/parsing/settings_parsers.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/io/parsing/settings_parsers.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22
28
29#pragma once
30
31
32
34
39
40
41
42
43namespace bertini {
44 namespace parsing {
45
46 namespace classic {
47
58
59 template<typename ConfigT>
60 ConfigT FillConfigStruct(std::string const& config_str)
61 {
62 std::string::const_iterator iter = config_str.begin();
63 std::string::const_iterator end = config_str.end();
64 ConfigT settings;
66 auto parse_success = phrase_parse(iter, end, parser,boost::spirit::ascii::space, settings);
67 if (!parse_success || iter!=end)
68 {
69 std::string remaining(iter, end);
70 if (remaining.size() > 60)
71 remaining = remaining.substr(0, 60) + "...";
72 if (remaining.empty())
73 remaining = "<end of input>";
74 throw std::runtime_error(
75 std::string("[config] parser did not consume entire input; "
76 "unparsed remainder: \"") + remaining + "\"");
77 }
78
79 return settings;
80 }
81
82
83
84
93 template<typename ...Ts>
95 {
107 static
108 std::tuple<Ts...> Parse(std::string const& config)
109 {
110 return std::make_tuple<Ts...>(FillConfigStruct<Ts>(config)...);
111 }
112
113 };
114
115
122 template<typename ConfigT>
123 struct ConfigParser <ConfigT>
124 {
125
133 static
134 ConfigT Parse(std::string const& config)
135 {
136 return FillConfigStruct<ConfigT>(config);
137 }
138 };
139
140
147 template<typename ...Ts>
148 struct ConfigParser<detail::TypeList<Ts...>>
149 {
151 static
152 auto Parse(std::string const& config)
153 {
154 return ConfigParser<Ts...>::Parse(config);
155 }
156 };
157 } // re: namespace classic
158
159 }// re: namespace parsing
160}// re: namespace bertini
Provides the parsing rules for algorithm-related settings in bertini2.
Provides the parsing rules for endgames-related settings in bertini2.
Parser specialisation for RandomConfig — handles randomseed: <uint>;.
Provides the parsing rules for tracking-related settings in bertini2.
Definition configured.hpp:34
Definition classic_utilities.hpp:41
ConfigT FillConfigStruct(std::string const &config_str)
Helper function to fill a single configuration struct by parsing a config input file.
Definition settings_parsers.hpp:60
Definition classic_utilities.hpp:40
Definition configIni_parse.hpp:78
Definition algorithm_builder.hpp:36
static ConfigT Parse(std::string const &config)
Fill a single configuration struct by parsing a config input file.
Definition settings_parsers.hpp:134
static auto Parse(std::string const &config)
Parse all the config types in the list from a classic-format config string.
Definition settings_parsers.hpp:152
Base variadic parser for parsing many config structs at once.
Definition settings_parsers.hpp:95
static std::tuple< Ts... > Parse(std::string const &config)
The primary idea for filling a tuple using variadic templates comes from: http://stackoverflow....
Definition settings_parsers.hpp:108
Qi Parser object for parsing config settings This ensures we can provide backwards compatibility with...
Definition base.hpp:52
Contains the detail/typelist helper type, for templated getting/setting/storage of config structs.