24 #ifndef _TEXTWRITER_HPP_
25 #define _TEXTWRITER_HPP_
30 #include "boost/lexical_cast.hpp"
48 TextWriter(std::ostream& os,
int depth = 0,
int arrayExampleCount = 3)
51 arrayExampleCount_(arrayExampleCount < 0 ? std::numeric_limits<size_t>::
max()
52 : (size_t) arrayExampleCount),
60 os_ << indent_ << text << std::endl;
67 if (!cvParam.
value.empty())
77 os_ << indent_ <<
"userParam: " << userParam.
name;
79 if (!userParam.
type.empty())
os_ <<
", " << userParam.
type;
85 template<
typename object_type>
86 TextWriter& operator()(
const std::string& label,
const std::vector<object_type>& v)
89 for_each(v.begin(), v.end(), child());
102 child()(
"version: " + msd.
version());
103 if (!msd.
cvs.empty())
104 child()(
"cvList: ", msd.
cvs);
121 child()(msd.
run, metadata_only);
139 (*this)(
"fileDescription:");
149 for (std::vector<ParamGroupPtr>::const_iterator it=paramContainer.
paramGroupPtrs.begin();
151 (*
this)(
"referenceableParamGroupRef: " + (*it)->id);
152 for_each(paramContainer.
cvParams.begin(), paramContainer.
cvParams.end(), *
this);
159 (*this)(
"fileContent:");
166 (*this)(
"sourceFile:");
171 (static_cast<const ParamContainer&>(sf));
184 (*this)(
"paramGroup:");
186 (
"id: " + paramGroup.
id)
187 (static_cast<const ParamContainer&>(paramGroup));
196 (
"name: " + sample.
name)
203 (*this)(
"instrumentConfiguration:");
205 (
"id: " + instrumentConfiguration.
id)
206 (static_cast<const ParamContainer&>(instrumentConfiguration));
210 child()(
"softwareRef: " + instrumentConfiguration.
softwarePtr->id);
216 (*this)(
"componentList:");
217 for (
size_t i=0; i < componentList.size(); ++i)
218 child()(componentList[i]);
224 switch(component.
type)
230 (*this)(
"analyzer: ");
233 (*this)(
"detector: ");
246 (*this)(
"software:");
248 (
"id: " + software.
id)
249 (
"version: " + software.
version)
256 (*this)(
"processingMethod:");
260 child()(
"softwareRef: " + processingMethod.
softwarePtr->id);
268 (*this)(
"dataProcessing:");
284 (*this)(
"scanSettings:");
295 child()(
"id: " + run.
id);
299 child()(
"sampleRef: " + run.
samplePtr->id);
314 std::string text(
"spectrumList (" + boost::lexical_cast<std::string>(spectrumList.
size()) +
" spectra)");
324 for (
size_t index=0; index<spectrumList.
size(); ++index)
326 (*spectrumList.
spectrum(index,
true));
332 return p.get() ? (*this)(*p, metadata_only) : *
this;
337 std::string text(
"chromatogramList (" + boost::lexical_cast<std::string>(chromatogramList.
size()) +
" chromatograms)");
347 for (
size_t index=0; index<chromatogramList.
size(); ++index)
355 return p.get() ? (*this)(*p, metadata_only) : *
this;
360 (*this)(
"spectrum:");
363 (
"id: " + spectrum.
id);
364 if (!spectrum.
spotID.empty())
365 child()(
"spotID: " + spectrum.
spotID);
371 (static_cast<const ParamContainer&>(spectrum));
375 child()(
"precursorList: ", spectrum.
precursors);
382 (*this)(
"chromatogram:");
385 (
"id: " + chromatogram.
id)
386 (
"defaultArrayLength: " + boost::lexical_cast<std::string>(chromatogram.
defaultArrayLength))
405 (*this)(
"scanWindow:");
412 if (!p.get() || p->empty())
return *
this;
414 std::stringstream oss;
417 for (
size_t i=0; i < arrayExampleCount_ && i < p->data.size(); i++)
418 oss << p->data[i] <<
" ";
419 if (p->data.size() > arrayExampleCount_)
422 (*this)(
"binaryDataArray:");
424 if (p->dataProcessingPtr.get() && !p->dataProcessingPtr->empty())
425 child()(p->dataProcessingPtr);
426 if (!p->data.empty())
427 child()(
"binary: " + oss.str());
433 (*this)(
"selectedIon:");
440 (*this)(
"precursor:");
443 (static_cast<const ParamContainer&>(precursor));
447 child()(
"isolationWindow:");
458 child()(
"activation:");
471 child()(
"isolationWindow:");
482 (
"scanList:", scanList.
scans);
487 template<
typename object_type>
488 TextWriter& operator()(
const boost::shared_ptr<object_type>& p)
490 return p.get() ? (*this)(*p) : *
this;
506 #endif // _TEXTWRITER_HPP_