Loading...
Searching...
No Matches
input_format.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * InputFormat — one input format a run can be read from.
5 *
6 * Formats are registered by name with the input-format registry
7 * (input_format_registry.hpp). Core registers Q3's YAML and Quantum ESPRESSO
8 * namelist inputs, and a build-time add-on may register more. An entry point
9 * asks the format everything it needs to know, so no entry point and no
10 * factory has to name one:
11 *
12 * - the names `--format` accepts, and how a log line names an input;
13 * - whether a path is an input of this format, consulted in descending
14 * detection_priority() when no `--format` is given;
15 * - whether a directory holds one that a run given no input path should read;
16 * - the parser that reads it;
17 * - any files the format's own conventions expect beside the results once
18 * the run has finished.
19 */
20
21#include <filesystem>
22#include <memory>
23#include <string>
24#include <vector>
25
26#include "io/input/data.hpp"
28
29namespace q3 {
30
31namespace generated {
32struct Results;
33} // namespace generated
34
35/// One input format a run can be read from; see the file comment.
37 public:
38 virtual ~InputFormat() = default;
39
40 /**
41 * The names `--format` accepts. The first is canonical: parse_input()
42 * records it as InputData::source_format, and usage text prints it.
43 */
44 [[nodiscard]] virtual std::vector<std::string> names() const = 0;
45
46 /// How a log line names an input of this format, e.g. "a Quantum ESPRESSO input".
47 [[nodiscard]] virtual std::string display_name() const = 0;
48
49 /**
50 * Rank among the formats that recognise a path, highest first. A format
51 * that recognises paths by file name or directory contents ranks above
52 * one that goes by extension, and the fallback ranks lowest, so a path is
53 * claimed by the most specific rule that matches it.
54 */
55 [[nodiscard]] virtual int detection_priority() const = 0;
56
57 /// Whether `path` names an input of this format, judged without parsing it.
58 [[nodiscard]] virtual bool recognizes(const std::filesystem::path& path) const = 0;
59
60 /**
61 * Whether `directory` holds an input of this format that a run given no
62 * input path should read. False for a format whose inputs are always
63 * named explicitly.
64 */
65 [[nodiscard]] virtual bool
66 claims_working_directory(const std::filesystem::path& /*directory*/) const {
67 return false;
68 }
69
70 /// A parser for inputs of this format.
71 [[nodiscard]] virtual std::unique_ptr<InputParser> create_parser() const = 0;
72
73 /**
74 * Write the files this format's conventions expect beside the results of
75 * a finished run that was read from it. Writes nothing for a format with
76 * no such convention.
77 */
78 virtual void write_companion_outputs(const InputData& /*input*/,
79 const generated::Results& /*results*/) const {}
80};
81
82} // namespace q3
One input format a run can be read from; see the file comment.
virtual std::unique_ptr< InputParser > create_parser() const =0
A parser for inputs of this format.
virtual int detection_priority() const =0
virtual std::vector< std::string > names() const =0
virtual bool claims_working_directory(const std::filesystem::path &) const
virtual std::string display_name() const =0
How a log line names an input of this format, e.g. "a Quantum ESPRESSO input".
virtual void write_companion_outputs(const InputData &, const generated::Results &) const
virtual bool recognizes(const std::filesystem::path &path) const =0
Whether path names an input of this format, judged without parsing it.
virtual ~InputFormat()=default
Parsed input data — holds raw values read from input files.
Definition data.hpp:27