source: molecuilder/src/Descriptors/AtomIdDescriptor.cpp@ 3db67e

Last change on this file since 3db67e was e7e088, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Added Descriptor that allows querying of atoms by their type

  • Property mode set to 100644
File size: 838 bytes
RevLine 
[86b917]1/*
2 * AtomIdDescriptor.cpp
3 *
4 * Created on: Feb 5, 2010
5 * Author: crueger
6 */
7
8#include "AtomIdDescriptor.hpp"
[323177]9#include "AtomIdDescriptor_impl.hpp"
[86b917]10
11#include "atom.hpp"
12
13using namespace std;
14
[323177]15
16AtomIdDescriptor_impl::AtomIdDescriptor_impl(int _id) :
[86b917]17 id(_id)
18{}
19
[323177]20AtomIdDescriptor_impl::~AtomIdDescriptor_impl()
[86b917]21{}
22
[323177]23bool AtomIdDescriptor_impl::predicate(std::pair<int,atom*> atom) {
[e7e088]24 return atom.first==id;
[973c03]25}
26
[323177]27AtomDescriptor AtomById(int id){
28 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomIdDescriptor_impl(id)));
[973c03]29}
30
[e7e088]31atom *AtomIdDescriptor_impl::find(){
[86b917]32 map<int,atom*> atoms = getAtoms();
33 map<int,atom*>::iterator res = atoms.find(id);
34 return (res!=atoms.end())?((*res).second):0;
35}
36
[e7e088]37vector<atom*> AtomIdDescriptor_impl::findAll(){
[86b917]38 atom *res = find();
39 return (res)?(vector<atom*>(1,res)):(vector<atom*>());
40}
Note: See TracBrowser for help on using the repository browser.