1 #ifndef CASM_InputParser
2 #define CASM_InputParser
4 #include <boost/filesystem.hpp>
119 std::string
name()
const;
129 return path.empty() ? val :
path / val;
134 typedef std::multimap<fs::path, std::shared_ptr<KwargsParser>>
map_type;
137 map_type::const_iterator
begin()
const;
140 map_type::const_iterator
end()
const;
146 std::map<fs::path, std::set<std::string>>
all_warnings()
const;
149 std::map<fs::path, std::set<std::string>>
all_errors()
const;
160 void insert(fs::path
path,
const std::shared_ptr<KwargsParser> &subparser);
163 void insert_error(fs::path option, std::string message);
229 template <
typename T>
237 template <
typename... Args>
242 template <
typename... Args>
247 template <
typename CustomParse>
252 template <
typename CustomParse>
264 template <
typename RequiredType,
typename... Args>
265 std::unique_ptr<RequiredType>
require(fs::path option, Args &&... args);
275 template <
typename RequiredType,
typename... Args>
276 void require(RequiredType &
value, fs::path option, Args &&... args);
287 template <
typename RequiredType,
typename... Args>
288 std::unique_ptr<RequiredType>
optional(fs::path option, Args &&... args);
300 template <
typename RequiredType,
typename... Args>
301 void optional(RequiredType &
value, fs::path option, Args &&... args);
313 template <
typename RequiredType,
typename... Args>
314 RequiredType
optional_else(fs::path option,
const RequiredType &_default,
327 template <
typename RequiredType,
typename... Args>
329 const RequiredType &_default, Args &&... args);
344 template <
typename RequiredType,
typename... Args>
345 std::shared_ptr<InputParser<RequiredType>>
subparse(fs::path option,
351 template <
typename RequiredType,
typename... Args>
352 std::shared_ptr<InputParser<RequiredType>>
subparse_if(fs::path option,
357 template <
typename RequiredType,
typename... Args>
359 fs::path option,
const RequiredType &_default, Args &&... args);
365 template <
typename RequiredType,
typename... Args>
366 std::shared_ptr<InputParser<RequiredType>>
parse_as(Args &&... args);
398 void parse(InputParser<std::nullptr_t> &parser);
400 template <
typename T>
401 void parse(InputParser<T> &parser);
407 std::string header =
"Warnings");
411 std::string header =
"Errors");
415 jsonParser
make_report(KwargsParser
const &parser);
419 template <
typename ErrorType>
int parse_verbosity(KwargsParser &parser, int default_verbosity=10)
void print_errors(KwargsParser const &parser, Log &log, std::string header="Errors")
Formatted print error messages, including all subparsers.
void print_warnings(KwargsParser const &parser, Log &log, std::string header="Warnings")
Formatted print warning messages, including all subparsers.
void report_and_throw_if_invalid(KwargsParser const &parser, Log &log, ErrorType error)
jsonParser make_report(KwargsParser const &parser)
Return parser.input with error and warning messages added in place.
void parse(InputParser< ConfigEnumOptions > &parser, std::string method_name, PrimClex const &primclex, DataFormatterDictionary< Configuration > const &dict)
std::string name() const
Name of this->self, equivalent to this->path.filename().string()
bool valid() const
Return true if this and and all subparsers are valid.
KwargsParser(jsonParser const &_input, fs::path _path, bool _required)
std::map< fs::path, std::set< std::string > > all_errors() const
Return error messages from this and all subparsers.
Validator & insert(const Validator &other)
map_type::value_type PairType
map_type::const_iterator begin() const
Begin iterator over subparsers.
bool required
If this->input.at(this->path) is required to exist.
void insert_warning(fs::path option, std::string message)
Insert a subparser at location option with a single warning message
fs::path relpath(const fs::path &val) const
Return this->path / val, ensuring the result is a relative path.
jsonParser const & input
Reference to the top of the JSON document being parsed.
std::multimap< fs::path, std::shared_ptr< KwargsParser > > map_type
std::map< fs::path, std::set< std::string > > all_warnings() const
Return warning messages from this and all subparsers.
const jsonParser & parent() const
void insert_error(fs::path option, std::string message)
Insert a subparser at location option with a single error message
map_type::const_iterator end() const
End iterator over subparsers.
fs::path parent_path() const
bool warn_unnecessary(const std::set< std::string > &expected)
Insert a warning if any unexpected JSON attributes are found in self.
Data structure to hold error and warning messages.
Validator & insert(const Validator &other)