/** * \file CLASSNAMEModifier.h \brief A Modifier on PLURALVARIABLETYPE * * This file is generated by a script (core/tools/make-container). * Do not edit directly. * * Copyright 2007-2010 IMP Inventors. All rights reserved. */ #ifndef IMP_HEADERNAME_MODIFIER_H #define IMP_HEADERNAME_MODIFIER_H #include "kernel_config.h" #include "DerivativeAccumulator.h" #include "base_types.h" #include "ParticleTuple.h" IMP_BEGIN_NAMESPACE // to keep swig happy class Particle; //! A base class for modifiers of PLURALVARIABLETYPE /** The primary function of such a class is to change the passed particles. A given CLASSNAMEModifier may only work when passed a DerivativeAccumulator or when not passed one. \see IMP::CLASSNAMEFunctor Implementors should see IMP_HEADERNAME_MODIFIER() and IMP_HEADERNAME_MODIFIER_DA(). */ class IMPEXPORT CLASSNAMEModifier : public Object { public: typedef VARIABLETYPE Argument; CLASSNAMEModifier(std::string name="CLASSNAMEModifier %1%"); /** Apply the function to a single value*/ virtual void apply(ARGUMENTTYPE, DerivativeAccumulator &) const { IMP_FAILURE("This CLASSNAMEModifier must be called without a" << " DerivativeAccumulator."); } /** Apply the function to a single value*/ virtual void apply(ARGUMENTTYPE) const { IMP_FAILURE("This CLASSNAMEModifier must be called with a" << " DerivativeAccumulator."); } /** Apply the function to a collection of PLURALVARIABLETYPE */ virtual void apply(const PLURALVARIABLETYPE &) const { IMP_FAILURE("This CLASSNAMEModifier must be called with a" << " DerivativeAccumulator."); } /** Apply the function to a collection of PLURALVARIABLETYPE */ virtual void apply(const PLURALVARIABLETYPE &, DerivativeAccumulator &) const { IMP_FAILURE("This CLASSNAMEModifier must be called without a" << " DerivativeAccumulator."); } /** Get the set of particles read when applied to the arguments.*/ virtual ParticlesTemp get_input_particles(Particle* p) const =0; /** Get the set of particles modifier when applied to the arguments.*/ virtual ParticlesTemp get_output_particles(Particle *p) const =0; /** Get the set of input containers when this modifier is applied to the arguments. */ virtual ContainersTemp get_input_containers(Particle *p) const =0; /** Get the set of output containers when this modifier is applied to the arguments. */ virtual ContainersTemp get_output_containers(Particle *p) const =0; }; IMP_OUTPUT_OPERATOR(CLASSNAMEModifier); IMP_OBJECTS(CLASSNAMEModifier,CLASSNAMEModifiers); //! Create a functor which can be used with build in C++ and python commands /** For example, you can do \code std::for_each(particles.begin(), particles.end(), IMP::SingletonFunctor(new IMP::core::Transform(tr))); IMP::for_each(particles, IMP::SingletonFunctor(new IMP::core::Transform(tr))); \endcode in C++ (the second can be used with when \c particles is a temporary value) or \verbatim map(SingletonFunctor(Transform(tr)), particles) \endverbatim in python. \see IMP::CLASSNAMEModifier */ class CLASSNAMEFunctor { Pointer f_; DerivativeAccumulator *da_; public: //! Store the CLASSNAMEModifier and the optional DerivativeAccumulator CLASSNAMEFunctor(const CLASSNAMEModifier *f): f_(f), da_(NULL){} CLASSNAMEFunctor(const CLASSNAMEModifier *f, DerivativeAccumulator *da): f_(f), da_(da){ IMP_USAGE_CHECK(da_, "The passed derivative accumulator should not be null."); } void operator()( VARIABLETYPE p) const { if (da_) { f_->apply(p, *da_); } else { f_->apply(p); } } }; IMP_END_NAMESPACE #endif /* IMP_HEADERNAME_MODIFIER_H */