Ignore:
Timestamp:
Feb 27, 2013, 12:43:29 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, Candidate_v1.7.0, 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:
da2d5c
Parents:
dbcc47
git-author:
Frederik Heber <heber@…> (12/18/12 12:39:10)
git-committer:
Frederik Heber <heber@…> (02/27/13 12:43:29)
Message:

Added virtual stream_to/from functions to SerializablePotential.

  • this allows overriding in SaturationPotential and hence printing/parsing of both contained types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/SerializablePotential.cpp

    rdbcc47 r3d2559  
    5151std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential)
    5252{
     53  potential.stream_to(ost);
     54  return ost;
     55}
     56
     57void SerializablePotential::stream_to(std::ostream &ost) const
     58{
    5359  // check stream
    5460  if (ost.bad())
     
    5662
    5763  /// print parameter key
    58   ost << potential.getToken() << ":";
     64  ost << getToken() << ":";
    5965  /// print associated particles
    60   const SerializablePotential::ParticleTypes_t &types = potential.getParticleTypes();
     66  const SerializablePotential::ParticleTypes_t &types = getParticleTypes();
    6167  for (size_t index=0; index < types.size(); ++index) {
    6268    ost << "\tparticle_type" << index+1 << "=" << types[index];
     
    6470  }
    6571  /// print coefficients
    66   const SerializablePotential::ParameterNames_t &paramNames = potential.getParameterNames();
    67   const SerializablePotential::parameters_t &params = potential.getParameters();
     72  const SerializablePotential::ParameterNames_t &paramNames = getParameterNames();
     73  const SerializablePotential::parameters_t &params = getParameters();
    6874  SerializablePotential::ParameterNames_t::const_iterator nameiter = paramNames.begin();
    6975  SerializablePotential::parameters_t::const_iterator valueiter = params.begin();
     
    7682  /// print terminating semi-colon
    7783  ost << ";";
    78   return ost;
    7984}
    8085
    8186std::istream& operator>>(std::istream &ist, SerializablePotential &potential)
     87{
     88  potential.stream_from(ist);
     89  return ist;
     90}
     91
     92void SerializablePotential::stream_from(std::istream &ist)
    8293{
    8394  // check stream
     
    8697
    8798  // create copy of current parameters, hence line may contain not all required
    88   SerializablePotential::parameters_t params(potential.getParameters());
     99  SerializablePotential::parameters_t params(getParameters());
    89100
    90101  // read in full line
     
    95106  const size_t colonpos = linestring.find(":");
    96107  if ((strBegin == std::string::npos) || (colonpos == std::string::npos) ||
    97       (linestring.substr(strBegin, colonpos-1) != potential.getToken()))
     108      (linestring.substr(strBegin, colonpos-1) != getToken()))
    98109    throw SerializablePotentialMissingValueException()
    99         << SerializablePotentialKey(potential.getName());
     110        << SerializablePotentialKey(getName());
    100111
    101112  // tokenize by ","
     
    130141        throw SerializablePotentialMissingValueException() << SerializablePotentialKey(key);
    131142      const std::string &value = *keyvalue_iter;
    132       potential.setParticleType(index, ConvertToParticleType(value));
     143      setParticleType(index, ConvertToParticleType(value));
    133144    } else {
    134       const size_t index = potential.getParameterIndex(key);
     145      const size_t index = getParameterIndex(key);
    135146      // parse the coefficients
    136147      if (index != (size_t)-1) {
     
    146157
    147158  /// set the new paremeters
    148   potential.setParameters(params);
    149   return ist;
     159  setParameters(params);
    150160}
    151161
Note: See TracChangeset for help on using the changeset viewer.