[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[fc1b24] | 8 | /*
|
---|
| 9 | * AtomDescriptor.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Feb 5, 2010
|
---|
| 12 | * Author: crueger
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[112b09] | 20 | #include "Helpers/MemDebug.hpp"
|
---|
| 21 |
|
---|
[7a1ce5] | 22 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 23 | #include "Descriptors/AtomDescriptor_impl.hpp"
|
---|
[fc1b24] | 24 |
|
---|
| 25 | #include "World.hpp"
|
---|
[7a1ce5] | 26 | #include "atom.hpp"
|
---|
[b99bf3] | 27 | #include "Patterns/ObservedContainer_impl.hpp"
|
---|
[7a1ce5] | 28 |
|
---|
[fc1b24] | 29 | #include <boost/bind.hpp>
|
---|
[6d574a] | 30 |
|
---|
[7a1ce5] | 31 | #include <iostream>
|
---|
[fc1b24] | 32 |
|
---|
| 33 | using namespace std;
|
---|
| 34 |
|
---|
[4d7462] | 35 | typedef World::AtomSet::internal_iterator atoms_iter_t;
|
---|
[fc1b24] | 36 |
|
---|
[7a1ce5] | 37 | /************************ Forwarding object **************************************/
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | AtomDescriptor::AtomDescriptor(impl_ptr _impl) :
|
---|
| 41 | impl(_impl)
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
| 44 | AtomDescriptor::AtomDescriptor(const AtomDescriptor& src) :
|
---|
| 45 | impl(src.get_impl())
|
---|
| 46 | {}
|
---|
| 47 |
|
---|
| 48 | AtomDescriptor::~AtomDescriptor()
|
---|
| 49 | {}
|
---|
| 50 |
|
---|
| 51 | AtomDescriptor& AtomDescriptor::operator=(AtomDescriptor &src){
|
---|
| 52 | if(&src!=this) {
|
---|
| 53 | impl=src.get_impl();
|
---|
| 54 | }
|
---|
| 55 | return *this;
|
---|
[fc1b24] | 56 | }
|
---|
| 57 |
|
---|
[7a1ce5] | 58 | atom* AtomDescriptor::find(){
|
---|
| 59 | return impl->find();
|
---|
[d1c5e2] | 60 | }
|
---|
| 61 |
|
---|
[7a1ce5] | 62 | std::vector<atom*> AtomDescriptor::findAll(){
|
---|
| 63 | return impl->findAll();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | AtomDescriptor::impl_ptr AtomDescriptor::get_impl() const{
|
---|
| 67 | return impl;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | /**************************** implementation ********************/
|
---|
| 74 |
|
---|
| 75 | AtomDescriptor_impl::AtomDescriptor_impl()
|
---|
[fc1b24] | 76 | {
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[7a1ce5] | 79 | AtomDescriptor_impl::~AtomDescriptor_impl()
|
---|
| 80 | {
|
---|
| 81 | }
|
---|
[fc1b24] | 82 |
|
---|
[7042f45] | 83 | World::AtomSet& AtomDescriptor_impl::getAtoms(){
|
---|
[23b547] | 84 | return World::getInstance().atoms;
|
---|
[fc1b24] | 85 | }
|
---|
| 86 |
|
---|
[7a1ce5] | 87 | atom* AtomDescriptor_impl::find() {
|
---|
[4d7462] | 88 | World::AtomSet &atoms = getAtoms();
|
---|
| 89 | atoms_iter_t res = find_if(atoms.begin_internal(),atoms.end_internal(),boost::bind(&AtomDescriptor_impl::predicate,this,_1));
|
---|
| 90 | return (res!=atoms.end_internal())?((*res).second):0;
|
---|
[fc1b24] | 91 | }
|
---|
| 92 |
|
---|
[7a1ce5] | 93 | vector<atom*> AtomDescriptor_impl::findAll() {
|
---|
[fc1b24] | 94 | vector<atom*> res;
|
---|
[7042f45] | 95 | World::AtomSet atoms = getAtoms();
|
---|
[8cce2b] | 96 | for_each(atoms.begin_internal(),
|
---|
| 97 | atoms.end_internal(),
|
---|
| 98 | boost::bind(&AtomDescriptor_impl::checkAndAdd,
|
---|
| 99 | this,&res,_1));
|
---|
[7a1ce5] | 100 | return res;
|
---|
[fc1b24] | 101 | }
|
---|
[d1c5e2] | 102 |
|
---|
[8cce2b] | 103 | void AtomDescriptor_impl::checkAndAdd(std::vector<atom*> *v,std::pair<atomId_t,atom*> p){
|
---|
| 104 | if(predicate(p)){
|
---|
| 105 | v->push_back(p.second);
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[7a1ce5] | 109 | /************************** Universe and Emptyset *****************/
|
---|
[d1c5e2] | 110 |
|
---|
[7a1ce5] | 111 | AtomAllDescriptor_impl::AtomAllDescriptor_impl()
|
---|
| 112 | {}
|
---|
[d1c5e2] | 113 |
|
---|
[7a1ce5] | 114 | AtomAllDescriptor_impl::~AtomAllDescriptor_impl()
|
---|
| 115 | {}
|
---|
[d1c5e2] | 116 |
|
---|
[24a5e0] | 117 | bool AtomAllDescriptor_impl::predicate(std::pair<atomId_t,atom*>){
|
---|
[7a1ce5] | 118 | return true;
|
---|
[d1c5e2] | 119 | }
|
---|
| 120 |
|
---|
[7a1ce5] | 121 | AtomDescriptor AllAtoms(){
|
---|
| 122 | return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomAllDescriptor_impl));
|
---|
[d1c5e2] | 123 | }
|
---|
| 124 |
|
---|
[7a1ce5] | 125 | AtomNoneDescriptor_impl::AtomNoneDescriptor_impl()
|
---|
| 126 | {}
|
---|
| 127 |
|
---|
| 128 | AtomNoneDescriptor_impl::~AtomNoneDescriptor_impl()
|
---|
| 129 | {}
|
---|
| 130 |
|
---|
[24a5e0] | 131 | bool AtomNoneDescriptor_impl::predicate(std::pair<atomId_t,atom*>){
|
---|
[7a1ce5] | 132 | return false;
|
---|
[d1c5e2] | 133 | }
|
---|
| 134 |
|
---|
[7a1ce5] | 135 | AtomDescriptor NoAtoms(){
|
---|
| 136 | return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomNoneDescriptor_impl));
|
---|
[d1c5e2] | 137 | }
|
---|
| 138 |
|
---|
[7a1ce5] | 139 | /************************** Operator stuff ************************/
|
---|
[d1c5e2] | 140 |
|
---|
[7a1ce5] | 141 | // AND
|
---|
| 142 | AtomAndDescriptor_impl::AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs) :
|
---|
| 143 | lhs(_lhs), rhs(_rhs)
|
---|
| 144 | {}
|
---|
[d1c5e2] | 145 |
|
---|
[7a1ce5] | 146 | AtomAndDescriptor_impl::~AtomAndDescriptor_impl()
|
---|
| 147 | {}
|
---|
[d1c5e2] | 148 |
|
---|
[24a5e0] | 149 | bool AtomAndDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
|
---|
[7a1ce5] | 150 | return lhs->predicate(atom) && rhs->predicate(atom);
|
---|
| 151 | }
|
---|
| 152 | AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
|
---|
| 153 | AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomAndDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
|
---|
| 154 | return AtomDescriptor(newImpl);
|
---|
[d1c5e2] | 155 | }
|
---|
| 156 |
|
---|
[7a1ce5] | 157 | // OR
|
---|
| 158 | AtomOrDescriptor_impl::AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs ,AtomDescriptor::impl_ptr _rhs) :
|
---|
| 159 | lhs(_lhs), rhs(_rhs)
|
---|
| 160 | {}
|
---|
| 161 |
|
---|
| 162 | AtomOrDescriptor_impl::~AtomOrDescriptor_impl(){
|
---|
[d1c5e2] | 163 | }
|
---|
| 164 |
|
---|
[24a5e0] | 165 | bool AtomOrDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
|
---|
[7a1ce5] | 166 | return lhs->predicate(atom) || rhs->predicate(atom);
|
---|
[d1c5e2] | 167 | }
|
---|
| 168 |
|
---|
[7a1ce5] | 169 | AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs){
|
---|
| 170 | AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomOrDescriptor_impl(lhs.get_impl(),rhs.get_impl()));
|
---|
| 171 | return AtomDescriptor(newImpl);
|
---|
[d1c5e2] | 172 | }
|
---|
| 173 |
|
---|
| 174 | // NOT
|
---|
| 175 |
|
---|
[7a1ce5] | 176 | AtomNotDescriptor_impl::AtomNotDescriptor_impl(AtomDescriptor::impl_ptr _arg) :
|
---|
| 177 | arg(_arg)
|
---|
| 178 | {}
|
---|
[d1c5e2] | 179 |
|
---|
| 180 |
|
---|
[7a1ce5] | 181 | AtomNotDescriptor_impl::~AtomNotDescriptor_impl()
|
---|
[d1c5e2] | 182 | {
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[24a5e0] | 185 | bool AtomNotDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
|
---|
[d1c5e2] | 186 | return !(arg->predicate(atom));
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[7a1ce5] | 189 | AtomDescriptor operator!(const AtomDescriptor &arg){
|
---|
| 190 | AtomDescriptor::impl_ptr newImpl = AtomDescriptor::impl_ptr(new AtomNotDescriptor_impl(arg.get_impl()));
|
---|
| 191 | return AtomDescriptor(newImpl);
|
---|
[d1c5e2] | 192 | }
|
---|