Changeset 97445f for src/Descriptors


Ignore:
Timestamp:
Jul 24, 2015, 4:44:34 PM (10 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:
795c0f
Parents:
270bdf
git-author:
Frederik Heber <heber@…> (06/01/15 07:42:00)
git-committer:
Frederik Heber <heber@…> (07/24/15 16:44:34)
Message:

World::getMolecules..() now has const versions as well.

Location:
src/Descriptors
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • src/Descriptors/MoleculeDescriptor.cpp

    r270bdf r97445f  
    4949
    5050typedef World::MoleculeSet::internal_iterator molecules_iter_t;
     51typedef World::MoleculeSet::const_iterator const_molecules_iter_t;
    5152
    5253/************************ Forwarding object **************************************/
     
    7576}
    7677
     78const molecule* MoleculeDescriptor::find() const {
     79  return const_cast<const impl_t &>(*impl).find();
     80}
     81
    7782std::vector<molecule*> MoleculeDescriptor::findAll(){
    7883  return impl->findAll();
    7984}
    8085
     86std::vector<const molecule*> MoleculeDescriptor::findAll() const{
     87  return const_cast<const impl_t &>(*impl).findAll();
     88}
     89
    8190MoleculeDescriptor::impl_ptr MoleculeDescriptor::get_impl() const{
    8291  return impl;
     
    100109}
    101110
     111const World::MoleculeSet& MoleculeDescriptor_impl::getMolecules() const{
     112  return World::getInstance().molecules;
     113}
     114
    102115molecule* MoleculeDescriptor_impl::find() {
    103116  World::MoleculeSet &molecules = getMolecules();
    104   molecules_iter_t res = find_if(molecules.begin_internal(),molecules.end_internal(),boost::bind(&MoleculeDescriptor_impl::predicate,this,_1));
     117  molecules_iter_t res = find_if(
     118      molecules.begin_internal(),molecules.end_internal(),
     119      boost::bind(&MoleculeDescriptor_impl::predicate,
     120              this,_1));
    105121  return (res!=molecules.end_internal())?((*res).second):0;
     122}
     123
     124const molecule* MoleculeDescriptor_impl::find() const {
     125  const World::MoleculeSet &molecules = getMolecules();
     126  const_molecules_iter_t res = find_if(
     127      molecules.begin(),molecules.end(),
     128      boost::bind(&MoleculeDescriptor_impl::predicate,
     129              this,_1));
     130  return (res!=molecules.end())?((*res).second):0;
    106131}
    107132
     
    111136  for_each(molecules.begin_internal(),
    112137           molecules.end_internal(),
    113            boost::bind(&MoleculeDescriptor_impl::checkAndAdd,
    114                        this,&res,_1));
     138           boost::bind(static_cast<void (MoleculeDescriptor_impl::*)(
     139               std::vector<molecule*> *,
     140               std::pair<moleculeId_t,molecule*>)>(&MoleculeDescriptor_impl::checkAndAdd),
     141                       this,boost::cref(&res),_1));
    115142  return res;
    116143}
    117144
    118 void MoleculeDescriptor_impl::checkAndAdd(std::vector<molecule*> *v,std::pair<moleculeId_t,molecule*> p){
     145vector<const molecule*> MoleculeDescriptor_impl::findAll() const {
     146  vector<const molecule*> res;
     147  const World::MoleculeSet &molecules = getMolecules();
     148  for_each(molecules.begin(),
     149           molecules.end(),
     150           boost::bind(static_cast<void (MoleculeDescriptor_impl::*)(
     151               std::vector<const molecule*> *,
     152               std::pair<moleculeId_t,const molecule*>) const>(&MoleculeDescriptor_impl::checkAndAdd),
     153                       boost::cref(this),&res,_1));
     154  return res;
     155}
     156
     157void MoleculeDescriptor_impl::checkAndAdd(
     158    std::vector<molecule*> *v,
     159    std::pair<moleculeId_t,molecule*> p){
    119160  if(predicate(p)){
    120161    v->push_back(p.second);
     
    122163}
    123164
     165void MoleculeDescriptor_impl::checkAndAdd(
     166    std::vector<const molecule*> *v,
     167    std::pair<moleculeId_t,const molecule*> p) const{
     168  if(predicate(p)){
     169    v->push_back(p.second);
     170  }
     171}
     172
    124173/************************** Universe and Emptyset *****************/
    125174
     
    130179{}
    131180
    132 bool MoleculeAllDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*>){
     181bool MoleculeAllDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*>) const{
    133182  return true;
    134183}
     
    144193{}
    145194
    146 bool MoleculeNoneDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*>){
     195bool MoleculeNoneDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*>) const{
    147196  return false;
    148197}
     
    162211{}
    163212
    164 bool MoleculeAndDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
     213bool MoleculeAndDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule) const{
    165214  return lhs->predicate(molecule) && rhs->predicate(molecule);
    166215}
     
    178227}
    179228
    180 bool MoleculeOrDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
     229bool MoleculeOrDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule) const{
    181230  return lhs->predicate(molecule) || rhs->predicate(molecule);
    182231}
     
    198247}
    199248
    200 bool MoleculeNotDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
     249bool MoleculeNotDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule) const{
    201250 return !(arg->predicate(molecule));
    202251}
  • src/Descriptors/MoleculeDescriptor.hpp

    r270bdf r97445f  
    4141  // close coupling to the world to allow access
    4242  friend molecule* World::getMolecule(MoleculeDescriptor descriptor);
     43  friend const molecule* World::getMolecule(MoleculeDescriptor descriptor) const;
    4344  friend std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor);
     45  friend std::vector<const molecule*> World::getAllMolecules(MoleculeDescriptor descriptor) const;
    4446  template <class,class,class> friend class SelectiveIterator;
    4547  template <class,class,class> friend class SelectiveConstIterator;
     
    7981   * forward Method to implementation
    8082   */
     83  const molecule* find() const;
     84
     85  /**
     86   * forward Method to implementation
     87   */
    8188  std::vector<molecule*> findAll();
     89
     90  /**
     91   * forward Method to implementation
     92   */
     93  std::vector<const molecule*> findAll() const;
    8294
    8395  /**
  • src/Descriptors/MoleculeDescriptor_impl.hpp

    r270bdf r97445f  
    3030   * Implement this abstract Method to make a concrete MoleculeDescriptor pick certain Molecules
    3131   */
    32   virtual bool predicate(std::pair<moleculeId_t,molecule*>)=0;
     32  virtual bool predicate(const std::pair<moleculeId_t,const molecule*>) const=0;
    3333
    3434protected:
     
    4343
    4444  /**
     45   * This method is called when the Descriptor is used to find the first matching
     46   * Molecule. Walks through all Molecules and stops on the first match. Can be implemented
     47   * when the searched Molecule can be found in a more efficient way. Calculated
     48   * Moleculedescriptors will always use this method, so no improvement there.
     49   */
     50  virtual const molecule* find() const;
     51
     52  /**
    4553   * This method is called when the Descriptor is used to find all matching Molecules.
    4654   * Walks through all Molecules and tests the predicate on each one. A vector of all
     
    4856   */
    4957  virtual std::vector<molecule*> findAll();
     58
     59  /**
     60   * This method is called when the Descriptor is used to find all matching Molecules.
     61   * Walks through all Molecules and tests the predicate on each one. A vector of all
     62   * matching Molecules is returned.
     63   */
     64  virtual std::vector<const molecule*> findAll() const;
    5065
    5166  /**
     
    5772  World::MoleculeSet& getMolecules();
    5873
     74  /**
     75   * This method is used internally to query the Set of Molecules from the world.
     76   * By using this method derived classes can also access the Internal World Datastructre.
     77   * Implemented in full in the Base Descriptor Implementation, so only this one method
     78   * needs to be friend with the World class.
     79   */
     80  const World::MoleculeSet& getMolecules() const;
     81
    5982  void checkAndAdd(std::vector<molecule*>*,std::pair<moleculeId_t,molecule*>);
     83
     84  void checkAndAdd(std::vector<const molecule*>*,std::pair<moleculeId_t,const molecule*>) const;
    6085};
    6186
     
    7398   * Always returns true for any Molecule
    7499   */
    75   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
     100  virtual bool predicate(const std::pair<moleculeId_t,const molecule*>) const;
    76101};
    77102
     
    88113   * Always returns false for any Molecule
    89114   */
    90   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
     115  virtual bool predicate(const std::pair<moleculeId_t,const molecule*>) const;
    91116};
    92117
     
    106131   * second Descriptor to decide if an Molecule should be selected.
    107132   */
    108   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
     133  virtual bool predicate(const std::pair<moleculeId_t,const molecule*>) const;
    109134
    110135private:
     
    126151   * second Descriptor to decide if an Molecule should be selected.
    127152   */
    128   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
     153  virtual bool predicate(const std::pair<moleculeId_t,const molecule*>) const;
    129154
    130155private:
     
    145170   * Opposite of the given descriptor predicate.
    146171   */
    147   virtual bool predicate(std::pair<moleculeId_t,molecule*>);
     172  virtual bool predicate(const std::pair<moleculeId_t,const molecule*>) const;
    148173
    149174private:
  • src/Descriptors/MoleculeFormulaDescriptor.cpp

    r270bdf r97445f  
    4848MoleculeFormulaDescriptor_impl::~MoleculeFormulaDescriptor_impl(){}
    4949
    50 bool MoleculeFormulaDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
     50bool MoleculeFormulaDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule) const{
    5151  return molecule.second->getFormula() == formula;
    5252}
  • src/Descriptors/MoleculeFormulaDescriptor_impl.hpp

    r270bdf r97445f  
    2323  MoleculeFormulaDescriptor_impl(const Formula &);
    2424  virtual ~MoleculeFormulaDescriptor_impl();
    25   bool predicate(std::pair<moleculeId_t,molecule*> molecule);
     25  bool predicate(const std::pair<moleculeId_t,const molecule*> molecule) const;
    2626private:
    2727  Formula formula;
  • src/Descriptors/MoleculeIdDescriptor.cpp

    r270bdf r97445f  
    5252{}
    5353
    54 bool MoleculeIdDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule) {
     54bool MoleculeIdDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule)  const{
    5555  return molecule.first==id;
    5656}
     
    6666}
    6767
     68const molecule *MoleculeIdDescriptor_impl::find() const {
     69  const World::MoleculeSet &molecules = getMolecules();
     70  const World::MoleculeSet::const_iterator res = molecules.find(id);
     71  return (res!=molecules.end())?((*res).second):0;
     72}
     73
    6874vector<molecule*> MoleculeIdDescriptor_impl::findAll(){
    6975  molecule *res = find();
    7076  return (res)?(vector<molecule*>(1,res)):(vector<molecule*>());
    7177}
     78
     79vector<const molecule*> MoleculeIdDescriptor_impl::findAll() const {
     80  const molecule *res = find();
     81  return (res)?(vector<const molecule*>(1,res)):(vector<const molecule*>());
     82}
     83
  • src/Descriptors/MoleculeIdDescriptor_impl.hpp

    r270bdf r97445f  
    1616  virtual ~MoleculeIdDescriptor_impl();
    1717
    18   bool predicate(std::pair<moleculeId_t,molecule*> molecule);
     18  bool predicate(const std::pair<moleculeId_t,const molecule*> molecule) const;
    1919
    2020protected:
    2121  virtual molecule *find();
     22  virtual const molecule *find() const;
    2223  virtual std::vector<molecule*> findAll();
     24  virtual std::vector<const molecule*> findAll() const;
    2325private:
    2426  moleculeId_t id;
  • src/Descriptors/MoleculeNameDescriptor.cpp

    r270bdf r97445f  
    5050{}
    5151
    52 bool MoleculeNameDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule) {
     52bool MoleculeNameDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule)  const{
    5353  return molecule.second->name==name;
    5454}
  • src/Descriptors/MoleculeNameDescriptor_impl.hpp

    r270bdf r97445f  
    1616  virtual ~MoleculeNameDescriptor_impl();
    1717
    18   bool predicate(std::pair<moleculeId_t,molecule*> molecule);
     18  bool predicate(const std::pair<moleculeId_t,const molecule*> molecule) const;
    1919
    2020private:
  • src/Descriptors/MoleculeOfAtomSelectionDescriptor.cpp

    r270bdf r97445f  
    4848MoleculeOfAtomSelectionDescriptor_impl::~MoleculeOfAtomSelectionDescriptor_impl(){}
    4949
    50 bool MoleculeOfAtomSelectionDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
     50bool MoleculeOfAtomSelectionDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule) const{
    5151  for (molecule::const_iterator iter = molecule.second->begin();
    5252      iter != molecule.second->end();
     
    7070}
    7171
     72const molecule* MoleculeOfAtomSelectionDescriptor_impl::find() const {
     73  const World::AtomSet &set = getSelectedAtoms();
     74  for (World::AtomSet::const_iterator iter = set.begin();
     75      iter != set.end();
     76      ++iter) {
     77    if (iter->second->getMolecule())
     78      return iter->second->getMolecule();
     79  }
     80  return 0;
     81}
     82
    7283std::vector<molecule*> MoleculeOfAtomSelectionDescriptor_impl::findAll(){
    7384  std::vector<molecule*> res;
     
    7889      iter != set.end_internal();
    7990      ++iter) {
    80     if (iter->second->getMolecule()) {
     91    if (iter->second->getMolecule() != NULL) {
     92      // get as non-const version
    8193      molecule * const _mol =
    8294          World::getInstance().getMolecule(
    8395              MoleculeById(iter->second->getMolecule()->getId()));
     96      inserter = temp.insert( _mol );
     97      if (inserter.second)
     98        res.push_back(_mol);
     99    }
     100  }
     101  return res;
     102}
     103
     104std::vector<const molecule*> MoleculeOfAtomSelectionDescriptor_impl::findAll() const {
     105  std::vector<const molecule*> res;
     106  std::set<const molecule*> temp;
     107  std::pair< std::set<const molecule*>::iterator, bool> inserter;
     108  const World::AtomSet &set = getSelectedAtoms();
     109  for (World::AtomSet::const_iterator iter = set.begin();
     110      iter != set.end();
     111      ++iter) {
     112    const molecule * const _mol = iter->second->getMolecule();
     113    if ( _mol != NULL ) {
    84114      inserter = temp.insert( _mol );
    85115      if (inserter.second)
     
    94124}
    95125
     126const World::AtomSet& MoleculeOfAtomSelectionDescriptor_impl::getSelectedAtoms() const{
     127  return World::getInstance().selectedAtoms;
     128}
     129
    96130MoleculeDescriptor MoleculesByAtomSelection(){
    97131  return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculeOfAtomSelectionDescriptor_impl()));
  • src/Descriptors/MoleculeOfAtomSelectionDescriptor_impl.hpp

    r270bdf r97445f  
    2121  MoleculeOfAtomSelectionDescriptor_impl();
    2222  virtual ~MoleculeOfAtomSelectionDescriptor_impl();
    23   bool predicate(std::pair<moleculeId_t,molecule*> molecule);
     23  bool predicate(const std::pair<moleculeId_t,const molecule*> molecule) const;
    2424protected:
    2525  // need to overide more than the standard methods to make this fast
    26   virtual molecule* find();
     26  virtual molecule *find();
     27  virtual const molecule *find() const;
    2728  virtual std::vector<molecule*> findAll();
     29  virtual std::vector<const molecule*> findAll() const;
    2830
    2931  World::AtomSet& getSelectedAtoms();
     32  const World::AtomSet& getSelectedAtoms() const;
    3033};
    3134
  • src/Descriptors/MoleculeOrderDescriptor.cpp

    r270bdf r97445f  
    5050{}
    5151
    52 bool MoleculeOrderDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> _molecule)
     52bool MoleculeOrderDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> _molecule) const
    5353{
    54   molecule *mol = find();
     54  const molecule *mol = find();
    5555  return (mol == _molecule.second);
    5656}
     
    6161
    6262World::MoleculeSet& MoleculeOrderDescriptor_impl::getMolecules()
     63{
     64  return World::getInstance().molecules;
     65}
     66
     67const World::MoleculeSet& MoleculeOrderDescriptor_impl::getMolecules() const
    6368{
    6469  return World::getInstance().molecules;
     
    95100}
    96101
     102const molecule* MoleculeOrderDescriptor_impl::find() const {
     103  const World::MoleculeSet &molecules = getMolecules();
     104
     105  int i=0;
     106  const molecule *mol = NULL;
     107  if (id == 0) {
     108    return NULL;
     109  } else if (id > 0) {
     110    World::MoleculeSet::const_iterator res = molecules.begin();
     111    for (; res != molecules.end(); ++res) { // when iterator is normal, ++ goes forward!
     112      ++i;
     113      if (id == i) {
     114        mol = res->second;
     115        break;
     116      }
     117    }
     118  } else {
     119    World::MoleculeSet::const_reverse_iterator res = molecules.rbegin();
     120    for (; res != molecules.rend(); ++res) {  // when iterator is reverse, ++ goes backward!
     121      --i;
     122      if (id == i) {
     123        mol = res->second;
     124        break;
     125      }
     126    }
     127  }
     128
     129  return mol;
     130}
     131
     132
    97133vector<molecule*> MoleculeOrderDescriptor_impl::findAll(){
    98134  molecule *res = find();
    99135  return (res)?(vector<molecule*>(1,res)):(vector<molecule*>());
    100136}
     137
     138vector<const molecule*> MoleculeOrderDescriptor_impl::findAll() const {
     139  const molecule *res = find();
     140  return (res)?(vector<const molecule*>(1,res)):(vector<const molecule*>());
     141}
  • src/Descriptors/MoleculeOrderDescriptor_impl.hpp

    r270bdf r97445f  
    1616  virtual ~MoleculeOrderDescriptor_impl();
    1717
    18   bool predicate(std::pair<moleculeId_t,molecule*> _molecule);
     18  bool predicate(const std::pair<moleculeId_t,const molecule*> _molecule) const;
    1919
    2020protected:
    2121  virtual molecule *find();
     22  virtual const molecule *find() const;
    2223  virtual std::vector<molecule*> findAll();
     24  virtual std::vector<const molecule*> findAll() const;
    2325
    2426  World::MoleculeSet& getMolecules();
     27  const World::MoleculeSet& getMolecules() const;
    2528
    2629private:
  • src/Descriptors/MoleculePtrDescriptor.cpp

    r270bdf r97445f  
    4545
    4646
    47 MoleculePtrDescriptor_impl::MoleculePtrDescriptor_impl(molecule * _ptr) :
     47MoleculePtrDescriptor_impl::MoleculePtrDescriptor_impl(const molecule * _ptr) :
    4848  ptr(_ptr)
    4949{}
     
    5252{}
    5353
    54 bool MoleculePtrDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule) {
     54bool MoleculePtrDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule)  const{
    5555  return molecule.second==ptr;
    5656}
    5757
    58 MoleculeDescriptor MoleculeByPtr(molecule * ptr){
     58MoleculeDescriptor MoleculeByPtr(const molecule * ptr){
    5959  return MoleculeDescriptor(MoleculeDescriptor::impl_ptr(new MoleculePtrDescriptor_impl(ptr)));
    6060}
  • src/Descriptors/MoleculePtrDescriptor.hpp

    r270bdf r97445f  
    1818#include "Descriptors/MoleculeDescriptor.hpp"
    1919
    20 MoleculeDescriptor MoleculeByPtr(molecule * ptr);
     20MoleculeDescriptor MoleculeByPtr(const molecule * ptr);
    2121
    2222#endif /* MOLECULEPTRDESCRIPTOR_HPP_ */
  • src/Descriptors/MoleculePtrDescriptor_impl.hpp

    r270bdf r97445f  
    1515{
    1616public:
    17   MoleculePtrDescriptor_impl(molecule * ptr);
     17  MoleculePtrDescriptor_impl(const molecule * ptr);
    1818  virtual ~MoleculePtrDescriptor_impl();
    1919
    20   bool predicate(std::pair<moleculeId_t,molecule*> molecule);
     20  bool predicate(const std::pair<moleculeId_t,const molecule*> molecule) const;
    2121
    2222private:
    23   molecule * ptr;
     23  const molecule * ptr;
    2424};
    2525
  • src/Descriptors/MoleculeSelectionDescriptor.cpp

    r270bdf r97445f  
    4444MoleculeSelectionDescriptor_impl::~MoleculeSelectionDescriptor_impl(){}
    4545
    46 bool MoleculeSelectionDescriptor_impl::predicate(std::pair<moleculeId_t,molecule*> molecule){
     46bool MoleculeSelectionDescriptor_impl::predicate(const std::pair<moleculeId_t,const molecule*> molecule) const{
    4747  return getSelectedMolecules().count(molecule.first);
    4848}
     
    5252  World::MoleculeSet::internal_iterator begin = set.begin_internal();
    5353  return (begin!=set.end_internal())?(begin->second):0;
     54}
     55
     56const molecule* MoleculeSelectionDescriptor_impl::find() const {
     57  const World::MoleculeSet &set = getSelectedMolecules();
     58  World::MoleculeSet::const_iterator begin = set.begin();
     59  return (begin!=set.end())?(begin->second):0;
    5460}
    5561
     
    6470}
    6571
     72std::vector<const molecule*> MoleculeSelectionDescriptor_impl::findAll() const {
     73  std::vector<const molecule*> res;
     74  const World::MoleculeSet &set = getSelectedMolecules();
     75  transform(set.begin(),
     76           set.end(),
     77           back_inserter(res),
     78           _take<molecule*,World::MoleculeSet::value_type>::get);
     79  return res;
     80}
     81
    6682World::MoleculeSet& MoleculeSelectionDescriptor_impl::getSelectedMolecules(){
     83  return World::getInstance().selectedMolecules;
     84}
     85
     86const World::MoleculeSet& MoleculeSelectionDescriptor_impl::getSelectedMolecules() const{
    6787  return World::getInstance().selectedMolecules;
    6888}
  • src/Descriptors/MoleculeSelectionDescriptor_impl.hpp

    r270bdf r97445f  
    2121  MoleculeSelectionDescriptor_impl();
    2222  virtual ~MoleculeSelectionDescriptor_impl();
    23   bool predicate(std::pair<moleculeId_t,molecule*> molecule);
     23  bool predicate(const std::pair<moleculeId_t,const molecule*> molecule) const;
    2424protected:
    2525  // need to overide more than the standard methods to make this fast
    26   virtual molecule* find();
     26  virtual molecule *find();
     27  virtual const molecule *find() const;
    2728  virtual std::vector<molecule*> findAll();
     29  virtual std::vector<const molecule*> findAll() const;
    2830
    2931  World::MoleculeSet& getSelectedMolecules();
     32  const World::MoleculeSet& getSelectedMolecules() const;
    3033};
    3134
Note: See TracChangeset for help on using the changeset viewer.