How to read subgroups from .ini based YARP configuration files? #2563
-
Is there a way to maintain subgroups based configuration using One of the ways, I have noticed, this being done is by including other ini files into the parent file (for example, see robotology/walking-controllers/dcm_walking_with_joypad.ini cc @GiulioRomualdi ). The contents of the child ini file is added as a sub group to the parent configuration.
I was wondering if there's an alternative to do this from within the same file. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I'm not sure to understand the question, but if you create a foo = a
bar = b
[SUBGROUP_NAME]
foo = a
bar = b you will get a subgroup, that should be the same as using |
Beta Was this translation helpful? Give feedback.
-
Please note groups and nested subgroups internally translate to lists (a.k.a. bottles). For instance: // config1.ini
test1 a
[MYGROUP]
test2 b
NESTED1 (test3 c) After parsing this file with
Which is exactly the same output you'll see if your config file resembles this one: // config2.ini
test1 a
MYGROUP (test2 b) (NESTED1 (test3 c)) Although there is no specific .ini syntax for subgroups such as there is // subgroup-test.cpp
#include <yarp/os/LogStream.h>
#include <yarp/os/ResourceFinder.h>
int main(int argc, char * argv[])
{
yarp::os::ResourceFinder rf;
rf.configure(argc, argv);
yInfo() << "full config:" << rf.toString();
yInfo() << "MYGROUP:" << rf.findGroup("MYGROUP").toString();
yInfo() << "MYGROUP::NESTED1:" << rf.findGroup("MYGROUP").findGroup("NESTED1").toString();
yInfo() << "MYGROUP::NESTED2:" << rf.findGroup("MYGROUP").findGroup("NESTED2").toString();
return 0;
} Result of
I went a bit further to demonstrate the |
Beta Was this translation helpful? Give feedback.
-
Another option is to write something like this [dummy_group foo]
hello 1
[dummy_group bar]
hello 2 This is equivalent to this bottle:
which you can parse using For reference, this page has lots of information about YARP ini files: https://yarp.it/git-master/yarp_config_files.html |
Beta Was this translation helpful? Give feedback.
Please note groups and nested subgroups internally translate to lists (a.k.a. bottles). For instance:
// config1.ini test1 a [MYGROUP] test2 b NESTED1 (test3 c)
After parsing this file with
ResourceFinder
and printing out its contents viatoString()
, you'll get:Which is exactly the same output you'll see if your config file resembles this one:
Although there is no specific .ini syntax for subgroups such as there is
[<group_name>]
for groups, the nested-like behavior can be mimicked by abusing the parens notation. The following C++ code proves my point in tha…