Changeset 0f6f3a


Ignore:
Timestamp:
Mar 11, 2010, 3:17:29 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
c3dbe0
Parents:
ed58ad
Message:

Small improvements to singleton pattern

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Singleton.hpp

    red58ad r0f6f3a  
    3232    void reset(T* _content);
    3333    void reset();
    34     ptr_t& operator=(ptr_t& rhs);
     34    ptr_t& operator=(const ptr_t& rhs);
    3535  private:
    36     T* content;
     36    mutable T* content;
    3737  };
    3838
     
    8585  static void setInstance(T*);
    8686protected:
     87  // constructor accessible by subclasses
     88  Singleton();
    8789
    8890private:
     91  // private copy constructor to avoid unintended copying
     92  Singleton(const Singleton&);
     93
    8994  static boost::recursive_mutex instanceLock;
    9095  static ptr_t theInstance;
  • src/Patterns/Singleton_impl.hpp

    red58ad r0f6f3a  
    7777}
    7878
     79template<class T, bool _may_create>
     80Singleton<T,_may_create>::Singleton(){/* empty */}
     81
     82// private copy constructor to avoid unintended copying
     83template <class T, bool _may_create>
     84Singleton<T,_may_create>::Singleton(const Singleton<T,_may_create>&){
     85  assert(0 && "Copy constructor of singleton template called");
     86}
     87
    7988/**
    8089 * This define allows simple instantiation of the necessary singleton functions
     
    121130
    122131template <class T,bool _may_create>
    123 typename Singleton<T,_may_create>::ptr_t& Singleton<T,_may_create>::ptr_t::operator=(typename Singleton<T,_may_create>::ptr_t& rhs){
     132typename Singleton<T,_may_create>::ptr_t& Singleton<T,_may_create>::ptr_t::operator=(const typename Singleton<T,_may_create>::ptr_t& rhs){
    124133  if(&rhs!=this){
    125134    delete content;
  • src/unittests/SingletonTest.cpp

    red58ad r0f6f3a  
    2929    count1++;
    3030  }
     31  // explicit copy constructor to catch if this is ever called
     32  SingletonStub1(const SingletonStub1&){
     33    CPPUNIT_FAIL    ( "Copy constructor of Singleton called" );
     34  }
    3135  virtual ~SingletonStub1(){
    3236    count2++;
     
    4751  SingletonStub2(){
    4852    count1++;
     53  }
     54  // explicit copy constructor to catch if thsi is ever called
     55  SingletonStub2(const SingletonStub2&){
     56    CPPUNIT_FAIL    ( "Copy constructor of Singleton called" );
    4957  }
    5058  virtual ~SingletonStub2(){
Note: See TracChangeset for help on using the changeset viewer.