Changeset 9f9b5a for src/Helpers


Ignore:
Timestamp:
Dec 4, 2010, 11:56:28 PM (14 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:
7d059d
Parents:
a06042
git-author:
Frederik Heber <heber@…> (11/22/10 17:27:26)
git-committer:
Frederik Heber <heber@…> (12/04/10 23:56:28)
Message:

Added some template operator<<() functions for std::list,map,multimap,set,vector.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Helpers/toString.hpp

    ra06042 r9f9b5a  
    1 /*
    2  * toString.hpp
     1/* \file toString.hpp
     2 *
     3 * contains template functions that allow for casting various types to strings.
    34 *
    45 *  Created on: Nov 14, 2010
     
    1213#include <string>
    1314#include <sstream>
     15
     16#include <list>
     17#include <map>
     18#include <set>
     19#include <vector>
    1420
    1521/** Converter for any class to string.
     
    2531}
    2632
     33
     34/** Operator for output to std::ostream operator of an std::list of arbitrary
     35 * type.
     36 * @param ost output stream
     37 * @param vector list of types to output
     38 * @return ost output stream
     39 */
     40template <class T> std::ostream & operator<<(std::ostream &ost, const std::list< T > &_vector)
     41{
     42  ost << "( ";
     43  for (typename std::list< T >::const_iterator iter = _vector.begin();
     44      iter != _vector.end();
     45      ++iter)
     46    ost << *iter << "; ";
     47  ost << ")";
     48  return ost;
     49}
     50
     51
     52/** Operator for output to std::ostream operator of an std::map of arbitrary
     53 * type.
     54 * @param ost output stream
     55 * @param vector map of types to output
     56 * @return ost output stream
     57 */
     58template <class T, class S> std::ostream & operator<<(std::ostream &ost, const std::map< T, S > &_vector)
     59{
     60  ost << "{ ";
     61  for (typename std::map< T, S >::const_iterator iter = _vector.begin();
     62      iter != _vector.end();
     63      ++iter)
     64    ost << "(" << iter->first << ")=>(" << iter->second << "); ";
     65  ost << "}";
     66  return ost;
     67}
     68
     69
     70/** Operator for output to std::ostream operator of an std::multimap of arbitrary
     71 * type.
     72 * @param ost output stream
     73 * @param multimap map of types to output
     74 * @return ost output stream
     75 */
     76template <class T, class S> std::ostream & operator<<(std::ostream &ost, const std::multimap< T, S > &_vector)
     77{
     78  ost << "{ ";
     79  for (typename std::multimap< T, S >::const_iterator iter = _vector.begin();
     80      iter != _vector.end();
     81      ++iter)
     82    ost << "(" << iter->first << ")=>(" << iter->second << "); ";
     83  ost << "}";
     84  return ost;
     85}
     86
     87
     88/** Operator for output to std::ostream operator of an std::set of arbitrary
     89 * type.
     90 * @param ost output stream
     91 * @param set list of types to output
     92 * @return ost output stream
     93 */
     94template <class T> std::ostream & operator<<(std::ostream &ost, const std::set< T > &_vector)
     95{
     96  ost << "( ";
     97  for (typename std::set< T >::const_iterator iter = _vector.begin();
     98      iter != _vector.end();
     99      ++iter)
     100    ost << *iter << "; ";
     101  ost << ")";
     102  return ost;
     103}
     104
     105
     106/** Operator for output to std::ostream operator of an std::vector of arbitrary
     107 * type.
     108 * @param ost output stream
     109 * @param vector vector of types to output
     110 * @return ost output stream
     111 */
     112template <class T> std::ostream & operator<<(std::ostream &ost, const std::vector< T > &_vector)
     113{
     114  ost << "( ";
     115  for (typename std::vector< T >::const_iterator iter = _vector.begin();
     116      iter != _vector.end();
     117      ++iter)
     118    ost << *iter << "; ";
     119  ost << ")";
     120  return ost;
     121}
     122
     123
    27124#endif /* TOSTRING_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.