42 #ifndef OPTIONS_FROM_STREAM_H
43 #define OPTIONS_FROM_STREAM_H
45 #include "Moocho_ConfigDefs.hpp"
50 namespace OptionsFromStreamPack {
51 namespace OptionsFromStreamUtilityPack {
56 false_bool_t() : val_(false) {}
57 void set(
bool val) { val_ = val; }
58 operator bool()
const {
return val_; }
65 typedef std::map< std::string , std::string > option_to_value_map_t;
69 typedef std::pair< option_to_value_map_t, false_bool_t > options_group_pair_t;
73 typedef std::map< std::string, options_group_pair_t > options_group_map_t;
111 class OptionsFromStream;
117 namespace OptionsFromStreamPack {
125 namespace OptionsFromStreamUtilityPack {
262 std::string&
option_value(
const std::string& option_name );
264 const std::string&
option_value(
const std::string& option_name )
const;
292 option_to_value_map_t* option_to_value_map_;
293 static std::string option_does_not_exist_;
302 OptionsGroup( option_to_value_map_t* option_to_value_map )
303 : option_to_value_map_(option_to_value_map)
317 return (*itr).second;
429 typedef OptionsFromStreamUtilityPack::options_group_map_t::iterator
iterator;
431 typedef OptionsFromStreamUtilityPack::options_group_map_t::const_iterator
const_iterator;
438 {
public:
InputStreamError(
const std::string& what_arg) : std::logic_error(what_arg) {}};
538 typedef OptionsFromStreamUtilityPack::false_bool_t false_bool_t;
539 typedef OptionsFromStreamUtilityPack::option_to_value_map_t option_to_value_map_t;
540 typedef OptionsFromStreamUtilityPack::options_group_map_t options_group_map_t;
541 options_group_map_t options_group_map_;
559 const_cast<OptionsFromStreamUtilityPack::option_to_value_map_t*>(&(*itr).second.first) );
569 using OptionsFromStreamUtilityPack::option_name;
571 using OptionsFromStreamUtilityPack::option_value;
583 namespace OptionsFromStreamPack {
585 namespace OptionsFromStreamUtilityPack {
591 option_to_value_map_t::iterator itr = option_to_value_map_->find( option_name );
592 return ( itr != option_to_value_map_->end() ? (*itr).second : option_does_not_exist_ );
597 option_to_value_map_t::const_iterator itr = option_to_value_map_->find( option_name );
598 return ( itr != option_to_value_map_->end() ? (*itr).second : option_does_not_exist_ );
603 return &option_value != &option_does_not_exist_;
608 return option_to_value_map_ != 0;
613 return option_to_value_map_->size();
618 return option_to_value_map_->begin();
623 return option_to_value_map_->end();
628 return option_to_value_map_->begin();
633 return option_to_value_map_->end();
651 options_group_map_.clear();
662 return options_group_map_.size();
667 return options_group_map_.begin();
672 return options_group_map_.end();
677 return options_group_map_.begin();
682 return options_group_map_.end();
687 #endif // OPTIONS_FROM_STREAM_H
Extracts options from a text stream and then allows convenient access to them.
option_to_value_map_t::iterator iterator
OptionsFromStream()
Construct with no options set.
option_to_value_map_t::const_iterator const_iterator
void print_options(std::ostream &out) const
Print the options to an output stream.
static bool options_group_exists(const options_group_t &options_group)
int num_options_groups() const
OptionsFromStreamUtilityPack::options_group_map_t::const_iterator const_iterator
non-const iterator through options group access options
OptionsFromStreamUtilityPack::OptionsGroup options_group_t
{OptionsGroup} typedef
std::string & option_value(const std::string &option_name)
void clear_options()
Clear all the options.
static bool option_exists(const std::string &option_value)
void read_options(std::istream &in)
Add / modify options read in from a text stream.
Class used to encapsulate options belonging an options group.
void reset_unaccessed_options_groups()
Reset the flags to false for if the options groups was accessed.
options_group_t options_group(const std::string &options_group_name)
void print_unaccessed_options_groups(std::ostream &out) const
Print a list of options groups never accessed (accessed flag is falsed).
bool options_group_exists() const
Returns true if this options groups exists.
OptionsFromStreamUtilityPack::options_group_map_t::iterator iterator
const iterator through options group access options