source: src/AtomIdSet.cpp@ eb0d77

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 eb0d77 was 6aad6f, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: molecule::containsAtom() is now const and has const param, added AtomIdSet::contains().

  • AtomIdSet::contains() is predicate to whether id is contained, added unit test function.
  • also added molecule::containsAtom() on atomic id only.
  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[5e6534]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
[6aad6f]117/** Predicate whether given atomic id is contained.
118 *
119 * @param id id to check
120 * @return true - is contained, false - is not
121 */
122bool AtomIdSet::contains(const atomId_t &id) const
123{
124 return (atoms.find(id) != atoms.end());
125}
126
127/** Predicate whether given atom is contained.
128 *
129 * @param key atom to check
130 * @return true - is contained, false - is not
131 */
132bool AtomIdSet::contains(const atom * const key) const
133{
134 return contains(key->getId());
135}
136
[5e6534]137/** Returns the iterator to the atom \a *key.
138 *
139 * @param key atom to find
140 * @return iterator to atom if found, to end() - else
141 */
142AtomIdSet::const_iterator AtomIdSet::find(const atom * const key) const
143{
[6aad6f]144 return find(key->getId());
[5e6534]145}
146
147/** Returns the iterator to the atom \a *key.
148 *
149 * @param id atomic id to find
150 * @return iterator to atom if found, to end() - else
151 */
152AtomIdSet::const_iterator AtomIdSet::find(const atomId_t &id) const
153{
154 return const_iterator(atoms.find(id), FromIdToAtom());
155}
156
157/** Inserts a given atom into the set.
158 *
159 * @param key atom to insert
160 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
161 */
162std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atom * const key)
163{
164 std::pair<atomIdSet::iterator, bool> iter =
165 atoms.insert(key->getId());
166 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
167
168 return retiter;
169}
170
171/** Inserts a given atom into the set.
172 *
173 * @param id atomic id to insert
174 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
175 */
176std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atomId_t &id)
177{
178 std::pair<atomIdSet::iterator, bool> iter =
179 atoms.insert(id);
180 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
181
182 return retiter;
183}
184
185AtomIdSet::const_iterator AtomIdSet::erase(AtomIdSet::const_iterator &loc)
186{
187 const_iterator iter = loc;
188 ++iter;
189 atom * const _atom = const_cast<atom *>(*loc);
190 atoms.erase( _atom->getId() );
191 return iter;
192}
193
194/** Erase an atom from the list.
195 *
196 * @param *key key to atom in list
197 * @return iterator to just after removed item (compliant with standard)
198 */
199AtomIdSet::const_iterator AtomIdSet::erase(const atom * const key)
200{
201 const_iterator iter = find(key);
202 if (iter != end()){
203 ++iter;
204 atoms.erase( key->getId() );
205 }
206 return iter;
207}
208
209/** Erase an atom from the list.
210 *
211 * @param id atomic id atom in list to erase
212 * @return iterator to just after removed item (compliant with standard)
213 */
214AtomIdSet::const_iterator AtomIdSet::erase(const atomId_t &id)
215{
216 atomIdSet::const_iterator iter = atoms.find(id);
217 if (iter != atoms.end()){
218 ++iter;
219 atoms.erase( id );
220 }
221 return iterator(iter, FromIdToAtom());
222}
Note: See TracBrowser for help on using the repository browser.