1// This file contains boilerplate code for static writer functions in all
2// classes inheriting from Writer. These methods just forward to the methods on
3// the Writer base class, but code duplication can't be avoided without a
4// preprocessor hack like this, AFAIK.
6/// @name Writing a single analysis object.
9/// Write out object @a ao to output stream @a stream.
10static void write(std::ostream& stream, const AnalysisObject& ao) {
11 create().write(stream, ao);
14/// Write out pointer-like object @a ao to output stream @a stream.
16static typename std::enable_if<DerefableToAO<T>::value>::type //< -> void if valid
17write(std::ostream& stream, const T& ao, int precision=-1) { write(stream, *ao, precision); }
19/// Write out object @a ao to file @a filename.
20static void write(const std::string& filename, const AnalysisObject& ao, int precision=-1) {
21 const size_t lastdot = filename.find_last_of(".");
22 std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
23 const bool compress = (fmt == "gz");
25 if (precision > 0) w.setPrecision(precision);
26 w.useCompression(compress);
27 w.write(filename, ao);
30/// Write out pointer-like object @a ao to file @a filename.
32static typename std::enable_if<DerefableToAO<T>::value>::type //< -> void if valid
33write(const std::string& filename, const T& ao, int precision=-1) { write(filename, *ao, precision); }
38/// @name Writing multiple analysis objects by collection.
41template <typename RANGE>
42static typename std::enable_if<CIterable<RANGE>::value>::type
43write(std::ostream& stream, const RANGE& aos, int precision=-1) {
44 create().write(stream, std::begin(aos), std::end(aos), precision);
47template <typename RANGE>
48static typename std::enable_if<CIterable<RANGE>::value>::type
49write(const std::string& filename, const RANGE& aos, int precision=-1) {
50 const size_t lastdot = filename.find_last_of(".");
51 std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
52 const bool compress = (fmt == "gz");
54 if (precision > 0) w.setPrecision(precision);
55 w.useCompression(compress);
56 w.write(filename, std::begin(aos), std::end(aos));
62/// @name Writing multiple analysis objects by iterator range.
65/// Write out the objects specified by start iterator @a begin and end
66/// iterator @a end to output stream @a stream.
68/// @todo Add SFINAE trait checking for AOITER = DerefableToAO
69template <typename AOITER>
70static void write(std::ostream& stream, const AOITER& begin, const AOITER& end, int precision=-1) {
71 create().write(stream, begin, end, precision);
74/// Write out the objects specified by start iterator @a begin and end
75/// iterator @a end to file @a filename.
77/// @todo Add SFINAE trait checking for AOITER = DerefableToAO
78template <typename AOITER>
79static void write(const std::string& filename, const AOITER& begin, const AOITER& end, int precision=-1) {
80 const size_t lastdot = filename.find_last_of(".");
81 std::string fmt = Utils::toLower(lastdot == std::string::npos ? filename : filename.substr(lastdot+1));
82 const bool compress = (fmt == "gz");
84 if (precision > 0) w.setPrecision(precision);
85 w.useCompression(compress);
86 w.write(filename, begin, end);