|
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 |
| void | mark_all_unread () const |
| bool | was_read (const std::string &name) 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) |
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*.
|
inline |
Mark every parameter as unread (used before a shooting iteration).
|
inline |
Return true if name has been marked as read.
| 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.