OpenStructure
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-2011 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 <boost/operators.hpp>
23 
24 #include <ost/mol/module_config.hh>
25 
26 namespace ost { namespace mol {
27 
28 
29 class DLLEXPORT ResNum: private
30  boost::additive<ResNum, int,
31  boost::totally_ordered<ResNum,
32  boost::totally_ordered<ResNum, int,
33  boost::unit_steppable<ResNum> > > >
34 {
35 public:
36  ResNum(int n):
37  num_(n), alt_('\0')
38  { }
39 
40  ResNum(int n, char a):
41  num_(n), alt_(a)
42  {}
43 
44  bool operator==(const ResNum& r) const
45  {
46  return num_==r.num_ && alt_==r.alt_;
47  }
48 
49  bool operator<(const ResNum& r) const
50  {
51  return num_==r.num_ ? alt_<r.alt_ : num_<r.num_;
52  }
53 
54  int operator+=(int i)
55  {
56  num_+=i;
57  return num_;
58  }
59 
60  int operator-=(int i)
61  {
62  num_-=i;
63  return num_;
64  }
65 
66  int operator+=(const ResNum& r)
67  {
68  num_+=r.num_;
69  return num_;
70  }
71 
72  int operator-=(const ResNum& r)
73  {
74  num_-=r.num_;
75  return num_;
76  }
77 
78  ResNum& operator++()
79  {
80  ++num_;
81  return *this;
82  }
83 
84  ResNum& operator--()
85  {
86  --num_;
87  return *this;
88  }
89 
90  ResNum NextInsertionCode() const
91  {
92  char alt= alt_=='\0' ? 'a' : alt_+1;
93  ResNum nrvo(num_,alt);
94  return nrvo;
95  }
96 
102  inline String AsString() const;
103 
104  int GetNum() const { return num_; }
105 
106  void SetNum(int num) { num_=num; }
107 
108  void SetInsCode(char ins_code) { alt_=ins_code; }
109 
110  char GetInsCode() const { return alt_; }
111 
112 private:
113  int num_ : 24;
114  int alt_ : 8;
115 };
116 
118 
119 inline std::ostream& operator<<(std::ostream& os, const ResNum& n)
120 {
121  return os << n.GetNum();
122  if (n.GetInsCode()!='\0')
123  os << n.GetInsCode();
124  return os;
125 }
126 
127 inline String ResNum::AsString() const
128 {
129  std::stringstream ss;
130  ss << *this;
131  return ss.str();
132 }
133 
134 }} // ns
135 
136 
137 #endif