Boost::program_options で空の値を受け入れる方法から部分的な解決策を得ました。これは、引数が存在する場合と存在しない場合があるパラメーターに対して、implicit_value メソッドを使用することを提案しています。したがって、「明るさ」パラメーターを初期化するための呼び出しは次のようになります。
("brightness,b", po::value<string>()->implicit_value(""),
次に、変数マップを反復処理し、文字列である引数について、それが空かどうかを確認し、そうであれば現在の値を出力します。そのコードは次のようになります。
// check if we're just printing a feature's current value
bool gotFeature = false;
for (po::variables_map::iterator iter = vm.begin(); iter != vm.end(); ++iter)
{
/// parameter has been given with no value
if (iter->second.value().type() == typeid(string))
if (iter->second.as<string>().empty())
{
gotFeature = true;
printFeatureValue(iter->first, camera);
}
}
// this is all we're supposed to do, time to exit
if (gotFeature)
{
cleanup(dc1394, camera, cameras);
return 0;
}
更新: これにより、前述の構文が変更されます。暗黙的な値を使用する場合は、引数が指定された場合、次の形式にする必要があります。
./dc-ctl -b500
それ以外の
./dc-ctl -b 500
これが他の誰かに役立つことを願っています。