0

I'm trying to read an array from a configuration file but it shows the message: " in option 'PARAM_ARRAY': invalid option value ".

The topic doesn't helps me because it reads the array from command line.

The code (only important lines) is something like this:

typedef boost::numeric::ublas::bounded_vector<double,6> vec6;

po::options_description parameters("Options");
parameters.add_options()
("PARAM_ARRAY", po::value< vec6 >(&configParameters.PARAM_ARRAY), "parameters array comment")
;

then I have this lines too:

po::options_description config_file_options;
    config_file_options.add(parameters);


// Parser the command line options
po::variables_map vm;
po::store(po::command_line_parser(ac, av).
          options(cmdline_options).run(), vm);
po::notify(vm);


// Verify if a config file was passed as an option
if (vm.count("config")) {
     const std::vector<std::string> &config_files = vm["config"].as< std::vector<std::string> >();

    for(std::vector<std::string>::const_iterator it = config_files.begin();
        it != config_files.end(); ++it) {

        ifstream ifs(it->c_str());
        if (!ifs)
        {
            cout << "can not open config file: " << *it << "\n";
            exit(1);
        }

        // Parse the options on the config file.
        // NOTE: They are not going to be updated if they were already set by the command line option
        po::store(parse_config_file(ifs, config_file_options), vm);
        po::notify(vm);
        }
    }

And finally, my configuration file (.yaml) has: PARAM_ARRAY= (0,0,0,0,0,0)

I've also tried: PARAM_ARRAY= {0,0,0,0,0,0} and many other formats.

Community
  • 1
  • 1
NelsonC
  • 53
  • 1
  • 6

1 Answers1

0

I already solved the problem. It was a little annoying blank space between each number, the "{}" should be "()" and I missed the size indication of the array PARAM_ARRAY.

I had:

PARAM_ARRAY= {0, 0, 0, 0, 0, 0}

but the configuration file should be like:

PARAM_ARRAY=[6](0,0,0,0,0,0)

Thank you anyway and hope this will help someone in the future.

NelsonC
  • 53
  • 1
  • 6