ampsci
c++ program for high-precision atomic structure calculations of single-valence systems
Public Member Functions | Friends | List of all members
IO::InputBlock

Holds list of Options, and a list of other InputBlocks. Can be initialised with a list of options, with a string, or from a file (ifstream). Format for input is, e.g.,: More...

#include <InputBlock.hpp>

Public Member Functions

 InputBlock ()
 Default constructor: name will be blank.
 
 InputBlock (std::string_view name, std::initializer_list< Option > options={})
 Construct from literal list of 'Options' (see Option struct)
 
 InputBlock (std::string_view name, const std::string &string_input)
 Construct from a string with the correct Block{option=value;} format.
 
 InputBlock (std::string_view name, const std::istream &file)
 Construct from plain text file, in Block{option=value;} format.
 
void add (InputBlock block, bool merge=false)
 Add a new InputBlock (merge: will be merged with existing if names match)
 
void merge (InputBlock block)
 
void add (Option option)
 Adds a new option to end of list.
 
void add (const std::vector< Option > &options)
 
void add (const std::string &string, bool merge=false)
 Adds options/inputBlocks by parsing a string.
 
void merge (const std::string &string)
 
std::string_view name () const
 
const std::vector< Option > & options () const
 Return const reference to list of options.
 
const std::vector< InputBlock > & blocks () const
 Return const reference to list of blocks.
 
template<typename T >
get (std::string_view key, T default_value) const
 If 'key' exists in the options, returns value. Else, returns default_value. Note: If two keys with same name, will use the later.
 
template<typename T = std::string>
std::optional< T > get (std::string_view key) const
 Returns optional value. Contains value if key exists; empty otherwise. Note: If two keys with same name, will use the later.
 
bool has_option (std::string_view key) const
 Check is option is present (even if not set) in current block.
 
bool option_is_set (std::string_view key) const
 Check if option is present AND has been set.
 
template<typename T >
get (std::initializer_list< std::string > blocks, std::string_view key, T default_value) const
 Get value from set of nested blocks. .get({block1,block2},option)
 
template<typename T >
std::optional< T > get (std::initializer_list< std::string > blocks, std::string_view key) const
 As above, but without default value.
 
std::optional< InputBlockgetBlock (std::string_view name) const
 Returns optional InputBlock. Contains InputBlock if block of given name exists; empty otherwise.
 
std::optional< InputBlockgetBlock (std::initializer_list< std::string > blocks, std::string_view name) const
 
InputBlock get_block (std::string_view name) const
 If block is present, returns a copy of it. If not, returns empty block.
 
bool has_block (std::string_view name) const
 Checks if block 'name' is present in current block.
 
bool has_block (std::initializer_list< std::string > blocks, std::string_view name) const
 Checks if block 'name' is present in nesteded block.
 
std::optional< OptiongetOption (std::string_view key) const
 Get an 'Option' (kay, value) - rarely needed.
 
void print (std::ostream &os=std::cout, int indent_depth=0) const
 Prints options to screen in user-friendly form. Same form as input string. By default prints to cout, but can be given any ostream.
 
bool check (std::initializer_list< std::string > blocks, const std::vector< std::pair< std::string, std::string >> &list, bool print=false) const
 Check all the options and blocks in this; if any of them are not present in 'list', then there is likely a spelling error in the input => returns false, warns user, and prints all options to screen. list is a pair: {option, description}. Description allws you to explain what each option is - great for 'self-documenting' code If print=true - will print all options+descriptions even if all good. More...
 
bool check (const std::vector< std::pair< std::string, std::string >> &list, bool print=false) const
 Override for when condidering current block.
 

Friends

bool operator== (InputBlock block, std::string_view name)
 Comparison of blocks compares the 'name'.
 
bool operator== (std::string_view name, InputBlock block)
 
bool operator!= (InputBlock block, std::string_view name)
 
bool operator!= (std::string_view name, InputBlock block)
 

Detailed Description

Holds list of Options, and a list of other InputBlocks. Can be initialised with a list of options, with a string, or from a file (ifstream). Format for input is, e.g.,:

BlockName1{ option1=value1; option2=value2; InnerBlock{ option1=v3; } }

Note: comparison for block/option names is case insensitive!

Member Function Documentation

◆ check()

bool IO::InputBlock::check ( std::initializer_list< std::string >  blocks,
const std::vector< std::pair< std::string, std::string >> &  list,
bool  print = false 
) const
inline

Check all the options and blocks in this; if any of them are not present in 'list', then there is likely a spelling error in the input => returns false, warns user, and prints all options to screen. list is a pair: {option, description}. Description allws you to explain what each option is - great for 'self-documenting' code If print=true - will print all options+descriptions even if all good.

Check one of the sub-blocks.


The documentation for this class was generated from the following file: