source: src/AtomIdSet.cpp@ 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 f01769, checked in by Frederik Heber <heber@…>, 9 years ago

Replaced World::getAtom() wherever possible by const version.

  • some AtomSet member functions now have const atom ptr instead of atom ptr.
  • molecule can return const and non-const AtomSet.
  • added FromIdToConstAtom to allow iterate through atoms in molecule (which are stored by id, not by ptr) in const fashion.
  • in molecule::isInMolecule() is now const, ::CopyMolecule..() is non-const (because copying involves father atom who is stored non-const).
  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * AtomIdSet.cpp
25 *
26 * Created on: Feb 21, 2012
27 * Author: heber
28 */
29
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "CodePatterns/MemDebug.hpp"
37
38#include "AtomIdSet.hpp"
39
40#include <boost/foreach.hpp>
41
42#include "Atom/atom.hpp"
43#include "Descriptors/AtomIdDescriptor.hpp"
44#include "Fragmentation/KeySet.hpp"
45#include "World.hpp"
46
47atom * FromIdToAtom::operator()(atomId_t id) const {
48 return World::getInstance().getAtom(AtomById(id));
49}
50
51const atom * FromIdToConstAtom::operator()(atomId_t id) const {
52 return const_cast<const World &>(World::getInstance()).getAtom(AtomById(id));
53}
54
55/** Constructor for class AtomIdSet.
56 *
57 * @param _atoms atoms to put into this set
58 */
59AtomIdSet::AtomIdSet(const atomIdSet &_atoms) :
60 atoms(_atoms)
61{}
62
63/** Constructor for class AtomIdSet.
64 *
65 * @param _keyset keyset to put into this set
66 */
67AtomIdSet::AtomIdSet(const KeySet &_keyset) :
68 atoms(atomIdSet(_keyset.begin(), _keyset.end()))
69{}
70
71/** Constructor for class AtomIdSet.
72 *
73 * @param _atoms atoms to put into this set
74 */
75AtomIdSet::AtomIdSet(const std::vector<atom *> &_atoms)
76{
77 BOOST_FOREACH(const atom * _atom, _atoms) {
78 insert(_atom->getId());
79 }
80}
81
82/** Constructor for class AtomIdSet.
83 *
84 */
85AtomIdSet::AtomIdSet()
86{}
87
88/** Destructor for class AtomIdSet.
89 *
90 */
91AtomIdSet::~AtomIdSet()
92{}
93
94/** Returns iterator to first atim via a transform_iterator.
95 *
96 * @return iterator to first atom in this set
97 */
98AtomIdSet::iterator AtomIdSet::begin(){
99 return iterator(atoms.begin(), FromIdToAtom());
100}
101
102/** Returns constant iterator to first atim via a transform_iterator.
103 *
104 * @return const iterator to first atom in this set
105 */
106AtomIdSet::const_iterator AtomIdSet::begin() const{
107 return const_iterator(atoms.begin(), FromIdToConstAtom());
108}
109
110/** Returns iterator to one beyond last atom via a transform_iterator.
111 *
112 * @return iterator to one beyond last atom in this set
113 */
114AtomIdSet::iterator AtomIdSet::end(){
115 return iterator(atoms.end(), FromIdToAtom());
116}
117
118/** Returns constant iterator to one beyond last atom via a transform_iterator.
119 *
120 * @return const iterator to one beyond last atom in this set
121 */
122AtomIdSet::const_iterator AtomIdSet::end() const{
123 return const_iterator(atoms.end(), FromIdToConstAtom());
124}
125
126/** Returns true if this set is empty.
127 *
128 * @return true - set is empty, false - there is at least one atom
129 */
130bool AtomIdSet::empty() const
131{
132 return (atoms.empty());
133}
134
135/** Returns the number of members of this set.
136 *
137 * @return number of members in set
138 */
139size_t AtomIdSet::size() const
140{
141 // set has unique members, hence just return its size
142 return atoms.size();
143}
144
145/** Predicate whether given atomic id is contained.
146 *
147 * @param id id to check
148 * @return true - is contained, false - is not
149 */
150bool AtomIdSet::contains(const atomId_t &id) const
151{
152 return (atoms.find(id) != atoms.end());
153}
154
155/** Predicate whether given atom is contained.
156 *
157 * @param key atom to check
158 * @return true - is contained, false - is not
159 */
160bool AtomIdSet::contains(const atom * const key) const
161{
162 return contains(key->getId());
163}
164
165/** Returns the iterator to the atom \a *key.
166 *
167 * @param key atom to find
168 * @return iterator to atom if found, to end() - else
169 */
170AtomIdSet::const_iterator AtomIdSet::find(const atom * const key) const
171{
172 return find(key->getId());
173}
174
175/** Returns the iterator to the atom \a *key.
176 *
177 * @param id atomic id to find
178 * @return iterator to atom if found, to end() - else
179 */
180AtomIdSet::const_iterator AtomIdSet::find(const atomId_t &id) const
181{
182 return const_iterator(atoms.find(id), FromIdToConstAtom());
183}
184
185/** Inserts a given atom into the set.
186 *
187 * @param key atom to insert
188 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
189 */
190std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atom * const key)
191{
192 std::pair<atomIdSet::iterator, bool> iter =
193 atoms.insert(key->getId());
194 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
195
196 return retiter;
197}
198
199/** Inserts a given atom into the set.
200 *
201 * @param id atomic id to insert
202 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
203 */
204std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atomId_t &id)
205{
206 std::pair<atomIdSet::iterator, bool> iter =
207 atoms.insert(id);
208 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
209
210 return retiter;
211}
212
213AtomIdSet::const_iterator AtomIdSet::erase(AtomIdSet::const_iterator &loc)
214{
215 const_iterator iter = loc;
216 ++iter;
217 atom * const _atom = const_cast<atom *>(*loc);
218 atoms.erase( _atom->getId() );
219 return iter;
220}
221
222/** Erase an atom from the list.
223 *
224 * @param *key key to atom in list
225 * @return iterator to just after removed item (compliant with standard)
226 */
227AtomIdSet::const_iterator AtomIdSet::erase(const atom * const key)
228{
229 const_iterator iter = const_cast<const AtomIdSet &>(*this).find(key);
230 if (iter != const_cast<const AtomIdSet &>(*this).end()){
231 ++iter;
232 atoms.erase( key->getId() );
233 }
234 return iter;
235}
236
237/** Erase an atom from the list.
238 *
239 * @param id atomic id atom in list to erase
240 * @return iterator to just after removed item (compliant with standard)
241 */
242AtomIdSet::const_iterator AtomIdSet::erase(const atomId_t &id)
243{
244 atomIdSet::const_iterator iter = atoms.find(id);
245 if (iter != atoms.end()){
246 ++iter;
247 atoms.erase( id );
248 }
249 return const_iterator(iter, FromIdToConstAtom());
250}
Note: See TracBrowser for help on using the repository browser.