/* * SerializablePotential.hpp * * Created on: 23.11.2012 * Author: heber */ #ifndef SERIALIZABLEPOTENTIAL_HPP_ #define SERIALIZABLEPOTENTIAL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include /** SerializablePotential is a potential that can be parsed from and stored to * a .potentials file. * * All required functionality for printing and parsing the set of parameters * is set as virtual functions and have to be implemented specifically, e.g. * -# ParameterNames: Should be static instance as are the same over each * potential type despite although there may be more than one instance. * \note If the parameter name is left empty, the value is neither printed * nor parsed. This may be issued to skip internal parameters (e.g. offset). * -# ParticleTypes: has been implemented here, as is different per instance. * * Specifically, what you need to do when inheriting is: * -# implement getParameters() and setParameters() * -# have some static const ParameterNames_t in your class and implement * getParameterNames() as a getter for it (or any other way you prefer). * The static instance can be easily initialized via boost::assign::list_of. * */ class SerializablePotential { public: //!> typedef for particle designation typedef int ParticleType_t; //!> typedef for a vector of particle designations typedef std::vector ParticleTypes_t; //!> typedef for a vector of parameter names typedef std::vector ParameterNames_t; //!> typedef for a single parameter degree of freedom of the function typedef double parameter_t; //!> typedef for the whole set of parameters of the function typedef std::vector parameters_t; public: SerializablePotential(const ParticleTypes_t &_ParticleTypes) : ParticleTypes(_ParticleTypes) {} virtual ~SerializablePotential() {} /** Return the token name of this specific potential. * * \return token name of the potential */ virtual const std::string& getToken() const=0; /** Return the name of this specific potential. * * This is required for storage in a Registry. The name is the token name * followed by "_" and the particle types to make it unique. * * \return name of the potential */ const std::string getName() const; /** Getter for the parameters of this model function. * * \return current set of parameters of the model function */ virtual parameters_t getParameters() const=0; /** Getter for the number of parameters of this model function. * * \return number of parameters */ virtual size_t getParameterDimension() const=0; /** Returns a vector of particle designations. * * These designations denote the particle types for which this potential * has been parametrized. * * \return vector of particle type */ const ParticleTypes_t& getParticleTypes() const { return ParticleTypes; } /** Returns a vector of parameter names. * * This is required from the specific implementation * * \return vector of strings containing parameter names */ virtual const ParameterNames_t& getParameterNames() const=0; /** Returns the index associated to a specific parameter \a _name. * * \param _name parameter name to look up index for * \return index to the given \a _name or (size_t)-1 if none found */ const size_t getParameterIndex(const std::string &_name) const; /** Print parameters to given stream \a ost. * * These are virtual functions to allow for overriding and hence * changing the default behavior. * * @param ost stream to print to */ virtual void stream_to(std::ostream &ost) const; /** Parse parameters from given stream \a ist. * * These are virtual functions to allow for overriding and hence * changing the default behavior. * * @param ist stream to parse from */ virtual void stream_from(std::istream &ist); protected: /** Setter for the parameters of the model function. * * \param params set of parameters to set */ virtual void setParameters(const parameters_t ¶ms)=0; /** Setter for a given particle type. * * \param index index of type to set * \param _designation type to set to */ void setParticleType(const size_t index, const ParticleType_t& _designation) { if (ParticleTypes.size() <= index) const_cast(ParticleTypes).resize(index+1); const_cast(ParticleTypes)[index] = _designation; } protected: /** Default constructor for class EmpiricalPotential. * * Callable only by derived functions. * */ SerializablePotential(); private: //!> static definition of the particle types for this potential const ParticleTypes_t ParticleTypes; }; /** Output operations stores .potentials line containing these parameters * coefficients and designations. * * \param ost output stream to print to * \param potential potential whose coefficients to print * \return output stream for concatenation */ std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential); /** Input operation parses coefficients from a given line of a .potentials * file. * * \param ist input stream to parse from * \param potential potential to set * \return input stream for concatenation */ std::istream& operator>>(std::istream &ist, SerializablePotential &potential); #endif /* SERIALIZABLEPOTENTIAL_HPP_ */