Victor
 All Data Structures Functions Variables Friends Pages
SimpleBond.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef _SIMPLEBOND_H_
18 #define _SIMPLEBOND_H_
19 
20 // Includes:
21 #include <algorithm>
22 #include <vector>
23 #include <string>
24 //#include <Debug.h>
25 #include <Identity.h>
26 using namespace std;
27 
28 // Global constants, typedefs, etc. (to avoid):
29 
30 
31 namespace Victor { namespace Biopool {
32 
39  class SimpleBond {
40  public:
41 
42  // CONSTRUCTORS/DESTRUCTOR:
43  SimpleBond(unsigned int mI = 1, unsigned int mO = 4);
44  SimpleBond(const SimpleBond& orig);
45  virtual ~SimpleBond();
46 
47  // PREDICATES:
48  virtual string getType() const;
49 
50  bool isBond(const SimpleBond& c) const;
51  bool isInBond(const SimpleBond& c) const;
52  bool isOutBond(const SimpleBond& c) const;
53  bool isIndirectBond(const SimpleBond& c) const;
54  // eg. A to C if A bond B & B bond C
55  bool isIndirectInBond(const SimpleBond& c) const;
56  bool isIndirectOutBond(const SimpleBond& c) const;
57  bool isTorsionBond(const SimpleBond& c) const;
58  // eg. A to D if A indirect bond C & C bond D
59 
60  virtual const SimpleBond& getInBond(unsigned int n) const;
61  virtual const SimpleBond& getOutBond(unsigned int n) const;
62  virtual SimpleBond& getInBond(unsigned int n);
63  virtual SimpleBond& getOutBond(unsigned int n);
64 
65  unsigned int sizeInBonds() const;
66  unsigned int sizeOutBonds() const;
67 
68  unsigned int getMaxInBonds() const;
69  unsigned int getMaxOutBonds() const;
70 
71  // MODIFIERS:
72  virtual void copy(const SimpleBond& orig);
73 
74  virtual void setType(string _name);
75 
76  virtual void bindIn(SimpleBond& c);
77  virtual void bindOut(SimpleBond& c);
78 
79  virtual void unbindIn(SimpleBond& c);
80  virtual void unbindOut(SimpleBond& c);
81 
82  void setMaxInBonds(unsigned int m);
83  void setMaxOutBonds(unsigned int m);
84 
85  // OPERATORS:
86  bool operator==(const SimpleBond& other) const;
87  SimpleBond& operator=(const SimpleBond& orig);
88 
89  protected:
90 
91  // HELPERS:
92  virtual void pUnbindIn(SimpleBond& c);
93  virtual void pUnbindOut(SimpleBond& c);
94 
95  // ATTRIBUTES:
96  vector<SimpleBond*> inBonds, outBonds; // current in and out bonds
97  unsigned int maxIn, maxOut; // maximum number of in and out bonds
98  Identity id; // Object Id and name
99 
100  private:
101 
102  };
103 
104 
105  // ---------------------------------------------------------------------------
106  // SimpleBond
107  // -----------------x-------------------x-------------------x-----------------
108 
109  // PREDICATES:
110 
114  inline string SimpleBond::getType() const {
115  return this->id;
116  }
117 
122  inline bool SimpleBond::isBond(const SimpleBond& c) const {
123  return (isInBond(c) || isOutBond(c));
124  }
125 
130  inline bool SimpleBond::isInBond(const SimpleBond& c) const {
131  return find(inBonds.begin(), inBonds.end(), &c) != inBonds.end();
132  }
133 
138  inline bool
139  SimpleBond::isOutBond(const SimpleBond& c) const {
140  return find(outBonds.begin(), outBonds.end(), &c) != outBonds.end();
141  }
142 
146  inline unsigned int SimpleBond::sizeInBonds() const {
147  return inBonds.size();
148  }
149 
153  inline unsigned int SimpleBond::sizeOutBonds() const {
154  return outBonds.size();
155  }
156 
160  inline SimpleBond& SimpleBond::getInBond(unsigned int n) {
161  PRECOND(n < sizeInBonds(), exception);
162  return *inBonds[n];
163  }
164 
168  inline SimpleBond& SimpleBond::getOutBond(unsigned int n) {
169  PRECOND(n < sizeOutBonds(), exception);
170  return *outBonds[n];
171  }
172 
176  inline const SimpleBond& SimpleBond::getInBond(unsigned int n) const {
177  PRECOND(n < sizeInBonds(), exception);
178  return *inBonds[n];
179  }
180 
184  inline const SimpleBond& SimpleBond::getOutBond(unsigned int n) const {
185  PRECOND(n < sizeOutBonds(), exception);
186  return *outBonds[n];
187  }
188 
193  inline unsigned int SimpleBond::getMaxInBonds() const {
194  return maxIn;
195  }
196 
200  inline unsigned int SimpleBond::getMaxOutBonds() const {
201  return maxOut;
202  }
203 
204  // MODIFIERS:
205 
209  inline void SimpleBond::setType(string _name) {
210  id.setName(_name);
211  }
212 
216  inline void SimpleBond::setMaxInBonds(unsigned int m) {
217  PRECOND((m >= inBonds.size()), exception);
218  maxIn = m;
219  }
220 
225  inline void SimpleBond::setMaxOutBonds(unsigned int m) {
226  PRECOND((m >= outBonds.size()), exception);
227  maxOut = m;
228  }
229 
230  // OPERATORS:
231 
232  inline SimpleBond& SimpleBond::operator=(const SimpleBond& orig) {
233  PRINT_NAME;
234  if (&orig != this)
235  copy(orig);
236  return *this;
237  }
238 
239  inline bool SimpleBond::operator==(const SimpleBond& other) const {
240  return id == (other.id);
241  }
242 
243 }} //namespace
244 
245 #endif //_SimpleBond_H_
246 
Defines chemical and abstract bonds between objects. eg.: covalent bonds. Attention: copy() strips or...
Definition: SimpleBond.h:39
Implements object id. With a "number" a "name" and a "counter".
Definition: Identity.h:36