28#ifndef app_appConfigurator_hpp
29#define app_appConfigurator_hpp
51 const std::string &filename ) =
99 typedef std::unordered_map<std::string, configTarget>::iterator
targetIterator;
105 std::unordered_map<std::string, configTarget>
m_targets;
135 void add(
const std::string &n,
136 const std::string &so,
137 const std::string &lo,
140 const std::string &s,
141 const std::string &kw,
143 const std::string &ht =
"",
144 const std::string &he =
""
152 const std::string &oneTarget =
""
160 bool reportFileNotFound =
true
168 bool isSet(
const std::string &name,
169 std::unordered_map<std::string, configTarget> &targets
179 bool isSet(
const std::string &name );
185 int count(
const std::string &name,
186 std::unordered_map<std::string, configTarget> &targets
195 int count(
const std::string &name );
204 std::unordered_map<std::string, configTarget> &targets
215 int verbosity(
const std::string &name );
224 template <
typename typeT>
226 const std::string &name,
228 std::unordered_map<std::string, configTarget> &targets
240 template <
typename typeT>
242 const std::string &name,
255 template <
typename typeT>
257 const std::string &name,
258 std::unordered_map<std::string, configTarget> &targets
270 template <
typename typeT>
272 const std::string &name
283 template <
typename typeT>
284 int get( std::vector<typeT> &v,
285 const std::string &name,
287 std::unordered_map<std::string, configTarget> &targets
298 template <
typename typeT>
299 int get( std::vector<typeT> &v,
300 const std::string &name,
312 template <
typename typeT>
313 int get( std::vector<typeT> &v,
314 const std::string &name,
315 std::unordered_map<std::string, configTarget> &targets
326 template <
typename typeT>
327 int get( std::vector<typeT> &v,
328 const std::string &name
336 template <
typename typeT>
339 const std::string &name
347 template <
typename typeT>
350 const std::string &key
358 template <
typename typeT>
361 const std::string §ion,
362 const std::string &keyword
383 const std::string &name,
385 const std::string &valueStr,
386 const std::string &source
393template <
typename typeT>
395 const std::string &name,
397 std::unordered_map<std::string, configTarget> &targets )
399 targets[name].used =
true;
401 if( !
isSet( name, targets ) )
411 if( targets[name].values.size() <= i )
435 const std::string &name,
437 std::unordered_map<std::string, configTarget> &targets );
440 const std::string &name,
442 std::unordered_map<std::string, configTarget> &targets );
445 const std::string &name,
447 std::unordered_map<std::string, configTarget> &targets );
450 const std::string &name,
452 std::unordered_map<std::string, configTarget> &targets );
455 const std::string &name,
457 std::unordered_map<std::string, configTarget> &targets );
460 const std::string &name,
462 std::unordered_map<std::string, configTarget> &targets );
465 const std::string &name,
467 std::unordered_map<std::string, configTarget> &targets );
470 const std::string &name,
472 std::unordered_map<std::string, configTarget> &targets );
475 const std::string &name,
477 std::unordered_map<std::string, configTarget> &targets );
480 const std::string &name,
482 std::unordered_map<std::string, configTarget> &targets );
485 const std::string &name,
487 std::unordered_map<std::string, configTarget> &targets );
490 const std::string &name,
492 std::unordered_map<std::string, configTarget> &targets );
495 const std::string &name,
497 std::unordered_map<std::string, configTarget> &targets );
500 const std::string &name,
502 std::unordered_map<std::string, configTarget> &targets );
506 const std::string &name,
508 std::unordered_map<std::string, configTarget> &targets );
512 const std::string &name,
514 std::unordered_map<std::string, configTarget> &targets );
517 const std::string &name,
519 std::unordered_map<std::string, configTarget> &targets );
523template <
typename typeT>
569template <
typename typeT>
570int appConfigurator::get( typeT &v,
const std::string &name, std::unordered_map<std::string, configTarget> &targets )
572 targets[name].used =
true;
574 if( !
isSet( name, targets ) )
584 int i = targets[name].values.size() - 1;
589 return get( v, name, i, targets );
597 const std::string &name,
598 std::unordered_map<std::string, configTarget> &targets );
601 const std::string &name,
602 std::unordered_map<std::string, configTarget> &targets );
611 const std::string &name,
612 std::unordered_map<std::string, configTarget> &targets );
615 const std::string &name,
616 std::unordered_map<std::string, configTarget> &targets );
619 const std::string &name,
620 std::unordered_map<std::string, configTarget> &targets );
623 const std::string &name,
624 std::unordered_map<std::string, configTarget> &targets );
627 const std::string &name,
628 std::unordered_map<std::string, configTarget> &targets );
631 const std::string &name,
632 std::unordered_map<std::string, configTarget> &targets );
635 const std::string &name,
636 std::unordered_map<std::string, configTarget> &targets );
639 const std::string &name,
640 std::unordered_map<std::string, configTarget> &targets );
643 const std::string &name,
644 std::unordered_map<std::string, configTarget> &targets );
648 const std::string &name,
649 std::unordered_map<std::string, configTarget> &targets );
656 const std::string &name,
657 std::unordered_map<std::string, configTarget> &targets );
661template <
typename typeT>
705template <
typename typeT>
707 const std::string &name,
709 std::unordered_map<std::string, configTarget> &targets )
711 targets[name].used =
true;
713 if( !
isSet( name, targets ) )
723 if( targets[name].values.size() <= i )
756 while( st < s.size() && ::isspace(
static_cast<unsigned char>( s[st] ) ) )
759 com = s.find(
',', st );
763 while( com != std::string::npos )
767 while( st < s.size() && ::isspace(
static_cast<unsigned char>( s[st] ) ) )
770 com = s.find(
',', st );
792 const std::string &name,
794 std::unordered_map<std::string, configTarget> &targets );
797 const std::string &name,
799 std::unordered_map<std::string, configTarget> &targets );
802 const std::string &name,
804 std::unordered_map<std::string, configTarget> &targets );
807 const std::string &name,
809 std::unordered_map<std::string, configTarget> &targets );
812 const std::string &name,
814 std::unordered_map<std::string, configTarget> &targets );
817 const std::string &name,
819 std::unordered_map<std::string, configTarget> &targets );
822 const std::string &name,
824 std::unordered_map<std::string, configTarget> &targets );
827 const std::string &name,
829 std::unordered_map<std::string, configTarget> &targets );
832 const std::string &name,
834 std::unordered_map<std::string, configTarget> &targets );
837 const std::string &name,
839 std::unordered_map<std::string, configTarget> &targets );
842 const std::string &name,
844 std::unordered_map<std::string, configTarget> &targets );
847 const std::string &name,
849 std::unordered_map<std::string, configTarget> &targets );
852 const std::string &name,
854 std::unordered_map<std::string, configTarget> &targets );
857 const std::string &name,
859 std::unordered_map<std::string, configTarget> &targets );
863 const std::string &name,
865 std::unordered_map<std::string, configTarget> &targets );
869 const std::string &name,
871 std::unordered_map<std::string, configTarget> &targets );
874 const std::string &name,
876 std::unordered_map<std::string, configTarget> &targets );
880template <
typename typeT>
930template <
typename typeT>
932 const std::string &name,
933 std::unordered_map<std::string, configTarget> &targets )
935 targets[name].used =
true;
937 if( !
isSet( name, targets ) )
945 int i = targets[name].values.size() - 1;
950 return get( v, name, i, targets );
955 const std::string &name,
956 std::unordered_map<std::string, configTarget> &targets );
959 const std::string &name,
960 std::unordered_map<std::string, configTarget> &targets );
963 const std::string &name,
964 std::unordered_map<std::string, configTarget> &targets );
967 const std::string &name,
968 std::unordered_map<std::string, configTarget> &targets );
971 const std::string &name,
972 std::unordered_map<std::string, configTarget> &targets );
975 const std::string &name,
976 std::unordered_map<std::string, configTarget> &targets );
979 const std::string &name,
980 std::unordered_map<std::string, configTarget> &targets );
983 const std::string &name,
984 std::unordered_map<std::string, configTarget> &targets );
987 const std::string &name,
988 std::unordered_map<std::string, configTarget> &targets );
991 const std::string &name,
992 std::unordered_map<std::string, configTarget> &targets );
995 const std::string &name,
996 std::unordered_map<std::string, configTarget> &targets );
999 const std::string &name,
1000 std::unordered_map<std::string, configTarget> &targets );
1003 const std::string &name,
1004 std::unordered_map<std::string, configTarget> &targets );
1007 const std::string &name,
1008 std::unordered_map<std::string, configTarget> &targets );
1012 const std::string &name,
1013 std::unordered_map<std::string, configTarget> &targets );
1017 const std::string &name,
1018 std::unordered_map<std::string, configTarget> &targets );
1021 const std::string &name,
1022 std::unordered_map<std::string, configTarget> &targets );
1026template <
typename typeT>
1054 const std::string &name );
1072template <
typename typeT>
1080extern template int appConfigurator::operator()<
char>(
char &v,
const std::string &name );
1082extern template int appConfigurator::operator()<
signed char>(
signed char &v,
const std::string &name );
1084extern template int appConfigurator::operator()<
short>(
short &v,
const std::string &name );
1086extern template int appConfigurator::operator()<
int>(
int &v,
const std::string &name );
1088extern template int appConfigurator::operator()<
long>(
long &v,
const std::string &name );
1090extern template int appConfigurator::operator()<
long long>(
long long &v,
const std::string &name );
1092extern template int appConfigurator::operator()<
unsigned char>(
unsigned char &v,
const std::string &name );
1094extern template int appConfigurator::operator()<
unsigned short>(
unsigned short &v,
const std::string &name );
1096extern template int appConfigurator::operator()<
unsigned int>(
unsigned int &v,
const std::string &name );
1098extern template int appConfigurator::operator()<
unsigned long>(
unsigned long &v,
const std::string &name );
1100extern template int appConfigurator::operator()<
unsigned long long>(
unsigned long long &v,
const std::string &name );
1102extern template int appConfigurator::operator()<
float>(
float &v,
const std::string &name );
1104extern template int appConfigurator::operator()<
double>(
double &v,
const std::string &name );
1106extern template int appConfigurator::operator()<
long double>(
long double &v,
const std::string &name );
1109extern template int appConfigurator::operator()<__float128>( __float128 &v,
const std::string &name );
1112extern template int appConfigurator::operator()<
bool>(
bool &v,
const std::string &name );
1114extern template int appConfigurator::operator()<std::string>( std::string &v,
const std::string &name );
1118template <
typename typeT>
1161template <
typename typeT>
1186 const std::string §ion,
1187 const std::string &keyword );
1190 const std::string §ion,
1191 const std::string &keyword );
1197 const std::string §ion,
1198 const std::string &keyword );
1201 const std::string §ion,
1202 const std::string &keyword );
1255 const std::vector<std::string> §ions,
1256 const std::vector<std::string> &keywords,
1257 const std::vector<std::string> &values
void writeConfigFile(const std::string &fname, const std::vector< std::string > §ions, const std::vector< std::string > &keywords, const std::vector< std::string > &values)
A simple config file writing function, useful for testing.
int(* appConfiguratorParser)(iniFile &parser, const std::string &filename)
Optional parser override used to deterministically test appConfigurator parser failures.
Targets for the configuration manager, and utiltities.
typeT stoT(const std::string &str, error_t *errc=nullptr)
Convert a string to a numerical value.
Declares and defines an ini-style (toml) file parser.
Declarations of some libarary wide utilities.
Class to manage a set of configurable values, and read their values from config/ini files and the com...
std::unordered_map< std::string, configTarget > m_targets
The targets are stored in an unordered_map for fast access by key.
int readConfig(const std::string &fname, bool reportFileNotFound=true)
Read and parse a config/ini file, updating the targets.
int operator()(typeT &v, const std::string &name)
Access operator, configures a value by calling get.
void add(const configTarget &tgt)
Add a configTarget.
bool m_sources
Flag controlling whether or not to record config sources.
int get(typeT &v, const std::string &name, size_t i, std::unordered_map< std::string, configTarget > &targets)
Get the i-th value of the target, converted to the specified type.
std::vector< std::string > nonOptions
Non-option arguments from the command line.
int configUnused(typeT &v, const std::string &key)
Configure a value from the unused map, using the iniFile key.
void(* configLog)(const std::string &name, const int &code, const std::string &valueStr, const std::string &source)
Call an external logging function whenever a config value is accessed by get or operator().
int verbosity(const std::string &name, std::unordered_map< std::string, configTarget > &targets)
Get the command line verbosity count for this option.
std::unordered_map< std::string, configTarget >::iterator targetIterator
Iterator for the targets unordered_map.
int isSetUnused(const std::string &name)
Check if a target has been set in the unused configuration.
bool isSet(const std::string &name, std::unordered_map< std::string, configTarget > &targets)
Check if a target has been set by the configuration.
void clear()
Clear the containers and free up the associated memory.
int unusedSections(std::vector< std::string > §ions)
Get the unique sections in the unused config targets.
int numUnknownOptions()
Get the number of unknown options found during config processing.
std::list< configTarget > clOnlyTargets
Targets which are only for the command line are stored separately in a list.
int count(const std::string &name, std::unordered_map< std::string, configTarget > &targets)
Get the number of different values set for the specified config target.
void parseCommandLine(int argc, char **argv, const std::string &oneTarget="")
Parse the command line, updating the targets.
int nAdded
Running count of options added, used to track order.
std::unordered_map< std::string, configTarget > m_unusedConfigs
std::list< configTarget >::iterator clOnlyTargetIterator
Iterator for the clOnlyTargets list.
A wrapper for the ini functions.
static std::string makeKey(const std::string §ion, const std::string &name)
Return a key generated from the section and name.