/** * \file SingletonContainerSet.cpp * \brief A set of SingletonContainers. * * This file is generated by a script (core/tools/make-container). * Do not edit directly. * * Copyright 2007-2010 IMP Inventors. All rights reserved. * */ #include "IMP/container/SingletonContainerSet.h" #include IMPCONTAINER_BEGIN_NAMESPACE namespace { SingletonContainerSet* get_set(SingletonContainer* c) { return dynamic_cast(c); } } SingletonContainerSet ::SingletonContainerSet() { } SingletonContainerSet ::SingletonContainerSet(Model *m, std::string name): SingletonContainer(m, name), deps_(new DependenciesScoreState(this), m){ } namespace { Model *my_get_model(const SingletonContainersTemp &in) { if (in.empty()) { IMP_THROW("Cannot initialize from empty list of containers.", IndexException); } return in[0]->get_model(); } } SingletonContainerSet ::SingletonContainerSet(const SingletonContainersTemp& in, std::string name): SingletonContainer(my_get_model(in), name), deps_(new DependenciesScoreState(this), my_get_model(in)){ set_singleton_containers(in); } bool SingletonContainerSet ::get_contains_particle(Particle* vt) const { for (SingletonContainerConstIterator it= singleton_containers_begin(); it != singleton_containers_end(); ++it) { if ((*it)->get_contains_particle(vt)) return true; } return false; } void SingletonContainerSet::do_show(std::ostream &out) const { IMP_CHECK_OBJECT(this); out << get_number_of_particles() << " containers" << std::endl; } unsigned int SingletonContainerSet::get_number_of_particles() const { unsigned int sum=0; for (SingletonContainerConstIterator it= singleton_containers_begin(); it != singleton_containers_end(); ++it) { sum+= (*it)->get_number_of_particles(); } return sum; } Particle* SingletonContainerSet::get_particle(unsigned int i) const { for (SingletonContainerConstIterator it= singleton_containers_begin(); it != singleton_containers_end(); ++it) { if ( i >= (*it)->get_number_of_particles()) { i-= (*it)->get_number_of_particles(); } else { return (*it)->get_particle(i); } } throw IndexException("out of range"); } IMP_LIST_IMPL(SingletonContainerSet, SingletonContainer, singleton_container, SingletonContainer*, SingletonContainers, { if (get_has_added_and_removed_containers()) { get_set(get_added_container()) ->add_singleton_container(obj ->get_added_container()); } obj->set_was_used(true); },{}, if (container && container->get_has_added_and_removed_containers()) { get_set(container->get_removed_container()) ->add_singleton_container(obj ->get_removed_container()); }); void SingletonContainerSet::apply(const SingletonModifier *sm) { for (unsigned int i=0; i< get_number_of_singleton_containers(); ++i) { get_singleton_container(i)->apply(sm); } } void SingletonContainerSet::apply(const SingletonModifier *sm, DerivativeAccumulator &da) { for (unsigned int i=0; i< get_number_of_singleton_containers(); ++i) { get_singleton_container(i)->apply(sm, da); } } double SingletonContainerSet::evaluate(const SingletonScore *s, DerivativeAccumulator *da) const { double score=0; for (unsigned int i=0; i< get_number_of_singleton_containers(); ++i) { score+=get_singleton_container(i)->evaluate(s, da); } return score; } double SingletonContainerSet::evaluate_change(const SingletonScore *s, DerivativeAccumulator *da) const { double score=0; for (unsigned int i=0; i< get_number_of_singleton_containers(); ++i) { score+=get_singleton_container(i)->evaluate_change(s, da); } return score; } double SingletonContainerSet::evaluate_prechange(const SingletonScore *s, DerivativeAccumulator *da) const { double score=0; for (unsigned int i=0; i< get_number_of_singleton_containers(); ++i) { score+=get_singleton_container(i)->evaluate_prechange(s, da); } return score; } ParticlesTemp SingletonContainerSet::get_contained_particles() const { ParticlesTemp ret; for (unsigned int i=0; i< get_number_of_singleton_containers(); ++i) { ParticlesTemp cur= get_singleton_container(i)->get_contained_particles(); ret.insert(ret.end(), cur.begin(), cur.end()); } return ret; } bool SingletonContainerSet::get_contained_particles_changed() const { for (unsigned int i=0; i< get_number_of_singleton_containers(); ++i) { if (get_singleton_container(i)->get_contained_particles_changed()) { return true; } } return false; } IMPCONTAINER_END_NAMESPACE