|
CLASSpp Manual
Cosmology reference and developer manual
|
#include <parser.h>
Public Member Functions | |
| void | set (const std::string &name, const std::string &value) |
| FileContent & | operator+= (const FileContent &other) |
| int | size () const |
| const std::string & | get_filename () const |
| template<class T > | |
| std::optional< T > | get (const std::string &name) const |
| template<class T > | |
| T | get_or (const std::string &name, T fallback) const |
| std::string | get_or (const std::string &name, const char *fallback) const |
| bool | get_yes (const std::string &name, bool fallback=false) const |
| std::optional< bool > | get_yes_no (const std::string &name) const |
| template<class E > | |
| void | read_choice (const std::string &name, E &choice, std::initializer_list< std::pair< const char *, E > > spellings) const |
| void | mark_all_unread () const |
| bool | was_read (const std::string &name) const |
| bool | legacy_ncdm_transmuted () const |
| bool | single_instance_translated () const |
| std::vector< std::string > | instances_with (const std::string &field, const std::string &value) const |
| std::vector< std::string > | unread_parameters () const |
| void | for_each (const std::function< void(const std::string &name, const std::string &value, bool read)> &fn) const |
Static Public Member Functions | |
| static FileContent | from_file (const std::string &filename) |
| static bool | parse_line (const std::string &line, std::string &name, std::string &value) |
| static std::vector< std::string > | split_csv (const std::string &s) |
| static bool | is_instance_name (const std::string &name) |
Holds the parsed contents of one or more .ini/.pre files.
Internally uses std::map for O(log N) parameter lookup and a std::vector to preserve insertion order. A std::set tracks which parameters have been consumed so that callers can warn about unused entries.
|
static |
Load parameters from an .ini/.pre file. Throws std::invalid_argument on I/O errors or duplicate keys within the same file.
| void FileContent::set | ( | const std::string & | name, |
| const std::string & | value | ||
| ) |
Insert or overwrite a single parameter. Marks the key as unread.
| FileContent & FileContent::operator+= | ( | const FileContent & | other | ) |
Merge another FileContent into this one. Throws std::invalid_argument if a key already present in *this also appears in other.
|
inline |
Number of stored parameters.
|
inline |
Source filename (or "file1 or file2" after a merge).
| std::optional< T > FileContent::get | ( | const std::string & | name | ) | const |
Typed accessor: the value if name is present (marking it read), or std::nullopt if absent. Throws on a present-but-unparseable value. Supported T: int, double, std::string, std::vector<{int,double,std::string}>.
|
inline |
Read-with-default: get<T>(name) if present, else fallback.
| std::string FileContent::get_or | ( | const std::string & | name, |
| const char * | fallback | ||
| ) | const |
Overload so a string-literal fallback does not deduce T = const char*.
| bool FileContent::get_yes | ( | const std::string & | name, |
| bool | fallback = false |
||
| ) | const |
A yes/no flag as CLASS has always read it: fallback if name is absent, otherwise whether its value contains 'y' or 'Y'.
| std::optional< bool > FileContent::get_yes_no | ( | const std::string & | name | ) | const |
A strict yes/no flag: a value containing 'y' or 'Y' is yes, else one containing 'n' or 'N' is no, else an error. std::nullopt if name is absent.
|
inline |
Set choice from the value of name, one of a fixed set of spellings (several may map to the same choice). Left unchanged if name is absent; an error naming the spellings if the value is none of them.
|
inline |
Mark every parameter as unread (used before a shooting iteration).
|
inline |
Return true if name has been marked as read.
|
inline |
Legacy-NCDM transmutation state.
TransmuteLegacyStandardNcdmToDot writes ncdm__N.* keys, and its own collision guard rejects exactly those keys, so it must run at most once per FileContent – while every shooting target (100*theta_s, Omega_dcdmdr, ...) reparses the same FileContent. This flag is deliberately NOT a parameter: the parameter map accepts arbitrary user-supplied names, so a sentinel key there could be set from an input file and would silently suppress the transmutation and its collision guard. It also survives mark_all_unread(), which only clears read state.
|
inline |
Single-instance dot-syntax translation state, for the same reason as the NCDM flag above. TranslateSingleInstanceDotSyntax copies e.g. "f.w0" into "w0_fld" on the first pass; from then on the legacy key is the live copy. A reparse of a copy (pk_eq overriding w0_fld, a shooting step) must neither re-copy the dot value over the override nor read the override as the user setting both spellings. Not a parameter, and it survives mark_all_unread().
| std::vector< std::string > FileContent::instances_with | ( | const std::string & | field, |
| const std::string & | value | ||
| ) | const |
Return every instance name N such that the entry "N.<field>" has the given value. The dot is a literal separator; N must match the instance regex [A-Za-z_][A-Za-z0-9_]*. Results are returned in insertion order. Does NOT mark anything as read.
| std::vector< std::string > FileContent::unread_parameters | ( | ) | const |
Return the names of all parameters that have not yet been read.
| void FileContent::for_each | ( | const std::function< void(const std::string &name, const std::string &value, bool read)> & | fn | ) | const |
Invoke fn for every parameter in insertion order. Arguments: parameter name, value string, whether it was read. Declared in the second public section so the Cython wrapper generator (which stops at the first private:) does not attempt to parse it.
|
static |
Parse a single .ini line into name/value. Returns true when the line contains a valid key=value pair. Public for the legacy wrapper.
|
static |
Split a comma-separated value string into trimmed substrings.
|
static |
True if name is a legal species instance name: [A-Za-z_][A-Za-z0-9_]*.