ProteoWizard
MZTolerance.hpp
Go to the documentation of this file.
1 //
2 // $Id: MZTolerance.hpp 3317 2012-02-27 16:36:06Z chambm $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2009 Center for Applied Molecular Medicine
8 // University of Southern California, Los Angeles, CA
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 #ifndef _MZTOLERANCE_HPP_
24 #define _MZTOLERANCE_HPP_
25 
26 
28 #include <iosfwd>
29 
30 
31 namespace pwiz {
32 namespace chemistry {
33 
34 
35 ///
36 /// struct for expressing m/z tolerance in either amu or ppm
37 ///
39 {
40  enum Units {MZ, PPM};
41  double value;
43 
44  MZTolerance(double _value = 0, Units _units = MZ)
45  : value(_value), units(_units)
46  {}
47 };
48 
49 
50 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const MZTolerance& mzt);
51 PWIZ_API_DECL std::istream& operator>>(std::istream& is, MZTolerance& mzt);
52 PWIZ_API_DECL bool operator==(const MZTolerance& a, const MZTolerance& b);
53 PWIZ_API_DECL bool operator!=(const MZTolerance& a, const MZTolerance& b);
54 
55 
56 PWIZ_API_DECL double& operator+=(double& d, const MZTolerance& tolerance);
57 PWIZ_API_DECL double& operator-=(double& d, const MZTolerance& tolerance);
58 PWIZ_API_DECL double operator+(double d, const MZTolerance& tolerance);
59 PWIZ_API_DECL double operator-(double d, const MZTolerance& tolerance);
60 
61 
62 /// returns true iff a is in (b-tolerance, b+tolerance)
63 PWIZ_API_DECL bool isWithinTolerance(double a, double b, const MZTolerance& tolerance);
64 /// returns true iff b - a is greater than the value in tolerance (useful for matching sorted mass lists)
65 PWIZ_API_DECL bool lessThanTolerance(double a, double b, const MZTolerance& tolerance);
66 
67 
68 } // namespace chemistry
69 } // namespace pwiz
70 
71 
72 #endif // _MZTOLERANCE_HPP_
73