LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
PropertyPrinter.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
28 #include "lsst/daf/base/DateTime.h"
29 #include <boost/any.hpp>
30 
31 namespace lsst {
32 namespace pex {
33 namespace logging {
34 
35 //@cond
36 using std::vector;
37 using std::ostream;
40 
42 
44 
45 std::ostream& WrappedPrinterIter::write(std::ostream *strm) const {
46  _it.get()->write(strm);
47  return *strm;
48 }
49 
50 PrinterIter& WrappedPrinterIter::operator++() { ++(*_it); return *_it; }
51 PrinterIter& WrappedPrinterIter::operator--() { --(*_it); return *_it; }
52 bool WrappedPrinterIter::operator==(const PrinterIter& that) const {
53  return (*_it == that);
54 }
55 bool WrappedPrinterIter::operator!=(const PrinterIter& that) const {
56  return (*_it == that);
57 }
58 bool WrappedPrinterIter::notAtEnd() const {
59  return _it.get()->notAtEnd();
60 }
61 bool WrappedPrinterIter::notLTBegin() const {
62  return _it.get()->notLTBegin();
63 }
64 
66 
68 
69 std::ostream& DateTimePrinterIter::write(std::ostream *strm) const {
70  (*strm) << _it->nsecs();
71  return *strm;
72 }
73 
75 
77  PrinterIter *it = new DateTimePrinterIter(_list.begin(),
78  _list.begin(), _list.end());
79  return iterator(boost::shared_ptr<PrinterIter>(it));
80 }
82  PrinterIter *it = new DateTimePrinterIter(_list.end()-1,
83  _list.begin(), _list.end());
84  return iterator(boost::shared_ptr<PrinterIter>(it));
85 }
86 
87 PrinterList* makeDateTimePrinter(const PropertySet& prop,
88  const std::string& name)
89 {
90  return new DateTimePrinterList(prop, name);
91 }
92 
94 
95 std::ostream& BoolPrinterIter::write(std::ostream *strm) const {
96  (*strm) << ((*_it) ? "true" : "false");
97  return *strm;
98 }
99 
101 
103  PrinterIter *it = new BoolPrinterIter(_list.begin(),
104  _list.begin(), _list.end());
105  return iterator(boost::shared_ptr<PrinterIter>(it));
106 }
108  PrinterIter *it = new BoolPrinterIter(_list.end()-1,
109  _list.begin(), _list.end());
110  return iterator(boost::shared_ptr<PrinterIter>(it));
111 }
112 
113 PrinterList* makeBoolPrinter(const PropertySet& prop,
114  const std::string& name)
115 {
116  return new BoolPrinterList(prop, name);
117 }
118 
119 #define PF_ADD(T) add(typeid(T), &lsst::pex::logging::makePrinter<T>)
120 
122  PF_ADD(short);
123  PF_ADD(int);
124  PF_ADD(long);
125  PF_ADD(long long);
126  PF_ADD(float);
127  PF_ADD(double);
128  PF_ADD(char);
129  PF_ADD(signed char);
130  PF_ADD(unsigned char);
131  PF_ADD(std::string);
132  add(typeid(bool), makeBoolPrinter);
133  add(typeid(DateTime), makeDateTimePrinter);
134 }
135 
136 PrinterFactory PropertyPrinter::defaultPrinterFactory(true);
137 
139  const std::string& name,
140  const PrinterFactory& fact)
141  : _list(fact.makePrinter(prop, name))
142 {
143  if (_list.get() == 0) {
144  PropertySet tmp;
145  tmp.set(name, "<unprintable>");
146  _list = boost::shared_ptr<PrinterList>(fact.makePrinter(tmp, name));
147  }
148 }
149 
151  return _list.get()->begin();
152 }
153 
155  return _list.get()->last();
156 }
157 
158 //@endcond
159 }}} // end lsst::pex::logging
160 
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:58
table::Key< std::string > name
Definition: ApCorrMap.cc:71
virtual bool operator==(const PrinterIter &that) const
PropertyPrinter(const lsst::daf::base::PropertySet &prop, const std::string &name, const PrinterFactory &fact=defaultPrinterFactory)
virtual iterator last() const
virtual PrinterIter & operator--()
virtual std::ostream & write(std::ostream *strm) const
void add(const std::type_info &tp, factoryFuncPtr func)
virtual iterator begin() const
PrinterList * makeBoolPrinter(const lsst::daf::base::PropertySet &prop, const std::string &name)
void set(std::string const &name, T const &value)
Definition: PropertySet.cc:581
PrinterList * makePrinter(const lsst::daf::base::PropertySet &prop, const std::string &name)
the template factory function for supporting printing of printable types
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:58
PrinterList * makeDateTimePrinter(const lsst::daf::base::PropertySet &prop, const std::string &name)
virtual std::ostream & write(std::ostream *strm) const
std::vector< lsst::daf::base::DateTime >::const_iterator _it
definition of the PropertyPrinter class and its helpers
virtual bool operator!=(const PrinterIter &that) const
boost::shared_ptr< PrinterList > _list
Interface for DateTime class.
virtual std::ostream & write(std::ostream *strm) const
virtual iterator begin() const
boost::shared_ptr< PrinterIter > _it
virtual PrinterIter & operator++()
Class for storing generic metadata.
Definition: PropertySet.h:82
static PrinterFactory defaultPrinterFactory
virtual iterator last() const