source: src/AtomIdSet.cpp@ 8de597

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 8de597 was 5e6534, checked in by Frederik Heber <heber@…>, 13 years ago

Refactored transform_iterator out of class molecule as AtomIdSet.

  • also added unit test.
  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * AtomIdSet.cpp
10 *
11 * Created on: Feb 21, 2012
12 * Author: heber
13 */
14
15
16// include config.h
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "CodePatterns/MemDebug.hpp"
22
23#include "AtomIdSet.hpp"
24
25#include <boost/foreach.hpp>
26
27#include "Atom/atom.hpp"
28#include "Descriptors/AtomIdDescriptor.hpp"
29#include "World.hpp"
30
31atom * FromIdToAtom::operator()(atomId_t id) const {
32 return World::getInstance().getAtom(AtomById(id));
33}
34
35/** Constructor for class AtomIdSet.
36 *
37 * @param _atoms atoms to put into this set
38 */
39AtomIdSet::AtomIdSet(const atomIdSet &_atoms) :
40 atoms(_atoms)
41{}
42
43/** Constructor for class AtomIdSet.
44 *
45 * @param _atoms atoms to put into this set
46 */
47AtomIdSet::AtomIdSet(const std::vector<atom *> &_atoms)
48{
49 BOOST_FOREACH(const atom * _atom, _atoms) {
50 insert(_atom->getId());
51 }
52}
53
54/** Constructor for class AtomIdSet.
55 *
56 */
57AtomIdSet::AtomIdSet()
58{}
59
60/** Destructor for class AtomIdSet.
61 *
62 */
63AtomIdSet::~AtomIdSet()
64{}
65
66/** Returns iterator to first atim via a transform_iterator.
67 *
68 * @return iterator to first atom in this set
69 */
70AtomIdSet::iterator AtomIdSet::begin(){
71 return iterator(atoms.begin(), FromIdToAtom());
72}
73
74/** Returns constant iterator to first atim via a transform_iterator.
75 *
76 * @return const iterator to first atom in this set
77 */
78AtomIdSet::const_iterator AtomIdSet::begin() const{
79 return const_iterator(atoms.begin(), FromIdToAtom());
80}
81
82/** Returns iterator to one beyond last atom via a transform_iterator.
83 *
84 * @return iterator to one beyond last atom in this set
85 */
86AtomIdSet::iterator AtomIdSet::end(){
87 return iterator(atoms.end(), FromIdToAtom());
88}
89
90/** Returns constant iterator to one beyond last atom via a transform_iterator.
91 *
92 * @return const iterator to one beyond last atom in this set
93 */
94AtomIdSet::const_iterator AtomIdSet::end() const{
95 return const_iterator(atoms.end(), FromIdToAtom());
96}
97
98/** Returns true if this set is empty.
99 *
100 * @return true - set is empty, false - there is at least one atom
101 */
102bool AtomIdSet::empty() const
103{
104 return (atoms.empty());
105}
106
107/** Returns the number of members of this set.
108 *
109 * @return number of members in set
110 */
111size_t AtomIdSet::size() const
112{
113 // set has unique members, hence just return its size
114 return atoms.size();
115}
116
117/** Returns the iterator to the atom \a *key.
118 *
119 * @param key atom to find
120 * @return iterator to atom if found, to end() - else
121 */
122AtomIdSet::const_iterator AtomIdSet::find(const atom * const key) const
123{
124 return const_iterator(atoms.find(key->getId()), FromIdToAtom());
125}
126
127/** Returns the iterator to the atom \a *key.
128 *
129 * @param id atomic id to find
130 * @return iterator to atom if found, to end() - else
131 */
132AtomIdSet::const_iterator AtomIdSet::find(const atomId_t &id) const
133{
134 return const_iterator(atoms.find(id), FromIdToAtom());
135}
136
137/** Inserts a given atom into the set.
138 *
139 * @param key atom to insert
140 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
141 */
142std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atom * const key)
143{
144 std::pair<atomIdSet::iterator, bool> iter =
145 atoms.insert(key->getId());
146 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
147
148 return retiter;
149}
150
151/** Inserts a given atom into the set.
152 *
153 * @param id atomic id to insert
154 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
155 */
156std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atomId_t &id)
157{
158 std::pair<atomIdSet::iterator, bool> iter =
159 atoms.insert(id);
160 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
161
162 return retiter;
163}
164
165AtomIdSet::const_iterator AtomIdSet::erase(AtomIdSet::const_iterator &loc)
166{
167 const_iterator iter = loc;
168 ++iter;
169 atom * const _atom = const_cast<atom *>(*loc);
170 atoms.erase( _atom->getId() );
171 return iter;
172}
173
174/** Erase an atom from the list.
175 *
176 * @param *key key to atom in list
177 * @return iterator to just after removed item (compliant with standard)
178 */
179AtomIdSet::const_iterator AtomIdSet::erase(const atom * const key)
180{
181 const_iterator iter = find(key);
182 if (iter != end()){
183 ++iter;
184 atoms.erase( key->getId() );
185 }
186 return iter;
187}
188
189/** Erase an atom from the list.
190 *
191 * @param id atomic id atom in list to erase
192 * @return iterator to just after removed item (compliant with standard)
193 */
194AtomIdSet::const_iterator AtomIdSet::erase(const atomId_t &id)
195{
196 atomIdSet::const_iterator iter = atoms.find(id);
197 if (iter != atoms.end()){
198 ++iter;
199 atoms.erase( id );
200 }
201 return iterator(iter, FromIdToAtom());
202}
Note: See TracBrowser for help on using the repository browser.