ProteoWizard
Reader.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Origional author: Robert Burke <robert.burke@proteowizard.org>
6//
7// Copyright 2009 Spielberg Family Center for Applied Proteomics
8// University of Southern California, Los Angeles, California 90033
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 _MZID_READER_HPP_
25#define _MZID_READER_HPP_
26
28#include "IdentData.hpp"
29#include <string>
30#include <stdexcept>
32
33
34namespace pwiz {
35namespace identdata {
36
37/// interface for file readers
39{
40 public:
41
42
43 /// HACK: provide an option to read only file-level metadata;
44 /// once we have an enumerable ResultList implementation
45 /// this will be deprecated
47 {
51
52 Config(bool ignoreSequenceCollectionAndAnalysisData = false, bool ignoreProteinDetectionList = false)
53 : ignoreSequenceCollectionAndAnalysisData(ignoreSequenceCollectionAndAnalysisData),
54 ignoreProteinDetectionList(ignoreProteinDetectionList),
55 iterationListenerRegistry(NULL)
56 {}
57 };
58
59
60 /// return true iff Reader recognizes the file as one it should handle
61 /// that's not to say one it CAN handle, necessarily, as in Thermo on linux,
62 /// see comment for identify() below
63 bool accept(const std::string& filename,
64 const std::string& head) const
65 {
66 return (identify(filename,head).length() != 0);
67 }
68
69 /// return file type iff Reader recognizes the file, else empty;
70 /// note: for formats requiring a 3rd party DLL identify() should
71 /// return true if it recognized the format, even though reading
72 /// may fail if the 3rd party DLL isn't actually present
73 /// Reader may filter based on filename and/or head of the file
74 virtual std::string identify(const std::string& filename,
75 const std::string& head) const = 0;
76
77 /// fill in a vector of IdentData structures; provides support for multi-run input files
78 virtual void read(const std::string& filename,
79 IdentData& results,
80 const Config& config = Config()) const;
81
82 /// fill in a vector of IdentData structures; provides support for multi-run input files
83 virtual void read(const std::string& filename,
84 const std::string& head,
85 IdentData& results,
86 const Config& config = Config()) const = 0;
87
88 /// fill in a vector of IdentData structures; provides support for multi-run input files
89 virtual void read(const std::string& filename,
90 IdentDataPtr& results,
91 const Config& config = Config()) const;
92
93 /// fill in a vector of IdentData structures; provides support for multi-run input files
94 virtual void read(const std::string& filename,
95 const std::string& head,
96 IdentDataPtr& results,
97 const Config& config = Config()) const = 0;
98
99 /// fill in a vector of IdentData structures; provides support for multi-run input files
100 virtual void read(const std::string& filename,
101 const std::string& head,
102 std::vector<IdentDataPtr>& results,
103 const Config& config = Config()) const = 0;
104
105 virtual const char *getType() const = 0; // what kind of reader are you?
106
107 virtual ~Reader(){}
108};
109
110typedef boost::shared_ptr<Reader> ReaderPtr;
111
112class PWIZ_API_DECL ReaderFail : public std::runtime_error // reader failure exception
113{
114 public:
115
116 ReaderFail(const std::string& error)
117 : std::runtime_error(("[ReaderFail] " + error).c_str()),
118 error_(error)
119 {}
120
121 virtual const std::string& error() const {return error_;}
122 virtual ~ReaderFail() throw() {}
123
124 private:
125 std::string error_;
126};
127
128typedef boost::shared_ptr<Reader> ReaderPtr;
129
130
131///
132/// Reader container (composite pattern).
133///
134/// The template get<reader_type>() gives access to child Readers by type, to facilitate
135/// Reader-specific configuration at runtime.
136///
138 public std::vector<ReaderPtr>
139{
140 public:
141
142 /// returns child name iff some child identifies, else empty string
143 virtual std::string identify(const std::string& filename) const;
144
145 /// returns child name iff some child identifies, else empty string
146 virtual std::string identify(const std::string& filename,
147 const std::string& head) const;
148
149 /// delegates to first child that identifies
150 virtual void read(const std::string& filename,
151 IdentData& result,
152 const Config& config = Config()) const;
153
154 /// delegates to first child that identifies
155 virtual void read(const std::string& filename,
156 const std::string& head,
157 IdentData& result,
158 const Config& config = Config()) const;
159
160 /// delegates to first child that identifies
161 virtual void read(const std::string& filename,
162 IdentDataPtr& result,
163 const Config& config = Config()) const;
164
165 /// delegates to first child that identifies
166 virtual void read(const std::string& filename,
167 const std::string& head,
168 IdentDataPtr& result,
169 const Config& config = Config()) const;
170
171 /// delegates to first child that identifies;
172 /// provides support for multi-run input files
173 virtual void read(const std::string& filename,
174 std::vector<IdentDataPtr>& results,
175 const Config& config = Config()) const;
176
177 /// delegates to first child that identifies;
178 /// provides support for multi-run input files
179 virtual void read(const std::string& filename,
180 const std::string& head,
181 std::vector<IdentDataPtr>& results,
182 const Config& config = Config()) const;
183
184 /// appends all of the rhs operand's Readers to the list
185 ReaderList& operator +=(const ReaderList& rhs);
186
187 /// appends the rhs Reader to the list
188 ReaderList& operator +=(const ReaderPtr& rhs);
189
190 /// returns a concatenated list of all the Readers from the lhs and rhs operands
191 ReaderList operator +(const ReaderList& rhs) const;
192
193 /// returns a concatenated list of all the Readers from the lhs and rhs operands
194 ReaderList operator +(const ReaderPtr& rhs) const;
195
196 /// returns pointer to Reader of the specified type
197 template <typename reader_type>
198 reader_type* get()
199 {
200 for (iterator it=begin(); it!=end(); ++it)
201 {
202 reader_type* p = dynamic_cast<reader_type*>(it->get());
203 if (p) return p;
204 }
205
206 return 0;
207 }
208
209 /// returns const pointer to Reader of the specified type
210 template <typename reader_type>
211 const reader_type* get() const
212 {
213 return const_cast<ReaderList*>(this)->get<reader_type>();
214 }
215
216 virtual const char *getType() const {return "ReaderList";} // satisfy inheritance
217
218};
219
220
221/// returns a list containing the lhs and rhs as readers
223
224
225} // namespace identdata
226} // namespace pwiz
227
228
229#endif // _MZID_READER_HPP_
#define PWIZ_API_DECL
Definition Export.hpp:32
ReaderFail(const std::string &error)
Definition Reader.hpp:116
virtual const std::string & error() const
Definition Reader.hpp:121
interface for file readers
Definition Reader.hpp:39
virtual void read(const std::string &filename, const std::string &head, std::vector< IdentDataPtr > &results, const Config &config=Config()) const =0
fill in a vector of IdentData structures; provides support for multi-run input files
virtual std::string identify(const std::string &filename, const std::string &head) const =0
return file type iff Reader recognizes the file, else empty;
virtual void read(const std::string &filename, IdentDataPtr &results, const Config &config=Config()) const
fill in a vector of IdentData structures; provides support for multi-run input files
bool accept(const std::string &filename, const std::string &head) const
return true iff Reader recognizes the file as one it should handle
Definition Reader.hpp:63
virtual void read(const std::string &filename, const std::string &head, IdentDataPtr &results, const Config &config=Config()) const =0
fill in a vector of IdentData structures; provides support for multi-run input files
virtual const char * getType() const =0
virtual void read(const std::string &filename, const std::string &head, IdentData &results, const Config &config=Config()) const =0
fill in a vector of IdentData structures; provides support for multi-run input files
virtual void read(const std::string &filename, IdentData &results, const Config &config=Config()) const
fill in a vector of IdentData structures; provides support for multi-run input files
Reader container (composite pattern).
Definition Reader.hpp:139
virtual const char * getType() const
Definition Reader.hpp:216
virtual void read(const std::string &filename, std::vector< IdentDataPtr > &results, const Config &config=Config()) const
delegates to first child that identifies; provides support for multi-run input files
virtual std::string identify(const std::string &filename, const std::string &head) const
returns child name iff some child identifies, else empty string
reader_type * get()
returns pointer to Reader of the specified type
Definition Reader.hpp:198
virtual void read(const std::string &filename, const std::string &head, IdentDataPtr &result, const Config &config=Config()) const
delegates to first child that identifies
const reader_type * get() const
returns const pointer to Reader of the specified type
Definition Reader.hpp:211
virtual void read(const std::string &filename, IdentDataPtr &result, const Config &config=Config()) const
delegates to first child that identifies
virtual std::string identify(const std::string &filename) const
returns child name iff some child identifies, else empty string
virtual void read(const std::string &filename, IdentData &result, const Config &config=Config()) const
delegates to first child that identifies
virtual void read(const std::string &filename, const std::string &head, IdentData &result, const Config &config=Config()) const
delegates to first child that identifies
virtual void read(const std::string &filename, const std::string &head, std::vector< IdentDataPtr > &results, const Config &config=Config()) const
delegates to first child that identifies; provides support for multi-run input files
handles registration of IterationListeners and broadcast of update messages
boost::shared_ptr< IdentData > IdentDataPtr
PWIZ_API_DECL ReaderList operator+(const ReaderPtr &lhs, const ReaderPtr &rhs)
returns a list containing the lhs and rhs as readers
boost::shared_ptr< Reader > ReaderPtr
Definition Reader.hpp:110
STL namespace.
Implementation of the MzIdentMLType from the mzIdentML schema.
HACK: provide an option to read only file-level metadata; once we have an enumerable ResultList imple...
Definition Reader.hpp:47
const pwiz::util::IterationListenerRegistry * iterationListenerRegistry
Definition Reader.hpp:50
Config(bool ignoreSequenceCollectionAndAnalysisData=false, bool ignoreProteinDetectionList=false)
Definition Reader.hpp:52