source: src/Descriptors/SelectiveConstIterator_impl.hpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef was feb5d0, checked in by Frederik Heber <heber@…>, 12 years ago

Added SelectiveConstIterator, allows for constant iteration over Descriptor-constraint ranges.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * SelectiveConstIterator_impl.hpp
3 *
4 * Created on: Mar 19, 2013
5 * Author: heber
6 */
7
8#ifndef SELECTIVECONSTITERATOR_IMPL_HPP_
9#define SELECTIVECONSTITERATOR_IMPL_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16
17#include "Helpers/helpers.hpp"
18
19template<class _Target,
20 class _Container,
21 class _Descriptor>
22SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor _descr, const _Container &_content) :
23 descr(_descr.get_impl()),
24 index(0),
25 content(_content)
26{
27 state = content.begin();
28 advanceState();
29}
30
31template<class _Target,
32 class _Container,
33 class _Descriptor>
34SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor _descr, const _Container &_content, SelectiveConstIterator<_Target,_Container,_Descriptor>::Iter _state) :
35 state(_state),
36 descr(_descr.get_impl()),
37 index(0),
38 content(_content)
39{
40 advanceState();
41}
42
43template<class _Target,
44 class _Container,
45 class _Descriptor>
46SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs) :
47 state(rhs.state),
48 descr(rhs.descr),
49 index(rhs.index),
50 content(rhs.content)
51 {}
52
53template<class _Target,
54 class _Container,
55 class _Descriptor>
56SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs)
57{
58 if(&rhs!=this){
59 state=rhs.state;
60 descr=rhs.descr;
61 index=rhs.index;
62 }
63 return *this;
64}
65
66template<class _Target,
67 class _Container,
68 class _Descriptor>
69SelectiveConstIterator<_Target,_Container,_Descriptor>&
70 SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(){
71 ++state;
72 ++index;
73 advanceState();
74 return *this;
75 }
76
77template<class _Target,
78 class _Container,
79 class _Descriptor>
80SelectiveConstIterator<_Target,_Container,_Descriptor> SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(int){
81 SelectiveConstIterator<_Target,_Container,_Descriptor> res = SelectiveConstIterator<_Target,_Container,_Descriptor>(*this);
82 ++(*this);
83 return res;
84 }
85
86template<class _Target,
87 class _Container,
88 class _Descriptor>
89bool
90 SelectiveConstIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs){
91 return state==rhs.state;
92 }
93
94template<class _Target,
95 class _Container,
96 class _Descriptor>
97bool
98 SelectiveConstIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveConstIterator<_Target,_Container,_Descriptor>& rhs){
99 return state!=rhs.state;
100 }
101
102template<class _Target,
103 class _Container,
104 class _Descriptor>
105typename SelectiveConstIterator<_Target,_Container,_Descriptor>::Target const
106 SelectiveConstIterator<_Target,_Container,_Descriptor>::operator*(){
107 return _take<_Target,value_type>::get(*state);
108 }
109
110template<class _Target,
111 class _Container,
112 class _Descriptor>
113void
114 SelectiveConstIterator<_Target,_Container,_Descriptor>::advanceState(){
115 // go forward until we have a matching atom or the end is reached
116 while((state!=content.end()) && (!descr->predicate(*state))){
117 ++state;
118 ++index;
119 }
120 }
121
122template<class _Target,
123 class _Container,
124 class _Descriptor>
125int
126 SelectiveConstIterator<_Target,_Container,_Descriptor>::getCount(){
127 return index;
128 }
129
130
131#define CONSTRUCT_SELECTIVE_CONST_ITERATOR(_Target,_Container,_Descriptor) \
132 template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor, const _Container&); \
133 template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(_Descriptor, const _Container&, SelectiveConstIterator<_Target,_Container,_Descriptor>::Iter); \
134 template SelectiveConstIterator<_Target,_Container,_Descriptor>::SelectiveConstIterator(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
135 template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator=(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
136 template SelectiveConstIterator<_Target,_Container,_Descriptor>& SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(); \
137 template SelectiveConstIterator<_Target,_Container,_Descriptor> SelectiveConstIterator<_Target,_Container,_Descriptor>::operator++(int); \
138 template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator==(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
139 template bool SelectiveConstIterator<_Target,_Container,_Descriptor>::operator!=(const SelectiveConstIterator<_Target,_Container,_Descriptor>&); \
140 template SelectiveConstIterator<_Target,_Container,_Descriptor>::Target const SelectiveConstIterator<_Target,_Container,_Descriptor>::operator*(); \
141 template int SelectiveConstIterator<_Target,_Container,_Descriptor>::getCount();
142
143#endif /* SELECTIVECONSTITERATOR_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.