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-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::additive<ResNum,
32  boost::totally_ordered<ResNum,
33  boost::totally_ordered<ResNum, int,
34  boost::unit_steppable<ResNum> > > > >
35 {
36 public:
37 
38  // needed to wrap certain map classes
39  ResNum():
40  num_(1),alt_('\0')
41  {}
42 
43  ResNum(int n):
44  num_(n), alt_('\0')
45  { }
46 
47  ResNum(int n, char a):
48  num_(n), alt_(a)
49  {}
50 
51  bool operator==(const ResNum& r) const
52  {
53  return num_==r.num_ && alt_==r.alt_;
54  }
55 
56  bool operator<(const ResNum& r) const
57  {
58  return num_==r.num_ ? alt_<r.alt_ : num_<r.num_;
59  }
60 
61  int operator+=(int i)
62  {
63  num_+=i;
64  return num_;
65  }
66 
67  int operator-=(int i)
68  {
69  num_-=i;
70  return num_;
71  }
72 
73  int operator+=(const ResNum& r)
74  {
75  num_+=r.num_;
76  return num_;
77  }
78 
79  int operator-=(const ResNum& r)
80  {
81  num_-=r.num_;
82  return num_;
83  }
84 
85  ResNum& operator++()
86  {
87  ++num_;
88  return *this;
89  }
90 
91  ResNum& operator--()
92  {
93  --num_;
94  return *this;
95  }
96 
97  ResNum NextInsertionCode() const
98  {
99  char alt= alt_=='\0' ? 'a' : alt_+1;
100  ResNum nrvo(num_,alt);
101  return nrvo;
102  }
103 
109  inline String AsString() const;
110 
111  int GetNum() const { return num_; }
112 
113  void SetNum(int num) { num_=num; }
114 
115  void SetInsCode(char ins_code) { alt_=ins_code; }
116 
117  char GetInsCode() const { return alt_; }
118 
119 private:
120  int num_ : 24;
121  int alt_ : 8;
122 };
123 
125 
126 inline std::ostream& operator<<(std::ostream& os, const ResNum& n)
127 {
128  return os << n.GetNum();
129  if (n.GetInsCode()!='\0')
130  os << n.GetInsCode();
131  return os;
132 }
133 
134 inline String ResNum::AsString() const
135 {
136  std::stringstream ss;
137  ss << *this;
138  return ss.str();
139 }
140 
141 }} // ns
142 
143 
144 #endif