@@ -20,13 +20,16 @@ struct JHasInputs {
20
20
21
21
std::vector<InputBase*> m_inputs;
22
22
std::vector<VariadicInputBase*> m_variadic_inputs;
23
+ std::vector<std::pair<InputBase*, VariadicInputBase*>> m_ordered_inputs;
23
24
24
25
void RegisterInput (InputBase* input) {
25
26
m_inputs.push_back (input);
27
+ m_ordered_inputs.push_back ({input, nullptr });
26
28
}
27
29
28
30
void RegisterInput (VariadicInputBase* input) {
29
31
m_variadic_inputs.push_back (input);
32
+ m_ordered_inputs.push_back ({nullptr , input});
30
33
}
31
34
32
35
struct InputOptions {
@@ -464,6 +467,11 @@ struct JHasInputs {
464
467
const std::vector<JEventLevel>& variadic_input_levels,
465
468
const std::vector<std::vector<std::string>>& variadic_input_databundle_names) {
466
469
470
+ if (m_variadic_inputs.size () == 1 && variadic_input_databundle_names.size () == 0 ) {
471
+ WireInputsCompatibility (component_level, single_input_levels, single_input_databundle_names);
472
+ return ;
473
+ }
474
+
467
475
// Validate that we have the correct number of input databundle names
468
476
if (single_input_databundle_names.size () != m_inputs.size ()) {
469
477
throw JException (" Wrong number of (nonvariadic) input databundle names! Expected %d, found %d" , m_inputs.size (), single_input_databundle_names.size ());
@@ -498,6 +506,45 @@ struct JHasInputs {
498
506
}
499
507
}
500
508
509
+ void WireInputsCompatibility (JEventLevel component_level,
510
+ const std::vector<JEventLevel>& single_input_levels,
511
+ const std::vector<std::string>& single_input_databundle_names) {
512
+
513
+ // Figure out how many collection names belong to the variadic input
514
+ int variadic_databundle_count = single_input_databundle_names.size () - m_inputs.size ();
515
+ int databundle_name_index = 0 ;
516
+ int databundle_level_index = 0 ;
517
+
518
+ for (auto & [single_input, variadic_input] : m_ordered_inputs) {
519
+ if (single_input != nullptr ) {
520
+ single_input->SetDatabundleName (single_input_databundle_names.at (databundle_name_index));
521
+ if (single_input_levels.empty ()) {
522
+ single_input->SetLevel (component_level);
523
+ }
524
+ else {
525
+ single_input->SetLevel (single_input_levels.at (databundle_level_index));
526
+ }
527
+ databundle_name_index += 1 ;
528
+ databundle_level_index += 1 ;
529
+ }
530
+ else {
531
+ std::vector<std::string> variadic_databundle_names;
532
+ for (int i=0 ; i<variadic_databundle_count; ++i) {
533
+ variadic_databundle_names.push_back (single_input_databundle_names.at (databundle_name_index+i));
534
+ }
535
+ variadic_input->SetRequestedDatabundleNames (variadic_databundle_names);
536
+ if (single_input_levels.empty ()) {
537
+ variadic_input->SetLevel (component_level);
538
+ }
539
+ else {
540
+ variadic_input->SetLevel (single_input_levels.at (databundle_level_index)); // Last one wins!
541
+ }
542
+ databundle_name_index += variadic_databundle_count;
543
+ databundle_level_index += 1 ;
544
+ }
545
+ }
546
+ }
547
+
501
548
void SummarizeInputs (JComponentSummary::Component& summary) const {
502
549
for (const auto * input : m_inputs) {
503
550
summary.AddInput (new JComponentSummary::Collection (" " , input->GetDatabundleName (), input->GetTypeName (), input->GetLevel ()));
0 commit comments