OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
residue_prop.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_RESIDUE_PROP_HH
20 #define OST_RESIDUE_PROP_HH
21 
22 #include <vector>
23 #include <boost/operators.hpp>
24 
25 #include <ost/mol/module_config.hh>
26 
27 namespace ost { namespace mol {
28 
29 
30 class DLLEXPORT ResNum: private
31  boost::additive<ResNum, int,
32  boost::additive<ResNum,
33  boost::totally_ordered<ResNum,
34  boost::totally_ordered<ResNum, int,
35  boost::unit_steppable<ResNum> > > > >
36 {
37 public:
38 
39  // needed to wrap certain map classes
40  ResNum():
41  num_(1),alt_('\0')
42  {}
43 
44  ResNum(int n):
45  num_(n), alt_('\0')
46  { }
47 
48  ResNum(int n, char a):
49  num_(n), alt_(a)
50  {}
51 
52  bool operator==(const ResNum& r) const
53  {
54  return num_==r.num_ && alt_==r.alt_;
55  }
56 
57  bool operator<(const ResNum& r) const
58  {
59  return num_==r.num_ ? alt_<r.alt_ : num_<r.num_;
60  }
61 
62  int operator+=(int i)
63  {
64  num_+=i;
65  return num_;
66  }
67 
68  int operator-=(int i)
69  {
70  num_-=i;
71  return num_;
72  }
73 
74  int operator+=(const ResNum& r)
75  {
76  num_+=r.num_;
77  return num_;
78  }
79 
80  int operator-=(const ResNum& r)
81  {
82  num_-=r.num_;
83  return num_;
84  }
85 
87  {
88  ++num_;
89  return *this;
90  }
91 
93  {
94  --num_;
95  return *this;
96  }
97 
99  {
100  char alt= alt_=='\0' ? 'a' : alt_+1;
101  ResNum nrvo(num_,alt);
102  return nrvo;
103  }
104 
110  inline String AsString() const;
111 
112  int GetNum() const { return num_; }
113 
114  void SetNum(int num) { num_=num; }
115 
116  void SetInsCode(char ins_code) { alt_=ins_code; }
117 
118  char GetInsCode() const { return alt_; }
119 
120 private:
121  int num_ : 24;
122  int alt_ : 8;
123 };
124 
126 typedef std::vector<ResNum> ResNumList;
127 
128 inline std::ostream& operator<<(std::ostream& os, const ResNum& n)
129 {
130  os << n.GetNum();
131  if (n.GetInsCode()!='\0')
132  os << n.GetInsCode();
133  return os;
134 }
135 
136 inline String ResNum::AsString() const
137 {
138  std::stringstream ss;
139  ss << *this;
140  return ss.str();
141 }
142 
143 }} // ns
144 
145 
146 #endif
String ResidueKey
void SetNum(int num)
std::string String
Definition: base.hh:54
std::vector< ResNum > ResNumList
int operator+=(int i)
Definition: residue_prop.hh:62
char GetInsCode() const
DLLEXPORT_OST_MOL std::ostream & operator<<(std::ostream &os, const AtomBase &atom)
String AsString() const
get residue number as String
bool operator<(const ResNum &r) const
Definition: residue_prop.hh:57
ResNum NextInsertionCode() const
Definition: residue_prop.hh:98
ResNum & operator--()
Definition: residue_prop.hh:92
void SetInsCode(char ins_code)
ResNum(int n, char a)
Definition: residue_prop.hh:48
int operator-=(int i)
Definition: residue_prop.hh:68
int operator-=(const ResNum &r)
Definition: residue_prop.hh:80
int operator+=(const ResNum &r)
Definition: residue_prop.hh:74
int GetNum() const
ResNum & operator++()
Definition: residue_prop.hh:86
bool operator==(const ResNum &r) const
Definition: residue_prop.hh:52