/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * MoleculeOrderDescriptor.cpp * * Created on: Dec 7, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "MoleculeOrderDescriptor.hpp" #include "MoleculeOrderDescriptor_impl.hpp" #include "molecule.hpp" using namespace std; MoleculeOrderDescriptor_impl::MoleculeOrderDescriptor_impl(int _id) : id(_id) {} MoleculeOrderDescriptor_impl::~MoleculeOrderDescriptor_impl() {} bool MoleculeOrderDescriptor_impl::predicate(std::pair _molecule) { molecule *mol = find(); return (mol == _molecule.second); } MoleculeDescriptor MoleculeByOrder(int id){ return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeOrderDescriptor_impl(id))); } World::MoleculeSet& MoleculeOrderDescriptor_impl::getMolecules() { return World::getInstance().molecules; } molecule* MoleculeOrderDescriptor_impl::find() { World::MoleculeSet &molecules = getMolecules(); int i=0; molecule *mol = NULL; if (id == 0) { return NULL; } else if (id > 0) { World::MoleculeSet::internal_iterator res = molecules.begin_internal(); for (; res != molecules.end_internal(); ++res) { // when iterator is normal, ++ goes forward! ++i; if (id == i) { mol = res->second; break; } } } else { World::MoleculeSet::reverse_internal_iterator res = molecules.rbegin_internal(); for (; res != molecules.rend_internal(); ++res) { // when iterator is reverse, ++ goes backward! --i; if (id == i) { mol = res->second; break; } } } return mol; } vector MoleculeOrderDescriptor_impl::findAll(){ molecule *res = find(); return (res)?(vector(1,res)):(vector()); }