Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make C++ Config instances have default values in constructor #107

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/dynamic_reconfigure/parameter_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ def generatecpp(self):
f = open(os.path.join(self.pkgpath, cfg_cpp_dir, self.name + "Config.h"), 'w')

paramdescr = []
paraminit = []
groups = []
members = []
constants = []
Expand All @@ -493,6 +494,10 @@ def write_params(group):
else:
paramdescr.append(Template("${configname}Config::GroupDescription<${configname}Config::${class}, ${configname}Config::${parentclass}> ${name}(\"${name}\", \"${type}\", ${parent}, ${id}, ${cstate}, &${configname}Config::${field});").safe_substitute(group.to_dict(), configname=self.name))
for param in group.parameters:
if len(paraminit) > 0:
self.appendline(paraminit, "${name}($v), ", param, "default")
else:
self.appendline(paraminit, " : ${name}($v), ", param, "default")
self.appendline(members, "${ctype} ${name};", param)
self.appendline(paramdescr, "__min__.${name} = $v;", param, "min")
self.appendline(paramdescr, "__max__.${name} = $v;", param, "max")
Expand Down Expand Up @@ -521,12 +526,16 @@ def write_params(group):
self.appendgroup(groups, self.group)

paramdescr = '\n'.join(paramdescr)
paraminit = ' '.join(paraminit)
# chop off trailing ", "
paraminit = paraminit[:-2]
members = '\n'.join(members)
groups = '\n'.join(groups)
constants = '\n'.join(constants)
f.write(Template(template).substitute(
uname=self.name.upper(),
configname=self.name, pkgname=self.pkgname, paramdescr=paramdescr,
paraminit=paraminit,
members=members, groups=groups, doline=LINEDEBUG, constants=constants))
f.close()

Expand Down
9 changes: 9 additions & 0 deletions src/dynamic_reconfigure/parameter_generator_catkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def generatecpp(self):
# Write the configuration manipulator.
self.mkdirabs(self.cpp_gen_dir)
paramdescr = []
paraminit = []
groups = []
members = []
constants = []
Expand All @@ -473,6 +474,10 @@ def write_params(group):
else:
paramdescr.append(Template("${configname}Config::GroupDescription<${configname}Config::${class}, ${configname}Config::${parentclass}> ${name}(\"${name}\", \"${type}\", ${parent}, ${id}, ${cstate}, &${configname}Config::${field});").safe_substitute(group.to_dict(), configname=self.name))
for param in group.parameters:
if len(paraminit) > 0:
self.appendline(paraminit, "${name}($v), ", param, "default")
else:
self.appendline(paraminit, " : ${name}($v), ", param, "default")
self.appendline(members, "${ctype} ${name};", param)
self.appendline(paramdescr, "__min__.${name} = $v;", param, "min")
self.appendline(paramdescr, "__max__.${name} = $v;", param, "max")
Expand Down Expand Up @@ -501,13 +506,17 @@ def write_params(group):
self.appendgroup(groups, self.group)

paramdescr = '\n'.join(paramdescr)
paraminit = ' '.join(paraminit)
# chop off trailing ", "
paraminit = paraminit[:-2]
members = '\n'.join(members)
constants = '\n'.join(constants)
groups = '\n'.join(groups)
with open(os.path.join(self.cpp_gen_dir, self.name + "Config.h"), 'w') as f:
f.write(Template(template).substitute(
uname=self.name.upper(),
configname=self.name, pkgname=self.pkgname, paramdescr=paramdescr,
paraminit=paraminit,
members=members, groups=groups, doline=LINEDEBUG, constants=constants))
print("Wrote header file in " + os.path.join(self.cpp_gen_dir, self.name + "Config.h"))

Expand Down
4 changes: 4 additions & 0 deletions templates/ConfigType.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace ${pkgname}
class ${configname}Config
{
public:
${configname}Config()
${paraminit}
{
}
class AbstractParamDescription : public dynamic_reconfigure::ParamDescription
{
public:
Expand Down