ampsci
High-precision calculations for one- and two-valence atomic systems
Loading...
Searching...
No Matches
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.
 
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!

Constructor & Destructor Documentation

◆ InputBlock() [1/4]

IO::InputBlock::InputBlock ( )
inline

Default constructor: name will be blank.

◆ InputBlock() [2/4]

IO::InputBlock::InputBlock ( std::string_view  name,
std::initializer_list< Option options = {} 
)
inline

Construct from literal list of 'Options' (see Option struct)

◆ InputBlock() [3/4]

IO::InputBlock::InputBlock ( std::string_view  name,
const std::string &  string_input 
)
inline

Construct from a string with the correct Block{option=value;} format.

◆ InputBlock() [4/4]

IO::InputBlock::InputBlock ( std::string_view  name,
const std::istream &  file 
)
inline

Construct from plain text file, in Block{option=value;} format.

Member Function Documentation

◆ add() [1/3]

void IO::InputBlock::add ( InputBlock  block,
bool  merge = false 
)
inline

Add a new InputBlock (merge: will be merged with existing if names match)

◆ add() [2/3]

void IO::InputBlock::add ( Option  option)
inline

Adds a new option to end of list.

◆ add() [3/3]

void IO::InputBlock::add ( const std::string &  string,
bool  merge = false 
)
inline

Adds options/inputBlocks by parsing a string.

◆ options()

const std::vector< Option > & IO::InputBlock::options ( ) const
inline

Return const reference to list of options.

◆ blocks()

const std::vector< InputBlock > & IO::InputBlock::blocks ( ) const
inline

Return const reference to list of blocks.

◆ get() [1/4]

template<typename T >
T IO::InputBlock::get ( std::string_view  key,
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.

◆ get() [2/4]

template<typename T >
std::optional< T > IO::InputBlock::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.

◆ has_option()

bool IO::InputBlock::has_option ( std::string_view  key) const
inline

Check is option is present (even if not set) in current block.

◆ option_is_set()

bool IO::InputBlock::option_is_set ( std::string_view  key) const
inline

Check if option is present AND has been set.

◆ get() [3/4]

template<typename T >
T IO::InputBlock::get ( std::initializer_list< std::string >  blocks,
std::string_view  key,
default_value 
) const

Get value from set of nested blocks. .get({block1,block2},option)

◆ get() [4/4]

template<typename T >
std::optional< T > IO::InputBlock::get ( std::initializer_list< std::string >  blocks,
std::string_view  key 
) const

As above, but without default value.

◆ getBlock()

std::optional< InputBlock > IO::InputBlock::getBlock ( std::string_view  name) const
inline

Returns optional InputBlock. Contains InputBlock if block of given name exists; empty otherwise.

◆ get_block()

InputBlock IO::InputBlock::get_block ( std::string_view  name) const
inline

If block is present, returns a copy of it. If not, returns empty block.

◆ has_block() [1/2]

bool IO::InputBlock::has_block ( std::string_view  name) const
inline

Checks if block 'name' is present in current block.

◆ has_block() [2/2]

bool IO::InputBlock::has_block ( std::initializer_list< std::string >  blocks,
std::string_view  name 
) const
inline

Checks if block 'name' is present in nesteded block.

◆ getOption()

std::optional< Option > IO::InputBlock::getOption ( std::string_view  key) const
inline

Get an 'Option' (kay, value) - rarely needed.

◆ print()

void IO::InputBlock::print ( std::ostream &  os = std::cout,
int  indent_depth = 0 
) const
inline

Prints options to screen in user-friendly form. Same form as input string. By default prints to cout, but can be given any ostream.

◆ check() [1/2]

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.

◆ check() [2/2]

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

Override for when condidering current block.

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( InputBlock  block,
std::string_view  name 
)
friend

Comparison of blocks compares the 'name'.


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