source: src/Parameters/Validators/STLVectorValidator.hpp@ 8453b3

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 8453b3 was 8453b3, checked in by Frederik Heber <heber@…>, 13 years ago

Exemplarily modified PairCorrelationAction.def to have specific validators.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * STLVectorValidator.hpp
3 *
4 * Created on: May 9, 2012
5 * Author: heber
6 */
7
8#ifndef STLVECTORVALIDATOR_HPP_
9#define STLVECTORVALIDATOR_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include "DummyValidator.hpp"
18#include "RangeValidator.hpp"
19#include "Validator.hpp"
20
21#include <vector>
22
23#include "CodePatterns/Range.hpp"
24
25/** This class is a combination of \ref Validator<size_t> on the number of entries in
26 * the vector while each element is checked with a given Validator<value_type>.
27 */
28template <class T>
29class STLVectorValidator : public Validator< T >
30{
31 //!> this should throw an error at compile time if T is not a container
32 typedef typename T::value_type value_type;
33
34public:
35 /** Constructor for class STLVectorValidator, number of elements given by a range.
36 *
37 * @param validator validator for the single element
38 * @param range range of valid number of elements
39 */
40 STLVectorValidator(const range<size_t> &range, const Validator<value_type> &validator) :
41 ElementwiseValidator(validator.clone()),
42 NumberOfElementsValidator(new RangeValidator<size_t>(range))
43 {}
44
45 /** Constructor for class STLVectorValidator, number of elements given by a range.
46 *
47 * @param range range of valid number of elements
48 */
49 STLVectorValidator(const range<size_t> &range) :
50 ElementwiseValidator(new DummyValidator<value_type>()),
51 NumberOfElementsValidator(new RangeValidator<size_t>(range))
52 {}
53
54 /** Constructor for class STLVectorValidator, number of elements given by interval [\a min,\a max).
55 *
56 * @param validator validator for the single element
57 * @param min lower bound of interval for valid number of elements
58 * @param max upper bound of interval for valid number of elements
59 */
60 STLVectorValidator(const size_t min, const size_t max, const Validator<value_type> &validator) :
61 ElementwiseValidator(validator.clone()),
62 NumberOfElementsValidator(new RangeValidator<size_t>(min,max))
63 {}
64
65 /** Constructor for class STLVectorValidator, number of elements given by interval [\a min,\a max).
66 *
67 * @param min lower bound of interval for valid number of elements
68 * @param max upper bound of interval for valid number of elements
69 */
70 STLVectorValidator(const size_t min, const size_t max) :
71 ElementwiseValidator(new DummyValidator<value_type>()),
72 NumberOfElementsValidator(new RangeValidator<size_t>(min,max))
73 {}
74
75 /** Constructor for class STLVectorValidator, any number of elements is allowed.
76 *
77 * @param validator validator for the single element
78 */
79 STLVectorValidator(const Validator<value_type> &validator) :
80 ElementwiseValidator(validator.clone()),
81 NumberOfElementsValidator(new DummyValidator<size_t>())
82 {}
83
84 /** Constructor for class STLVectorValidator, any number of unrestricted elements is allowed.
85 *
86 */
87 STLVectorValidator() :
88 ElementwiseValidator(new DummyValidator<value_type>()),
89 NumberOfElementsValidator(new DummyValidator<size_t>())
90 {}
91
92 /** Destructor for class STLVectorValidator
93 *
94 */
95 ~STLVectorValidator()
96 {
97 delete ElementwiseValidator;
98 delete NumberOfElementsValidator;
99 }
100
101 bool isValid(const T & _value) const
102 {
103 bool status = NumberOfElementsValidator->isValid(_value.size());
104 for (typename std::vector<value_type>::const_iterator iter = _value.begin();
105 iter != _value.end(); ++iter) {
106 status = status && ElementwiseValidator->isValid(*iter);
107 }
108 return status;
109 }
110 bool operator==(const Validator<T> &_instance) const
111 {
112 const STLVectorValidator<T> *inst = dynamic_cast<const STLVectorValidator<T> *>(&_instance);
113 bool status = *NumberOfElementsValidator == *inst->NumberOfElementsValidator;
114 status = status && *ElementwiseValidator == *inst->ElementwiseValidator;
115 return status;
116 }
117
118 Validator<T>* clone() const
119 {
120 Validator<T> *inst = new STLVectorValidator<T>(*NumberOfElementsValidator, *ElementwiseValidator);
121 return inst;
122 }
123
124private:
125 /** Constructor for class STLVectorValidator, number of elements given by \ref RangeValidator.
126 *
127 * \note Is only used in STLVectorValidator::clone() as it may lead to ambiguities
128 * with a signature of two validators in case value_type equals size_t.
129 *
130 * @param validator validator for the single element
131 * @param rangevalidator validator for the valid number of elements
132 */
133 STLVectorValidator(const Validator<size_t> &rangevalidator, const Validator<value_type> &validator) :
134 ElementwiseValidator(validator.clone()),
135 NumberOfElementsValidator(dynamic_cast< Validator<size_t> *>(rangevalidator.clone()))
136 {}
137
138
139private:
140 Validator<value_type> *ElementwiseValidator;
141 Validator<size_t> *NumberOfElementsValidator;
142};
143
144
145#endif /* STLVECTORVALIDATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.