Loading...
Searching...
No Matches
pseudopotential_format.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * PseudopotentialFormat — one file format pseudopotential datasets are read from.
5 *
6 * Formats are registered with the pseudopotential-format registry
7 * (pseudopotential_format_registry.hpp). Core registers UPF, and a build-time
8 * add-on may register more. PseudopotentialFactory::read() shows each
9 * registered format the file's first line and hands the file to the
10 * recognising format with the highest detection_priority(), so a dataset is
11 * read by what it contains rather than by what it is called.
12 */
13
14#include <memory>
15#include <string>
16#include <vector>
17
19
20namespace q3 {
21
22/// One file format pseudopotential datasets are read from; see the file comment.
24 public:
25 virtual ~PseudopotentialFormat() = default;
26
27 /// The names this format answers to; the first is canonical and appears in error text.
28 [[nodiscard]] virtual std::vector<std::string> names() const = 0;
29
30 /// Whether a file whose first line is `first_line` holds a dataset of this format.
31 [[nodiscard]] virtual bool recognizes(const std::string& first_line) const = 0;
32
33 /**
34 * Rank among the formats that recognise a file, highest first. A format
35 * recognised by a definite signature ranks above one that claims whatever
36 * the others do not, so the broad claim never hides a specific one.
37 */
38 [[nodiscard]] virtual int detection_priority() const = 0;
39
40 /**
41 * Read the dataset at `dataset_index` from `filename`.
42 *
43 * The index counts datasets within one file, for a format that can hold
44 * several; a format holding one dataset per file ignores it.
45 */
46 [[nodiscard]] virtual std::unique_ptr<Pseudopotential> read(const std::string& filename,
47 int dataset_index) const = 0;
48};
49
50} // namespace q3
One file format pseudopotential datasets are read from; see the file comment.
virtual std::unique_ptr< Pseudopotential > read(const std::string &filename, int dataset_index) const =0
virtual std::vector< std::string > names() const =0
The names this format answers to; the first is canonical and appears in error text.
virtual ~PseudopotentialFormat()=default
virtual int detection_priority() const =0
virtual bool recognizes(const std::string &first_line) const =0
Whether a file whose first line is first_line holds a dataset of this format.