owlps/owlps-positioner/configuration.cc

107 lines
2.3 KiB
C++

/*
* This file is part of the Owl Positioning System (OwlPS) project.
* It is subject to the copyright notice and license terms in the
* COPYRIGHT.t2t file found in the top-level directory of this
* distribution and at
* https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
* No part of the OwlPS Project, including this file, may be copied,
* modified, propagated, or distributed except according to the terms
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
* distributed along with this file, either separately or by replacing
* this notice by the COPYRIGHT.t2t file's contents.
*/
#include "configuration.hh"
using namespace std ;
namespace po = boost::program_options ;
/* *** Attribute definitions *** */
po::variables_map Configuration::configuration ;
/* *** Read accessors *** */
po::variables_map& Configuration::getw_configuration()
{
return configuration ;
}
bool Configuration::is_configured(const string &key)
{
if (configuration.count(key))
return true ;
return false ;
}
const std::string&
Configuration::string_value(const string &key)
{
return configuration[key].as<string>() ;
}
int Configuration::int_value(const string &key)
{
return configuration[key].as<int>() ;
}
unsigned int Configuration::uint_value(const string &key)
{
return configuration[key].as<unsigned int>() ;
}
float Configuration::float_value(const string &key)
{
return configuration[key].as<float>() ;
}
bool Configuration::bool_value(const string &key)
{
return configuration[key].as<bool>() ;
}
/**
* @returns `true` if the string `value` exists in the vector `key.`
* @returns `false` if `value` is not found in `key.`
*/
bool Configuration::
value_exists_in_string_vector(const string &key, const string &value)
{
if (! is_configured(key))
return false ;
vector<string> key_values = configuration[key].as< vector<string> >() ;
for (auto i = key_values.begin() ; i != key_values.end() ; ++i)
if (*i == value)
return true ;
return false ;
}
const vector<string>& Configuration::
string_vector_value(const string &key)
{
return configuration[key].as< vector<string> >() ;
}
bool Configuration::autocalibration_enabled()
{
return string_value("positioning.generate-reference-points") != "false" ;
}