/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2011 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))); } 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::const_iterator res = molecules.begin(); for (; res != molecules.end(); ++res) { // when iterator is normal, ++ goes forward! ++i; if (id == i) break; } mol = res->second; } else { World::MoleculeSet::const_reverse_iterator res = molecules.rbegin(); for (; res != molecules.rend(); --res) { // when iterator is reverse, ++ goes backward! --i; if (id == i) break; } mol = res->second; } return mol; } vector MoleculeOrderDescriptor_impl::findAll(){ molecule *res = find(); return (res)?(vector(1,res)):(vector()); }