ProteoWizard
Main Page
Namespaces
Classes
Files
File List
File Members
pwiz
data
misc
SampleDatum.hpp
Go to the documentation of this file.
1
//
2
// $Id: SampleDatum.hpp 1195 2009-08-14 22:12:04Z chambm $
3
//
4
//
5
// Original author: Darren Kessner <darren@proteowizard.org>
6
//
7
// Copyright 2006 Louis Warschaw Prostate Cancer Center
8
// Cedars Sinai Medical Center, Los Angeles, California 90048
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
24
#ifndef _SAMPLEDATUM_HPP_
25
#define _SAMPLEDATUM_HPP_
26
27
28
#include "
pwiz/utility/misc/Export.hpp
"
29
#include <iostream>
30
#include <iomanip>
31
#include <sstream>
32
#include <stdexcept>
33
34
35
namespace
pwiz {
36
namespace
data {
37
38
39
template
<
typename
abscissa_type,
typename
ordinate_type>
40
struct
SampleDatum
41
{
42
abscissa_type
x
;
43
ordinate_type
y
;
44
45
SampleDatum
(abscissa_type _x=0, ordinate_type _y=0)
46
:
x
(_x),
y
(_y)
47
{}
48
};
49
50
51
template
<
typename
abscissa_type,
typename
ordinate_type>
52
bool
operator==
(
const
SampleDatum<abscissa_type,ordinate_type>
& a,
53
const
SampleDatum<abscissa_type,ordinate_type>
& b)
54
{
55
return
(a.
x
==b.
x
&& a.
y
==b.
y
);
56
}
57
58
59
namespace
SampleDatumConstant
60
{
61
const
char
open_
=
'<'
;
62
const
char
separator_
=
';'
;
// MSVC feature: this cannot be ','
63
const
char
close_
=
'>'
;
64
}
// namespace SampleDatumConstant
65
66
67
template
<
typename
abscissa_type,
typename
ordinate_type>
68
std::ostream& operator<<(std::ostream& os, const SampleDatum<abscissa_type,ordinate_type>& datum)
69
{
70
os <<
SampleDatumConstant::open_
71
<< datum.x
72
<<
SampleDatumConstant::separator_
73
<< datum.y
74
<<
SampleDatumConstant::close_
;
75
76
return
os;
77
}
78
79
80
template
<
typename
abscissa_type,
typename
ordinate_type>
81
std::istream&
operator>>
(std::istream& is,
SampleDatum<abscissa_type,ordinate_type>
& datum)
82
{
83
std::string buffer;
84
is >> buffer;
85
if
(!is)
return
is;
86
87
std::istringstream iss(buffer);
88
89
char
open, separator, close;
90
abscissa_type
x
;
91
ordinate_type
y
;
92
iss >> open >> x >> separator >> y >> close;
93
94
if
(open !=
SampleDatumConstant::open_
||
95
separator !=
SampleDatumConstant::separator_
||
96
close !=
SampleDatumConstant::close_
)
97
throw
std::runtime_error(
"[SampleDatum::operator>>] Invalid format."
);
98
99
datum.
x
=
x
;
100
datum.
y
=
y
;
101
102
return
is;
103
}
104
105
106
}
// namespace data
107
}
// namespace pwiz
108
109
110
#endif // _SAMPLEDATUM_HPP_
111
112
Generated on Mon Nov 26 2012 18:05:48 for ProteoWizard by
1.8.1.1