Changeset c4afdf3


Ignore:
Timestamp:
May 19, 2021, 7:06:29 PM (4 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
15fc6a
Parents:
3f8238
git-author:
Frederik Heber <frederik.heber@…> (05/14/21 21:14:53)
git-committer:
Frederik Heber <frederik.heber@…> (05/19/21 19:06:29)
Message:

Extended BindingModel by comparators.

  • this allows placing them in sorted STL containers.
  • TEST: Added unit test.
Location:
src
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Homology/HomologyGraph.hpp

    r3f8238 rc4afdf3  
    127127  }
    128128
     129  /** Checks whether this graph contains the given \a graph.
     130   *
     131   * Every edge must be present in this graph.
     132   *
     133   * \return true - graph is contained, false - else
     134   */
     135  bool contains(const HomologyGraph &graph) const {
     136    for (edges_t::const_iterator iter = graph.edges.begin(); iter != graph.edges.end(); ++iter) {
     137      edges_t::const_iterator finditer = edges.find(iter->first);
     138      if (finditer == edges.end())
     139        return false;
     140      else if (finditer->second < iter->second)
     141        return false;
     142    }
     143    return true;
     144  }
     145
    129146  /** Checks whether this graph has \b exactly \a _times nodes with \a _number
    130147   * atomic number.
  • src/Potentials/BindingModel.cpp

    r3f8238 rc4afdf3  
    5858{}
    5959
     60bool BindingModel::operator<(const BindingModel &model) const {
     61  if (graph.getEdges().empty()) {
     62    return nodes < model.nodes;
     63  } else
     64    return graph.getEdges() < model.graph.getEdges();
     65}
    6066
     67bool BindingModel::operator>(const BindingModel &model) const  {
     68  if (graph.getEdges().empty()) {
     69    return nodes > model.nodes;
     70  } else
     71    return graph.getEdges() > model.graph.getEdges();
     72}
     73
     74bool BindingModel::operator==(const BindingModel &model) const {
     75  if (graph.getEdges().empty()) {
     76    return nodes == model.nodes;
     77  } else
     78    return graph.getEdges() == model.graph.getEdges();
     79}
     80
  • src/Potentials/BindingModel.hpp

    r3f8238 rc4afdf3  
    5555  const vector_nodes_t& getNodes() const { return nodes; }
    5656
     57  // comparators (allows sorting and hence quicker finding in STL containers)
     58  bool operator<(const BindingModel &model) const;
     59  bool operator>(const BindingModel &model) const;
     60  bool operator==(const BindingModel &model) const;
     61  bool operator!=(const BindingModel &model) const {
     62    return (!(*this == model));
     63  }
     64
    5765private:
    5866  //!> the homology graph of this binding model
  • src/Potentials/unittests/Makefile.am

    r3f8238 rc4afdf3  
    33
    44POTENTIALSTESTSSOURCES = \
     5        ../Potentials/unittests/BindingModelUnitTest.cpp \
    56        ../Potentials/unittests/CompoundPotentialUnitTest.cpp \
    67        ../Potentials/unittests/PartialNucleiChargeFitterUnitTest.cpp \
     
    89
    910POTENTIALSTESTSHEADERS = \
     11        ../Potentials/unittests/BindingModelUnitTest.hpp \
    1012        ../Potentials/unittests/CompoundPotentialUnitTest.hpp \
    1113        ../Potentials/unittests/PartialNucleiChargeFitterUnitTest.hpp \
     
    1315
    1416POTENTIALSTESTS = \
     17        BindingModelUnitTest \
    1518        CompoundPotentialUnitTest \
    1619        PartialNucleiChargeFitterUnitTest \
     
    2932        $(BOOST_SERIALIZATION_LDFLAGS) $(BOOST_SERIALIZATION_LIBS) \
    3033        $(BOOST_LIB)
     34
     35BindingModelUnitTest_SOURCES = \
     36        ../Potentials/unittests/BindingModelUnitTest.cpp \
     37        ../Potentials/unittests/BindingModelUnitTest.hpp
     38BindingModelUnitTest_LDADD = \
     39        ${POTENTIALSLIBS} \
     40        ../libMolecuilderFragmentation.la \
     41        ../libMolecuilderFragmentation_getFromKeysetStub.la
    3142
    3243CompoundPotentialUnitTest_SOURCES = \
Note: See TracChangeset for help on using the changeset viewer.