lsst.astshim  master-gd1207e8857
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Channel.h
1 /*
2  * LSST Data Management System
3  * Copyright 2016 AURA/LSST.
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 <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #ifndef ASTSHIM_CHANNEL_H
23 #define ASTSHIM_CHANNEL_H
24 
25 #include <memory>
26 #include <ostream>
27 
28 #include "astshim/base.h"
29 #include "astshim/Object.h"
30 #include "astshim/Stream.h"
31 
32 namespace ast {
33 
34 class KeyMap;
35 
60 class Channel : public Object {
61 friend class Object;
62 public:
73  explicit Channel(Stream & stream, std::string const & options="");
74 
75  virtual ~Channel();
76 
77  Channel(Channel const &) = delete;
78  Channel(Channel &&) = default;
79  Channel & operator=(Channel const &) = delete;
80  Channel & operator=(Channel &&) = default;
81 
83  std::shared_ptr<Channel> copy() const {
84  throw std::logic_error(
85  "Channel cannot be deep copied because its contained stream cannot be deep copied");
86  }
87 
89  bool getComment() const { return getB("Comment"); }
90 
92  int getFull() const { return getI("Full"); }
93 
95  int getIndent() const { return getB("Indent"); }
96 
98  int getReportLevel() const { return getI("ReportLevel"); }
99 
101  bool getSkip() const { return getB("Skip"); }
102 
104  bool getStrict() const { return getB("Strict"); }
105 
107  std::shared_ptr<Object> read();
108 
110  void setComment(bool skip) { setB("Comment", skip); }
111 
113  void setFull(int full) { setI("Full", full); }
114 
116  void setIndent(int indent) { setI("Indent", indent); }
117 
124  void setReportLevel(int level) {
125  if ((level < 0) || (level > 3)) {
126  std::ostringstream os;
127  os << "level = " << level << " not in range [0, 3]";
128  throw std::invalid_argument(os.str());
129  }
130  setI("ReportLevel", level);
131  }
132 
134  void setSkip(bool skip) { setB("Skip", skip); }
135 
137  void setStrict(bool strict) { setB("Strict", strict); }
138 
152  KeyMap warnings() const;
153 
155  int write(Object const & object);
156 
157 protected:
158  virtual std::shared_ptr<Object> _copyPolymorphic() const override {
159  return std::shared_ptr<Object>();
160  }
161 
167  explicit Channel(AstChannel * chan, Stream & stream);
168 
172  explicit Channel(AstChannel * chan);
173 
175 };
176 
177 } // namespace ast
178 
179 #endif
std::shared_ptr< Channel > copy() const
Return a deep copy of this object.
Definition: Channel.h:83
Stream _stream
stream read and/or written read by the channel
Definition: Channel.h:174
void setI(std::string const &attrib, int value)
Definition: Object.h:483
bool getComment() const
Get Comment: include textual comments in output?
Definition: Channel.h:89
Channel(Stream &stream, std::string const &options="")
Definition: Channel.cc:31
KeyMap warnings() const
Definition: Channel.cc:74
void setIndent(int indent)
Set Indent: indentation increment between objects.
Definition: Channel.h:116
int write(Object const &object)
Write an object to a channel.
Definition: Channel.cc:68
int getReportLevel() const
Get ReportLevel: report level.
Definition: Channel.h:98
void setB(std::string const &attrib, bool value)
Definition: Object.h:435
Definition: Object.h:49
virtual std::shared_ptr< Object > _copyPolymorphic() const override
Definition: Channel.h:158
int getIndent() const
Get Indent: indentation increment between objects.
Definition: Channel.h:95
std::shared_ptr< Object > read()
Read an object from a channel.
Definition: Channel.cc:60
void setSkip(bool skip)
Set Skip: skip irrelevant data on input?
Definition: Channel.h:134
int getFull() const
Get Full: level of output detail; one of -1: minimum, 0: normal, 1: verbose.
Definition: Channel.h:92
Definition: Stream.h:41
bool getSkip() const
Get Skip: skip irrelevant data on input?
Definition: Channel.h:101
bool getStrict() const
Get Strict: generate errors instead of warnings?
Definition: Channel.h:104
void setStrict(bool strict)
Set Strict: generate errors instead of warnings?
Definition: Channel.h:137
void setComment(bool skip)
Set Comment: include textual comments in output?
Definition: Channel.h:110
int getI(std::string const &attrib) const
Definition: Object.h:386
bool getB(std::string const &attrib) const
Definition: Object.h:334
void setReportLevel(int level)
Definition: Channel.h:124
Definition: Channel.h:60
Definition: KeyMap.h:82
void setFull(int full)
Set Full: level of output detail; one of -1: minimum, 0: normal, 1: verbose.
Definition: Channel.h:113