10 template <
bool IsConst>
12 : m_primclex(&_primclex), m_name(selection_path.string()) {
13 if(selection_path ==
"MASTER") {
14 for(
auto it = _primclex.config_begin(); it != _primclex.config_end(); ++it) {
15 set_selected(it->name(), it->selected());
18 else if(selection_path ==
"NONE") {
19 for(
auto it = _primclex.config_cbegin(); it != _primclex.config_cend(); ++it) {
20 set_selected(it->name(),
false);
23 else if(selection_path ==
"ALL") {
24 for(
auto it = _primclex.config_cbegin(); it != _primclex.config_cend(); ++it) {
25 set_selected(it->name(),
true);
28 else if(selection_path ==
"CALCULATED") {
29 for(
auto it = _primclex.config_cbegin(); it != _primclex.config_cend(); ++it) {
34 if(!fs::exists(selection_path)) {
36 ss <<
"ERROR in parsing configuation selection name. \n"
37 <<
" Expected <filename>, 'ALL', 'NONE', 'CALCULATED', or 'MASTER' <--default \n"
38 <<
" Received: '" << selection_path <<
"'\n"
39 <<
" No file named '" << selection_path <<
"'.";
40 throw std::runtime_error(ss.str());
42 m_name = fs::absolute(selection_path).string();
43 if(selection_path.extension() ==
".json" || selection_path.extension() ==
".JSON")
46 std::ifstream select_file(selection_path.string().c_str());
55 template <
bool IsConst>
60 if(_input.peek() ==
'#') {
65 std::getline(_input, tname,
'\n');
66 m_col_headers.clear();
67 boost::split(m_col_headers, tname, boost::is_any_of(
" \t"), boost::token_compress_on);
70 while(_input >> tname >> tselect) {
71 m_config[tname] = tselect;
78 template <
bool IsConst>
81 std::cerr <<
"CRITICAL ERROR: Unable to initialize a ConfigSelection from passed JSON input." << std::endl
82 <<
" JSON input must be an array of Configuration records." << std::endl
83 <<
" Exiting..." << std::endl;
86 std::map<std::string, bool> prop_map;
92 auto it(_json[i].cbegin()), it_end(_json[i].cend());
95 contains_name =
false;
98 for(; it != it_end; ++it) {
99 if(it.name() ==
"configname") {
100 tname = it->get<std::string>();
101 contains_name =
true;
103 else if(it.name() ==
"selected") {
104 tselected = it->get<
bool>();
107 prop_map[it.name()] =
true;
111 throw std::runtime_error(
112 std::string(
"CRITICAL ERROR: Field 'configname' is missing from Configuration ") +
113 std::to_string(i) +
" of json Array passed to ConfigSelection::from_json()." +
114 " This field is required.");
117 m_config[tname] = tselected;
121 std::map<std::string, bool>::iterator it(prop_map.begin()), it_end(prop_map.end());
122 for(; it != it_end; ++it)
123 m_col_headers.push_back(it->first);
129 template <
bool IsConst>
133 bool only_selected)
const {
141 _json = tformat(selected_config_cbegin(),
142 selected_config_cend());
145 _json = tformat(config_cbegin(),
152 template <
bool IsConst>
156 bool only_selected)
const {
162 _out << tformat(selected_config_cbegin(),
163 selected_config_cend());
166 _out << tformat(config_cbegin(),
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
void from_json(ClexDescription &desc, const jsonParser &json)
ConfigIO::Selected selected_in(const ConfigSelection< IsConst > &_selection)
jsonParser & to_json(const DataFormatterDictionary< Configuration > &_dict, jsonParser &_json, bool only_selected=false) const
void print(const DataFormatterDictionary< Configuration > &_dict, std::ostream &_out, bool only_selected=false) const
void read(std::istream &_input)
std::string to_string(ENUM val)
Return string representation of enum class.
const jsonParser & from_json(const jsonParser &_json)
EigenIndex Index
For long integer indexing:
bool is_calculated(const Configuration &config)
Return true if all current properties have been been calculated for the configuration.
T max(const T &A, const T &B)
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
ConfigSelection()
Default constructor.
bool is_array() const
Check if array type.
jsonParser & put_array()
Puts new empty JSON array.