source: src/Formula.hpp@ 796aa6

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
Last change on this file since 796aa6 was d8a0ec, checked in by Tillmann Crueger <crueger@…>, 14 years ago

Made the Formula array resize itself in both directions

  • resizing the array to its smallest form helps speed up comparison of formulas and keeps the STL-equal algorithm from running over vector boundaries
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Formula.hpp
3 *
4 * Created on: Jul 21, 2010
5 * Author: crueger
6 */
7
8#ifndef FORMULA_HPP_
9#define FORMULA_HPP_
10
11#include <vector>
12#include <iosfwd>
13#include <iterator>
14
15#include "Exceptions/ParseError.hpp"
16
17#include "types.hpp"
18
19class element;
20
21class Formula
22{
23public:
24 typedef element* key_type;
25 typedef unsigned int mapped_type;
26 typedef std::pair<key_type, mapped_type> value_type;
27 typedef std::vector<unsigned int> set_t;
28
29 template <class result_type>
30 class _iterator : public std::iterator <std::bidirectional_iterator_tag,
31 result_type>
32 {
33 public:
34 _iterator(set_t&);
35 _iterator(set_t&,size_t);
36 _iterator(const _iterator &rhs);
37 ~_iterator();
38 _iterator &operator=(const _iterator &);
39 bool operator==(const _iterator&);
40 bool operator!=(const _iterator&);
41 _iterator operator++();
42 _iterator operator++(int);
43 _iterator operator--();
44 _iterator operator--(int);
45 result_type operator*();
46 result_type *operator->();
47 private:
48 set_t *set;
49 size_t pos; // cannot use an iterator, because we need a position to access the element
50 };
51
52 typedef _iterator<value_type> iterator;
53 typedef _iterator<const value_type> const_iterator;
54
55 Formula();
56 Formula(const std::string&);
57 Formula(const Formula&);
58 virtual ~Formula();
59
60 Formula &operator=(const Formula&);
61
62 std::string toString() const;
63 void fromString(const std::string&) throw(ParseError);
64 bool checkOut(std::ostream*) const;
65
66 unsigned int getElementCount() const;
67 bool hasElement(const element*) const;
68 bool hasElement(atomicNumber_t) const;
69 bool hasElement(const std::string&) const;
70
71 void operator+=(const element*);
72 void operator+=(atomicNumber_t);
73 void operator+=(const std::string&);
74
75 void operator-=(const element*);
76 void operator-=(atomicNumber_t);
77 void operator-=(const std::string&);
78
79 void addElements(const element*,unsigned int);
80 void addElements(atomicNumber_t,unsigned int);
81 void addElements(const std::string&,unsigned int);
82
83 // only const versions, because someone might try to increment a previously
84 // not set element
85 const unsigned int operator[](const element*) const;
86 const unsigned int operator[](atomicNumber_t) const;
87 const unsigned int operator[](std::string) const;
88
89 bool operator==(const Formula&) const;
90 bool operator!=(const Formula&) const;
91
92 iterator begin();
93 const_iterator begin() const;
94 iterator end();
95 const_iterator end() const;
96
97 void clear();
98
99private:
100 // this contains all counts of elements in the formula
101 // the size of the actual structure might be used in comparisons
102 // so be sure not to keep any zero elements at the end
103 // e.g. {5;4;0;0;0;2;1} or {0;1;0;0;2} are ok, but {1;2;3;0;0;0} is bad
104 set_t elementCounts;
105 unsigned int numElements;
106};
107
108std::ostream &operator<<(std::ostream&,const Formula&);
109
110#endif /* FORMULA_HPP_ */
Note: See TracBrowser for help on using the repository browser.