| [dae158] | 1 | /*
 | 
|---|
 | 2 |  * getFlatListFromHierarchyOfValidators.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Sep 7, 2014
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef GETFLATLISTFROMHIERARCHYOFVALIDATORS_HPP_
 | 
|---|
 | 9 | #define GETFLATLISTFROMHIERARCHYOFVALIDATORS_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <algorithm>
 | 
|---|
 | 17 | #include <vector>
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | #include "Parameters/Validators/Validator.hpp"
 | 
|---|
 | 20 | #include "Parameters/Validators/Ops_Validator.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | template <class T>
 | 
|---|
 | 23 | void ValidatorHierarchyClimber(
 | 
|---|
 | 24 |     const Validator<T> &_validator,
 | 
|---|
 | 25 |     std::vector<std::pair<const Validator<T> *, bool> > &_validators,
 | 
|---|
 | 26 |     const bool _groundtruth)
 | 
|---|
 | 27 | {
 | 
|---|
 | 28 |   if (dynamic_cast<const And_Validator<T> *>(&_validator) != NULL) {
 | 
|---|
 | 29 |     const And_Validator<T>& and_validator = dynamic_cast<const And_Validator<T>& >(_validator);
 | 
|---|
 | 30 |     ValidatorHierarchyClimber(*and_validator.getA(), _validators, _groundtruth);
 | 
|---|
 | 31 |     ValidatorHierarchyClimber(*and_validator.getB(), _validators, _groundtruth);
 | 
|---|
 | 32 |   } else if (dynamic_cast<const Or_Validator<T> *>(&_validator) != NULL) {
 | 
|---|
 | 33 |     const Or_Validator<T>& or_validator = dynamic_cast<const Or_Validator<T>& >(_validator);
 | 
|---|
 | 34 |     ValidatorHierarchyClimber(*or_validator.getA(), _validators, _groundtruth);
 | 
|---|
 | 35 |     ValidatorHierarchyClimber(*or_validator.getB(), _validators, _groundtruth);
 | 
|---|
 | 36 |   } else if (dynamic_cast<const Not_Validator<T> *>(&_validator) != NULL) {
 | 
|---|
 | 37 |     const Not_Validator<T>& not_validator = dynamic_cast<const Not_Validator<T>& >(_validator);
 | 
|---|
 | 38 |     ValidatorHierarchyClimber(*not_validator.getA(), _validators, !_groundtruth);
 | 
|---|
 | 39 |   } else if (dynamic_cast<const Validator<T> *>(&_validator) != NULL) {
 | 
|---|
 | 40 |     const Validator<T> * Tvalidator = dynamic_cast<const Validator<T> * >(&_validator);
 | 
|---|
 | 41 |     _validators.push_back( std::make_pair(Tvalidator, _groundtruth) );
 | 
|---|
 | 42 |   }
 | 
|---|
 | 43 | }
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | /** Function that recursively climbs down the hierarchy of validators and adds all
 | 
|---|
 | 46 |  * to a common vector as tuples of validator and a boolean, giving the ground truth
 | 
|---|
 | 47 |  * of the validator, i.e. whether it was negated by a prior Not_Validator.
 | 
|---|
 | 48 |  */
 | 
|---|
 | 49 | template <class T>
 | 
|---|
 | 50 | std::vector<std::pair<const Validator<T> *, bool> >
 | 
|---|
 | 51 | getFlatListFromHierarchyOfValidators(const Validator<T> &_validator)
 | 
|---|
 | 52 | {
 | 
|---|
 | 53 |   std::vector<std::pair<const Validator<T> *, bool> > validators;
 | 
|---|
 | 54 |   ValidatorHierarchyClimber(_validator, validators, true);
 | 
|---|
 | 55 |   return validators;
 | 
|---|
 | 56 | }
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | #endif /* GETFLATLISTFROMHIERARCHYOFVALIDATORS_HPP_ */
 | 
|---|