Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/MpqcParser_Parameters.hpp

    r7f570c rc1db05  
    1414#endif
    1515
     16#include <iosfwd>
    1617#include <list>
    17 #include <map>
     18#include <typeinfo>
    1819#include <vector>
    1920
    2021#include "CodePatterns/Clone.hpp"
    2122#include "CodePatterns/Log.hpp"
     23#include "CodePatterns/Verbose.hpp"
     24
     25#include <boost/any.hpp>
    2226
    2327#include "Parser/FormatParser_Parameters.hpp"
    24 
    25 #include "Parser/Parameters/ContinuousParameter.hpp"
    26 
    27 // specialization for bool (we want "yes/no" not "1/0")
    28 template <> const std::string ContinuousValue<bool>::get() const;
    29 template <> void ContinuousValue<bool>::set(const std::string _value);
    3028
    3129class MpqcParser;
     
    4442  MpqcParser_Parameters();
    4543
     44  /** Copy Constructor of MpqcParser_Parameters.
     45   *
     46   * @param state ref to instance to copy
     47   */
     48  MpqcParser_Parameters(const MpqcParser_Parameters & state);
     49
    4650  /** Destructor of MpqcParser_Parameters.
    4751   *
    4852   */
    4953  virtual ~MpqcParser_Parameters();
     54
     55  /** Enumeration of all known theories.
     56   *
     57   */
     58  enum Theory {
     59    CLHF,       //!< Closed Shell Hartree-Fock equations
     60    CLKS,       //!< Closed Shell Kohn-Sham equations
     61    MBPT2,      //!< Moeller Plesset Perturbation Theory second order
     62    MBPT2_R12,  //!< Moeller Plesset Perturbation Theory second order with R12 integral
     63    unknownTheory //!< designates an unknown theory
     64  };
     65
     66  /** Enumeration of all known integration methods
     67   *
     68   */
     69  enum IntegrationMethod {
     70    IntegralCints,  //!< Integration method Cints in MBPT2 R12?
     71    unknownIntegration //!< designates unknown integration method
     72  };
    5073
    5174  /** Enumeration of all known Parameters to allow placing them in vectors, maps.
     
    6689    unknownParam};   //!< unknownParam, designates an unknown parameter
    6790
    68   /** Enumeration of all known theories.
    69    *
    70    */
    71   enum Theory {
    72     CLHF,       //!< Closed Shell Hartree-Fock equations
    73     CLKS,       //!< Closed Shell Kohn-Sham equations
    74     MBPT2,      //!< Moeller Plesset Perturbation Theory second order
    75     MBPT2_R12,  //!< Moeller Plesset Perturbation Theory second order with R12 integral
    76     unknownTheory //!< designates an unknown theory
    77   };
    78 
    79   /** Enumeration of all known integration methods
    80    *
    81    */
    82   enum IntegrationMethod {
    83     IntegralCints,  //!< Integration method Cints in MBPT2 R12?
    84     unknownIntegration //!< designates unknown integration method
    85   };
    86 
    87   // enum to string getters
    88   const std::string getParameter(const enum Parameters param) const;
    89   void setParameter(const enum Parameters param, const std::string &);
    90   const std::string &getParameterName(const enum Parameters param) const;
    91   const std::string &getTheoryName(const enum Theory theory) const;
    92   const std::string &getIntegrationMethodName(const enum IntegrationMethod integration) const;
     91  bool checkWorldElementsAgainstCurrentBasis() const;
     92
     93  /** Sets the desired level of solving theory to use.
     94   *
     95   * \param _theory shorthand of the theory
     96   */
     97  void setTheory(enum Theory _theory);
     98
     99  /** Sets the desired level of solving integration to use.
     100   *
     101   * \param _integration shorthand of the integration
     102   */
     103  void setIntegration(enum IntegrationMethod _integration);
     104
     105  /** Getter for integration method in params.
     106   *
     107   * @return enumeration index of IntegrationMethod.
     108   */
     109  enum IntegrationMethod getIntegration() const;
     110
     111  /** Getter for current Theory in params.
     112   *
     113   * @return enumeration index of Theory
     114   */
     115  enum Theory getTheory() const;
     116
     117  /** Getter for a parameter in params as a string.
     118   *
     119   * @param _param enumeration index of desired Parameter
     120   * @return string value
     121   */
     122  std::string getString(enum Parameters _param) const;
     123
     124  /** Getter for integer value of desired Parameter in params.
     125   *
     126   * Only if type in params matches int!
     127   *
     128   * @param _param enumeration index in Parameter
     129   * @return integer value of parameter
     130   */
     131  int getInt(enum Parameters _param) const;
     132
     133  /** Getter for double value of desired Parameter in params.
     134   *
     135   * Only if type in params matches double!
     136   *
     137   * @param _param enumeration index in Parameter
     138   * @return double value of parameter
     139   */
     140  double getDouble(enum Parameters _param) const;
     141
     142  /** Getter for bool value of desired Parameter in params.
     143   *
     144   * Only if type in params matches bool!
     145   *
     146   * @param _param enumeration index in Parameter
     147   * @return bool value of parameter
     148   */
     149  bool getBool(enum Parameters _param) const;
     150
     151  /** Setter for a desired value of its type is known.
     152   *
     153   * We check whether given type matches present type in params.
     154   *
     155   * @param _param enumeration index of Parameter
     156   * @param _desired desired value to set to
     157   * @return true - type match, value set, false - type mismatch
     158   */
     159  template <class T> bool setter(enum Parameters _param, T _desired) {
     160    if (typeid(T) == params[_param].type()) {
     161      params[_param] = _desired;
     162      return true;
     163    } else
     164      return false;
     165  }
     166
     167  /** Sets a desired value in the params from a string.
     168   *
     169   * This is due to strict typing of C++ very ugly and boost::any does not make
     170   * it any better because it offers to functions to use values directly from
     171   * stringstream. Probably, because value is unknown to is as well and hence
     172   * the author could not implement it beautifully, so he dropped it altogether.
     173   * Grrr ....
     174   *
     175   * @param _param param to set
     176   * @param _desired stringstream containing value as next argument
     177   * @return true - type ok, false - unknown type in params.
     178   */
     179  bool setter(enum Parameters _param, std::stringstream& _desired);
     180
     181  /** Grants access to ParamLookup.
     182   *
     183   *  Does not check for unknown parameter.
     184   *
     185   * @param _name name of parameter
     186   * @return enumeration index of Parameters
     187   */
     188  enum Parameters getParam(std::string _name) const;
     189
     190  /** Checker whether parameter with name is known.
     191   *
     192   * @param _name
     193   * @return true - parameter known, false - parameter unknown
     194   */
     195  bool haveParam(std::string _name) const;
     196
     197  /** Creates a clone of the class.
     198   *
     199   * @return
     200   */
     201  FormatParser_Parameters* clone() const;
     202
     203  /** Applies a before returned undo state.
     204   *
     205   * @param undo state to set
     206   */
     207  void makeClone(const FormatParser_Parameters & _state);
     208
     209  /** Set the internal parameters to the one's from the given \a state.
     210   *
     211   * @param state set of parameters
     212   */
     213  void copyParameters(const MpqcParser_Parameters & state);
    93214
    94215private:
    95 
    96 
    97   //!> vector with all available theories in same order as enum Theory.
    98   std::vector<std::string> ValidTheories;
    99 
    100   //!> vector with all available integration methods in same order as enum IntegrationMethod.
    101   std::vector<std::string> ValidIntegrationMethods;
    102 
    103   bool checkWorldElementsAgainstCurrentBasis() const;
    104 
    105216  /** Global initialization in cstor.
    106217   *
     
    113224  void initBasis();
    114225
    115   //!> vector with all parameter names in same order as enum Parameters
    116   std::vector<std::string> ParamNames;
    117 
    118   //!> typedef for the list of all available basis sets
     226  /** Initializes params.
     227   * Sets the type and the associated enumeration index.
     228   */
     229  void initParameters();
     230
     231  /** Internal function used by initParameters() to add parameters to params.
     232   *
     233   * @param _enum enumeration index to set
     234   * @param _p (default) value to set with certain type
     235   */
     236  template <class T> void appendParameter(enum Parameters _enum, T _p) {
     237    boost::any _p_value = _p;
     238    params[_enum] = _p_value;
     239  }
     240
     241  // all internal typedefs for lists below
    119242  typedef std::map<std::string, std::list<std::string> > BasisMapType;
    120 
    121   //!> list of all basis along with their present element parametrization
     243  typedef std::map<enum Theory, std::string> TheoryNamesType;
     244  typedef std::map<std::string, enum Theory> TheoryLookupType;
     245  typedef std::map<enum IntegrationMethod, std::string> IntegrationNamesType;
     246  typedef std::map<std::string, enum IntegrationMethod> IntegrationLookupType;
     247  typedef std::map<enum Parameters, std::string> ParamNamesType;
     248  typedef std::map<std::string, enum Parameters> ParamLookupType;
     249  typedef std::map<enum Parameters, boost::any> parameterlist;
     250
     251  //!> boost::any container for all the parameters
     252  parameterlist params;
     253
     254  // maps from names to enumerations
     255
     256  //!> contains basis and all elements the basis knows about
    122257  BasisMapType BasisList;
     258  //!> contains the name of a theory as string
     259  TheoryNamesType TheoryNames;
     260  //!> contains a lookup from theory name to enumeration index
     261  TheoryLookupType TheoryLookup;
     262  //!> contains the name of an integration method as string
     263  IntegrationNamesType IntegrationNames;
     264  //!> contains a lookup from integration method name to enumeration index
     265  IntegrationLookupType IntegrationLookup;
     266  //!> contains the name of a parameter
     267  ParamNamesType ParamNames;
     268  //!> contains a lookup from parameter name to enumeration index
     269  ParamLookupType ParamLookup;
    123270};
    124271
     272/** Output operator for the contents of MpqcParser_Parameters::params.
     273 *
     274 * @param ost output stream
     275 * @param params reference to MpqcParser_Parameters containing params.
     276 * @return reference to output stream for concatenation
     277 */
     278std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params);
     279
     280/** Input operator for a list of parameters to place into \a params.
     281 *
     282 * @param ist input stream
     283 * @param params parameters to parse into
     284 * @return input stream for concatenation
     285 */
     286std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params);
     287
    125288#endif /* MPQCPARSER_PARAMETERS_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.