forked from plumed/plumed2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtomNumber.h
154 lines (129 loc) · 4.23 KB
/
AtomNumber.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Copyright (c) 2011-2016 The plumed team
(see the PEOPLE file at the root of the distribution for a list of names)
See http://www.plumed.org for more information.
This file is part of plumed, version 2.
plumed is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
plumed is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with plumed. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#ifndef __PLUMED_tools_AtomNumber_h
#define __PLUMED_tools_AtomNumber_h
#include "Exception.h"
#include <limits>
namespace PLMD{
/**
\ingroup TOOLBOX
Simple class to store the index of an atom.
It is just an unsigned, with all the methods inlined for better efficiency.
Its special thing is that it is only accessed through serial(), index(),
setSerial() and setIndex() methods, so that there
no ambiguity about using the "from 0" (index) or
"from 1" (serial) numbering (names as in VMD convention).
*/
class AtomNumber{
unsigned index_;
/// Construct with a given index.
/// This constructor is kept private to avoid implicit cast.
explicit AtomNumber(unsigned);
public:
/// Initialize to index=0 (serial=1)
// The following line triggers a warning in cppcheck,
// cppcheck-suppress noExplicitConstructor
AtomNumber();
/// Returns the serial number
unsigned serial()const;
/// Returns the index number
unsigned index()const;
/// Sets the atom number by serial, returning a reference to the AtomNumber itself.
AtomNumber & setSerial(unsigned);
/// Sets the atom number by index, returning a reference to the AtomNumber itself.
AtomNumber & setIndex(unsigned);
/// Returns an AtomNumber with a specified serial.
static AtomNumber serial(unsigned);
/// Returns an AtomNumber with a specified index.
static AtomNumber index(unsigned);
/// Comparison operators
friend bool operator<(const AtomNumber&,const AtomNumber&);
/// Comparison operators
friend bool operator>(const AtomNumber&,const AtomNumber&);
/// Comparison operators
friend bool operator<=(const AtomNumber&,const AtomNumber&);
/// Comparison operators
friend bool operator>=(const AtomNumber&,const AtomNumber&);
/// Comparison operators
friend bool operator==(const AtomNumber&,const AtomNumber&);
/// Comparison operators
friend bool operator!=(const AtomNumber&,const AtomNumber&);
};
inline
AtomNumber::AtomNumber(){
index_=0;
}
inline
AtomNumber::AtomNumber(unsigned i){
index_=i;
}
inline
unsigned AtomNumber::serial()const{
return index_+1;
}
inline
unsigned AtomNumber::index()const{
return index_;
}
inline
AtomNumber & AtomNumber::setSerial(unsigned i){
plumed_massert(i>0,"serial of an atom cannot be zero");
plumed_massert(i<std::numeric_limits<unsigned>::max()/2,"serial cannot be negative");
index_=i-1;
return *this;
}
inline
AtomNumber & AtomNumber::setIndex(unsigned i){
index_=i;
return *this;
}
inline
AtomNumber AtomNumber::serial(unsigned i){
plumed_massert(i>0,"serial of an atom cannot be zero");
plumed_massert(i<std::numeric_limits<unsigned>::max()/2,"serial cannot be negative");
return AtomNumber(i-1);
}
inline
AtomNumber AtomNumber::index(unsigned i){
return AtomNumber(i);
}
inline
bool operator<(const AtomNumber&a,const AtomNumber&b){
return a.index_<b.index_;
}
inline
bool operator>(const AtomNumber&a,const AtomNumber&b){
return a.index_>b.index_;
}
inline
bool operator<=(const AtomNumber&a,const AtomNumber&b){
return a.index_<=b.index_;
}
inline
bool operator>=(const AtomNumber&a,const AtomNumber&b){
return a.index_>=b.index_;
}
inline
bool operator==(const AtomNumber&a,const AtomNumber&b){
return a.index_==b.index_;
}
inline
bool operator!=(const AtomNumber&a,const AtomNumber&b){
return a.index_!=b.index_;
}
}
#endif