Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2795b6d

Browse files
committedOct 24, 2021
Make Config instances have default values in constructor- only C++ now, haven't looked at python #33
1 parent 662ebc1 commit 2795b6d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed
 

‎src/dynamic_reconfigure/parameter_generator.py

+9
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def generatecpp(self):
481481
f = open(os.path.join(self.pkgpath, cfg_cpp_dir, self.name + "Config.h"), 'w')
482482

483483
paramdescr = []
484+
paraminit = []
484485
groups = []
485486
members = []
486487
constants = []
@@ -494,6 +495,10 @@ def write_params(group):
494495
else:
495496
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))
496497
for param in group.parameters:
498+
if len(paraminit) > 0:
499+
self.appendline(paraminit, "${name}($v), ", param, "default")
500+
else:
501+
self.appendline(paraminit, " : ${name}($v), ", param, "default")
497502
self.appendline(members, "${ctype} ${name};", param)
498503
self.appendline(paramdescr, "__min__.${name} = $v;", param, "min")
499504
self.appendline(paramdescr, "__max__.${name} = $v;", param, "max")
@@ -522,12 +527,16 @@ def write_params(group):
522527
self.appendgroup(groups, self.group)
523528

524529
paramdescr = string.join(paramdescr, '\n')
530+
paraminit = ' '.join(paraminit)
531+
# chop off trailing ", "
532+
paraminit = paraminit[:-2]
525533
members = string.join(members, '\n')
526534
groups = string.join(groups, '\n')
527535
constants = string.join(constants, '\n')
528536
f.write(Template(template).substitute(
529537
uname=self.name.upper(),
530538
configname=self.name, pkgname=self.pkgname, paramdescr=paramdescr,
539+
paraminit=paraminit,
531540
members=members, groups=groups, doline=LINEDEBUG, constants=constants))
532541
f.close()
533542

‎src/dynamic_reconfigure/parameter_generator_catkin.py

+9
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def generatecpp(self):
461461
# Write the configuration manipulator.
462462
self.mkdirabs(self.cpp_gen_dir)
463463
paramdescr = []
464+
paraminit = []
464465
groups = []
465466
members = []
466467
constants = []
@@ -473,6 +474,10 @@ def write_params(group):
473474
else:
474475
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))
475476
for param in group.parameters:
477+
if len(paraminit) > 0:
478+
self.appendline(paraminit, "${name}($v), ", param, "default")
479+
else:
480+
self.appendline(paraminit, " : ${name}($v), ", param, "default")
476481
self.appendline(members, "${ctype} ${name};", param)
477482
self.appendline(paramdescr, "__min__.${name} = $v;", param, "min")
478483
self.appendline(paramdescr, "__max__.${name} = $v;", param, "max")
@@ -501,13 +506,17 @@ def write_params(group):
501506
self.appendgroup(groups, self.group)
502507

503508
paramdescr = '\n'.join(paramdescr)
509+
paraminit = ' '.join(paraminit)
510+
# chop off trailing ", "
511+
paraminit = paraminit[:-2]
504512
members = '\n'.join(members)
505513
constants = '\n'.join(constants)
506514
groups = '\n'.join(groups)
507515
with open(os.path.join(self.cpp_gen_dir, self.name + "Config.h"), 'w') as f:
508516
f.write(Template(template).substitute(
509517
uname=self.name.upper(),
510518
configname=self.name, pkgname=self.pkgname, paramdescr=paramdescr,
519+
paraminit=paraminit,
511520
members=members, groups=groups, doline=LINEDEBUG, constants=constants))
512521
print("Wrote header file in " + os.path.join(self.cpp_gen_dir, self.name + "Config.h"))
513522

‎templates/ConfigType.h.template

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ namespace ${pkgname}
3232
class ${configname}Config
3333
{
3434
public:
35+
${configname}Config()
36+
${paraminit}
37+
{
38+
}
3539
class AbstractParamDescription : public dynamic_reconfigure::ParamDescription
3640
{
3741
public:

0 commit comments

Comments
 (0)
Please sign in to comment.