ProteoWizard
SampleDatum.hpp
Go to the documentation of this file.
1//
2// $Id$
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
29#include <iostream>
30#include <iomanip>
31#include <sstream>
32#include <stdexcept>
33
34
35namespace pwiz {
36namespace data {
37
38
39template<typename abscissa_type, typename ordinate_type>
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
51template<typename abscissa_type, typename ordinate_type>
54{
55 return (a.x==b.x && a.y==b.y);
56}
57
58
59namespace SampleDatumConstant
60{
61 const char open_ = '<';
62 const char separator_ = ';'; // MSVC feature: this cannot be ','
63 const char close_ = '>';
64} // namespace SampleDatumConstant
65
66
67template<typename abscissa_type, typename ordinate_type>
68std::ostream& operator<<(std::ostream& os, const SampleDatum<abscissa_type,ordinate_type>& datum)
69{
71 << datum.x
73 << datum.y
75
76 return os;
77}
78
79
80template<typename abscissa_type, typename ordinate_type>
81std::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_ ||
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
KernelTraitsBase< Kernel >::space_type::abscissa_type x
KernelTraitsBase< Kernel >::space_type::ordinate_type y
std::ostream & operator<<(std::ostream &os, const Diff< object_type, config_type > &diff)
stream insertion of Diff results
Definition diff_std.hpp:200
std::istream & operator>>(std::istream &is, SampleDatum< abscissa_type, ordinate_type > &datum)
bool operator==(const SampleDatum< abscissa_type, ordinate_type > &a, const SampleDatum< abscissa_type, ordinate_type > &b)
SampleDatum(abscissa_type _x=0, ordinate_type _y=0)