@@ -388,6 +388,52 @@ class DropScanProps: public GenericAbstractFilter {
388
388
const TScanProps emp_;
389
389
};
390
390
391
+ class ScanPropSetter : public GenericAbstractFilter {
392
+ public:
393
+ ScanPropSetter (AbstractWriter *agent, const TStringList &propList);
394
+
395
+ // / override specified scan properties
396
+ void setScanProps (const TScanProps &origProps) override ;
397
+
398
+ private:
399
+ // key/val pairs are stored in a vector
400
+ using TItem = std::pair<std::string, std::string>;
401
+ using TList = std::vector<TItem>;
402
+ TList itemList_;
403
+ };
404
+
405
+ ScanPropSetter::ScanPropSetter (
406
+ AbstractWriter *agent,
407
+ const TStringList &propList):
408
+ GenericAbstractFilter(agent)
409
+ {
410
+ // iterate over the given NAME:VALUE strings
411
+ for (const std::string &str : propList) {
412
+ // split the string by the first occurrence of ':'
413
+ size_t ddAt = str.find (' :' );
414
+ if (std::string::npos == ddAt) {
415
+ const auto msg = " missing ':' in " + str;
416
+ throw std::runtime_error (msg);
417
+ }
418
+
419
+ // store the key/val pair into the vector
420
+ itemList_.emplace_back (/* key */ str.substr (0 , ddAt), /* val */ str.substr (ddAt + 1 ));
421
+ }
422
+ }
423
+
424
+ void ScanPropSetter::setScanProps (const TScanProps &origProps)
425
+ {
426
+ // we need to copy the given map
427
+ TScanProps props = origProps;
428
+
429
+ // apply specified changes
430
+ for (const auto &item : itemList_)
431
+ props[item./* key */ first] = item./* val */ second;
432
+
433
+ // forward the result
434
+ agent_->setScanProps (props);
435
+ }
436
+
391
437
class DuplicateFilter : public AbstractFilter {
392
438
public:
393
439
DuplicateFilter (AbstractWriter *agent):
@@ -632,6 +678,7 @@ int main(int argc, char *argv[])
632
678
(" embed-context,U" , po::value<int >(), " embed a number of lines of context from the source file for the key event" )
633
679
(" prune-events" , po::value<int >(), " event is preserved if its verbosity level is below the given number" )
634
680
(" remove-duplicates,u" , " remove defects that are not unique by their key event" )
681
+ (" set-scan-prop" , po::value<TStringList>(), " NAME:VALUE pair to override the specified scan property" )
635
682
(" strip-path-prefix" , po::value<string>(), " string prefix to strip from path (applied after all filters)" )
636
683
637
684
(" ignore-case,i" , " ignore case when matching regular expressions" )
@@ -712,6 +759,11 @@ int main(int argc, char *argv[])
712
759
" strip-path-prefix" ))
713
760
return 1 ;
714
761
762
+ // insert ScanPropSetter into the chain if requested
763
+ if (!chainDecoratorGeneric<ScanPropSetter, TStringList>(&eng, vm,
764
+ " set-scan-prop" ))
765
+ return 1 ;
766
+
715
767
// chain all filters
716
768
if (!chainFilters (&eng, vm))
717
769
// an error message already printed out
0 commit comments