Changeset 7f570c for src


Ignore:
Timestamp:
Oct 17, 2011, 4:56:37 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
032f31
Parents:
f758dd
git-author:
Frederik Heber <heber@…> (10/06/11 11:12:35)
git-committer:
Frederik Heber <heber@…> (10/17/11 16:56:37)
Message:

Moved operator<<() and operator>>() from Mpqc/Psi3Parser_Parameters into FormatParser_Parameters.

  • setting and getting of values are generalized.
Location:
src/Parser
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParser_Parameters.cpp

    rf758dd r7f570c  
    2020#include "CodePatterns/MemDebug.hpp"
    2121
     22#include <iostream>
     23#include <boost/algorithm/string.hpp>
     24#include <boost/tokenizer.hpp>
     25#include <sstream>
    2226#include <string>
     27
     28#include "CodePatterns/Assert.hpp"
     29#include "CodePatterns/Log.hpp"
    2330
    2431#include "Parameters/Parameter.hpp"
     
    106113  return storage->getByName(_name);
    107114}
     115
     116/** Output operator for the contents of FormatParser_Parameters::params.
     117 *
     118 * @param ost output stream
     119 * @param params reference to FormatParser_Parameters containing params.
     120 * @return reference to output stream for concatenation
     121 */
     122std::ostream & operator << (std::ostream& ost, const FormatParser_Parameters &params)
     123{
     124  // this is ugly, but with boost::any to safeguard const-ness is plain impossible
     125  std::ostringstream output;
     126  ASSERT(params.storage != NULL,
     127      "operator<<(FormatParser_Parameters) - storage is NULL.");
     128  for (ParameterStorage::const_iterator iter = params.storage->getBeginIter();
     129      iter != params.storage->getEndIter();
     130      ++iter)
     131    output << iter->first
     132           <<  "=" << iter->second->get() << ";";
     133  ost << output.str();
     134  return ost;
     135}
     136
     137/** Input operator for a list of parameters to place into \a params.
     138 *
     139 * @param ist input stream
     140 * @param params parameters to parse into
     141 * @return input stream for concatenation
     142 */
     143std::istream & operator >> (std::istream& ist, FormatParser_Parameters &params)
     144{
     145  typedef boost::tokenizer<boost::char_separator<char> >
     146      tokenizer;
     147  boost::char_separator<char> semicolonsep(";");
     148  boost::char_separator<char> equalitysep("=");
     149  boost::char_separator<char> ticksep("\"");
     150  std::string line;
     151  std::getline( ist, line );
     152  //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl);
     153  tokenizer tokens(line, semicolonsep);
     154  ASSERT(tokens.begin() != tokens.end(),
     155      "operator<< on FormatParser_Parameters - empty string, need at least ';' in line "+line+"!");
     156  for (tokenizer::iterator tok_iter = tokens.begin();
     157        tok_iter != tokens.end(); ++tok_iter) {
     158    //LOG(2, "INFO: (key,value) pair is: " << *tok_iter << ".");
     159    tokenizer paramtokens(*tok_iter, equalitysep);
     160    if (paramtokens.begin() != paramtokens.end()) {
     161      tokenizer::iterator tok_paramiter = paramtokens.begin();
     162      tokenizer::iterator tok_valueiter = tok_paramiter;
     163      tokenizer::iterator tok_checkiter = ++tok_valueiter;
     164      ++tok_checkiter;
     165      LOG(3, "INFO: key is '" << *tok_paramiter << "', value is '" << *tok_valueiter << "'.");
     166      // TODO: throw exception instead of ASSERT
     167      ASSERT(tok_paramiter != paramtokens.end(),
     168          "operator<< on FormatParser_Parameters - missing value before ' =' in token "+*tok_iter+"!");
     169      ASSERT(tok_valueiter != paramtokens.end(),
     170          "operator<< on FormatParser_Parameters - missing value after ' =' in token "+*tok_iter+"!");
     171      ASSERT(tok_checkiter == paramtokens.end(),
     172          "operator<< on FormatParser_Parameters - still more tokens after ' =' in token "+*tok_iter+":"
     173          +*tok_checkiter+"!");
     174      std::string key(*tok_paramiter);
     175      std::string value(*tok_valueiter);
     176      boost::trim(key);
     177      boost::trim(value);
     178      tokenizer ticklesstokens(value, ticksep);
     179      ASSERT(ticklesstokens.begin() != ticklesstokens.end(),
     180          "operator<< on FormatParser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!");
     181      std::stringstream valuestream(*(ticklesstokens.begin()));
     182      //LOG(2, "INFO: Token pair is " << key << "," << valuestream.str());
     183
     184      // TODO: throw exception instead of DoeLog()
     185      ASSERT(params.haveParameter(key),
     186          "operator >> on FormatParser_Parameters - unknown parameter name '"
     187          +key+"' with value "+valuestream.str()+"!");
     188      if (params.haveParameter(key)) {
     189        Parameter *instance = params.getParameter(key);
     190        instance->set(valuestream.str());
     191      }
     192    } else {
     193      ist.setstate(std::ios::eofbit);
     194    }
     195  }
     196  return ist;
     197}
  • src/Parser/FormatParser_Parameters.hpp

    rf758dd r7f570c  
    1414#endif
    1515
     16#include <iosfwd>
     17
    1618#include "CodePatterns/Clone.hpp"
    1719
     
    2729class FormatParser_Parameters : public Clone<FormatParser_Parameters>
    2830{
     31  //!> allow operator access to storage for easier printing.
     32  friend std::ostream & operator << (std::ostream& ost, const FormatParser_Parameters &params);
    2933public:
    3034  FormatParser_Parameters();
     
    4549};
    4650
     51std::ostream & operator << (std::ostream& ost, const FormatParser_Parameters &params);
     52
     53std::istream & operator >> (std::istream& ist, FormatParser_Parameters &params);
     54
    4755
    4856#endif /* FORMATPARSER_PARAMETERS_HPP_ */
  • src/Parser/MpqcParser_Parameters.cpp

    rf758dd r7f570c  
    1818#endif
    1919
    20 #include <iostream>
    21 #include <boost/tokenizer.hpp>
     20#include "CodePatterns/MemDebug.hpp"
     21
    2222#include <string>
    23 
    24 #include "CodePatterns/MemDebug.hpp"
    2523
    2624#include "CodePatterns/Log.hpp"
    2725
    2826#include "MpqcParser.hpp"
    29 
    3027#include "MpqcParser_Parameters.hpp"
    3128
     
    182179}
    183180
    184 
    185 /** Output operator for the contents of MpqcParser_Parameters::params.
    186  *
    187  * @param ost output stream
    188  * @param params reference to MpqcParser_Parameters containing params.
    189  * @return reference to output stream for concatenation
    190  */
    191 std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params)
    192 {
    193   // this is ugly, but with boost::any to safeguard const-ness is plain impossible
    194   std::ostringstream output;
    195   for (size_t param = (enum MpqcParser_Parameters::Parameters)0;
    196       param < (size_t)MpqcParser_Parameters::unknownParam; ++param)
    197     output << params.getParameterName((enum MpqcParser_Parameters::Parameters)param)
    198            <<  "=" << params.getParameter((enum MpqcParser_Parameters::Parameters)param) << ";";
    199   ost << output.str();
    200   return ost;
    201 }
    202 
    203 /** Input operator for a list of parameters to place into \a params.
    204  *
    205  * @param ist input stream
    206  * @param params parameters to parse into
    207  * @return input stream for concatenation
    208  */
    209 std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params)
    210 {
    211   typedef boost::tokenizer<boost::char_separator<char> >
    212       tokenizer;
    213   boost::char_separator<char> semicolonsep(";");
    214   boost::char_separator<char> equalitysep(" =");
    215   boost::char_separator<char> ticksep("\"");
    216   std::string line;
    217   std::getline( ist, line );
    218   //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl);
    219   tokenizer tokens(line, semicolonsep);
    220   ASSERT(tokens.begin() != tokens.end(),
    221       "operator<< on MpqcParser_Parameters - empty string, need at least ';' in line "+line+"!");
    222   for (tokenizer::iterator tok_iter = tokens.begin();
    223         tok_iter != tokens.end(); ++tok_iter) {
    224     tokenizer paramtokens(*tok_iter, equalitysep);
    225     if (paramtokens.begin() != paramtokens.end()) {
    226       tokenizer::iterator tok_paramiter = paramtokens.begin();
    227       tokenizer::iterator tok_valueiter = tok_paramiter;
    228       tokenizer::iterator tok_checkiter = ++tok_valueiter;
    229       ++tok_checkiter;
    230       // TODO: throw exception instead of ASSERT
    231       ASSERT(tok_paramiter != paramtokens.end(),
    232           "operator<< on MpqcParser_Parameters - missing value before ' =' in token "+*tok_iter+"!");
    233       ASSERT(tok_valueiter != paramtokens.end(),
    234           "operator<< on MpqcParser_Parameters - missing value after ' =' in token "+*tok_iter+"!");
    235       ASSERT(tok_checkiter == paramtokens.end(),
    236           "operator<< on MpqcParser_Parameters - still more tokens after ' =' in token "+*tok_iter+":"
    237           +*tok_checkiter+"!");
    238       std::stringstream keystream(*tok_paramiter);
    239       std::string key;
    240       keystream >> ws >> key;
    241       tokenizer ticklesstokens(*tok_valueiter, ticksep);
    242       ASSERT(ticklesstokens.begin() != ticklesstokens.end(),
    243           "operator<< on MpqcParser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!");
    244       std::stringstream valuestream(*(ticklesstokens.begin()));
    245       DoLog(2) && (Log() << Verbose(2)
    246           << "INFO: Token pair is " << key << "," << valuestream.str() << std::endl);
    247 
    248       // TODO: throw exception instead of DoeLog()
    249       ASSERT(params.haveParameter(key),
    250           "operator >> on MpqcParser_Parameters - unknown parameter name '"
    251           +key+"' with value "+valuestream.str()+"!");
    252       if (params.haveParameter(key)) {
    253         Parameter *instance = params.FormatParser_Parameters::getParameter(key);
    254         instance->set(valuestream.str());
    255       }
    256     } else {
    257       ist.setstate(std::ios::eofbit);
    258     }
    259   }
    260   return ist;
    261 }
    262 
    263181/** Checks whether all elements in the world also have parameters in the basis.
    264182 *
  • src/Parser/MpqcParser_Parameters.hpp

    rf758dd r7f570c  
    1414#endif
    1515
    16 #include <iosfwd>
    1716#include <list>
    1817#include <map>
     
    124123};
    125124
    126 std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params);
    127 
    128 std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params);
    129 
    130125#endif /* MPQCPARSER_PARAMETERS_HPP_ */
  • src/Parser/Psi3Parser_Parameters.cpp

    rf758dd r7f570c  
    1818#endif
    1919
    20 #include <iostream>
    21 #include <boost/tokenizer.hpp>
     20#include "CodePatterns/MemDebug.hpp"
     21
    2222#include <string>
    2323
    24 #include "CodePatterns/MemDebug.hpp"
    25 
     24#include "CodePatterns/Assert.hpp"
    2625#include "CodePatterns/Log.hpp"
    2726
     
    254253}
    255254
    256 ///** Getter for name of a specific Parameter.
    257 // *
    258 // * @param param index among enum Theory
    259 // * @return name of the desired Theory
    260 // */
    261 //const std::string &Psi3Parser_Parameters::getTheoryName(const enum Theory theory) const
    262 //{
    263 //  return ValidTheories[theory];
    264 //}
    265 //
    266 ///** Getter for the name of specific of IntegrationMethod.
    267 // *
    268 // * @param param index among enum IntegrationMethod
    269 // * @return value of the desired IntegrationMethod
    270 // */
    271 //const std::string &Psi3Parser_Parameters::getIntegrationMethodName(const enum IntegrationMethod integration) const
    272 //{
    273 //  return ValidIntegrationMethods[integration];
    274 //}
    275 
    276 
    277 /** Output operator for the contents of Psi3Parser_Parameters::params.
    278  *
    279  * @param ost output stream
    280  * @param params reference to Psi3Parser_Parameters containing params.
    281  * @return reference to output stream for concatenation
    282  */
    283 std::ostream & operator << (std::ostream& ost, const Psi3Parser_Parameters &params)
    284 {
    285   // this is ugly, but with boost::any to safeguard const-ness is plain impossible
    286   std::ostringstream output;
    287   for (size_t param = (enum Psi3Parser_Parameters::Parameters)0;
    288       param < (size_t)Psi3Parser_Parameters::unknownParam; ++param)
    289     output << params.getParameterName((enum Psi3Parser_Parameters::Parameters)param)
    290            <<  "=" << params.getParameter((enum Psi3Parser_Parameters::Parameters)param) << ";";
    291   ost << output.str();
    292   return ost;
    293 }
    294 
    295 /** Input operator for a list of parameters to place into \a params.
    296  *
    297  * @param ist input stream
    298  * @param params parameters to parse into
    299  * @return input stream for concatenation
    300  */
    301 std::istream & operator >> (std::istream& ist, Psi3Parser_Parameters &params)
    302 {
    303   typedef boost::tokenizer<boost::char_separator<char> >
    304       tokenizer;
    305   boost::char_separator<char> semicolonsep(";");
    306   boost::char_separator<char> equalitysep(" =");
    307   boost::char_separator<char> ticksep("\"");
    308   std::string line;
    309   std::getline( ist, line );
    310   //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl);
    311   tokenizer tokens(line, semicolonsep);
    312   ASSERT(tokens.begin() != tokens.end(),
    313       "operator<< on Psi3Parser_Parameters - empty string, need at least ';' in line "+line+"!");
    314   for (tokenizer::iterator tok_iter = tokens.begin();
    315         tok_iter != tokens.end(); ++tok_iter) {
    316     tokenizer paramtokens(*tok_iter, equalitysep);
    317     if (paramtokens.begin() != paramtokens.end()) {
    318       tokenizer::iterator tok_paramiter = paramtokens.begin();
    319       tokenizer::iterator tok_valueiter = tok_paramiter;
    320       tokenizer::iterator tok_checkiter = ++tok_valueiter;
    321       ++tok_checkiter;
    322       // TODO: throw exception instead of ASSERT
    323       ASSERT(tok_paramiter != paramtokens.end(),
    324           "operator<< on Psi3Parser_Parameters - missing value before ' =' in token "+*tok_iter+"!");
    325       ASSERT(tok_valueiter != paramtokens.end(),
    326           "operator<< on Psi3Parser_Parameters - missing value after ' =' in token "+*tok_iter+"!");
    327       ASSERT(tok_checkiter == paramtokens.end(),
    328           "operator<< on Psi3Parser_Parameters - still more tokens after ' =' in token "+*tok_iter+":"
    329           +*tok_checkiter+"!");
    330       std::stringstream keystream(*tok_paramiter);
    331       std::string key;
    332       keystream >> ws >> key;
    333       tokenizer ticklesstokens(*tok_valueiter, ticksep);
    334       ASSERT(ticklesstokens.begin() != ticklesstokens.end(),
    335           "operator<< on Psi3Parser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!");
    336       std::stringstream valuestream(*(ticklesstokens.begin()));
    337       DoLog(2) && (Log() << Verbose(2)
    338           << "INFO: Token pair is " << key << "," << valuestream.str() << std::endl);
    339 
    340       // TODO: throw exception instead of DoeLog()
    341       ASSERT(params.haveParameter(key),
    342           "operator >> on Psi3Parser_Parameters - unknown parameter name '"
    343           +key+"' with value "+valuestream.str()+"!");
    344       if (params.haveParameter(key)) {
    345         Parameter *instance = params.FormatParser_Parameters::getParameter(key);
    346         instance->set(valuestream.str());
    347       }
    348     } else {
    349       ist.setstate(std::ios::eofbit);
    350     }
    351   }
    352   return ist;
    353 }
    354 
    355255/** Checks whether all elements in the world also have parameters in the basis.
    356256 *
  • src/Parser/Psi3Parser_Parameters.hpp

    rf758dd r7f570c  
    1414#endif
    1515
    16 #include <iosfwd>
    1716#include <list>
    1817#include <map>
     
    2019
    2120#include "CodePatterns/Clone.hpp"
    22 #include "CodePatterns/Log.hpp"
    2321
    2422#include "Parser/FormatParser_Parameters.hpp"
     
    208206};
    209207
    210 std::ostream & operator << (std::ostream& ost, const Psi3Parser_Parameters &params);
    211 
    212 std::istream & operator >> (std::istream& ist, Psi3Parser_Parameters &params);
    213 
    214208#endif /* PSI3PARSER_PARAMETERS_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.