Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+7a5e04273c,g1ec0fe41b4+e220e2fb2f,g1fd858c14a+46aa96e35a,g35bb328faa+fcb1d3bbc8,g4d2262a081+0401f777d9,g53246c7159+fcb1d3bbc8,g56a49b3a55+6dde5ca9af,g60b5630c4e+f81e3c6253,g67b6fd64d1+fad15079a7,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8180f54f50+37e0867462,g824a5327fb+3effcb5f7d,g8352419a5c+fcb1d3bbc8,g8852436030+6fb7fc75dc,g89139ef638+fad15079a7,g9125e01d80+fcb1d3bbc8,g94187f82dc+f81e3c6253,g989de1cb63+fad15079a7,g9ccd5d7f00+cce09d2c12,g9d31334357+f81e3c6253,g9f33ca652e+b134ec2ed3,gabe3b4be73+1e0a283bba,gabf8522325+94c30d56e9,gb1101e3267+afdd7c51d9,gb58c049af0+f03b321e39,gb89ab40317+fad15079a7,gc0af124501+3c4db12c16,gcf25f946ba+6fb7fc75dc,gd6cbbdb0b4+8d7f1baacb,gdb1c4ca869+16879ca1a6,gde0f65d7ad+c1c55904c1,ge1ad929117+f81e3c6253,ge278dab8ac+4d6e48c014,ge410e46f29+fad15079a7,gf5e32f922b+fcb1d3bbc8,gf618743f1b+445e15116c,gf67bdafdda+fad15079a7,w.2025.17
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Channel.cc
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 * Copyright 2017 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
23#include "astshim/base.h"
24#include "astshim/KeyMap.h"
25#include "astshim/Object.h"
26#include "astshim/Stream.h"
27#include "astshim/Channel.h"
28
29namespace ast {
30
32 : Channel(astChannel(detail::source, detail::sink, "%s", options.c_str()), stream) {
33 assertOK();
34}
35
36Channel::Channel(AstChannel *chan, Stream &stream, bool isFits)
37 : Object(reinterpret_cast<AstObject *>(chan)), _stream(stream) {
38 astPutChannelData(getRawPtr(), &_stream);
39 _stream.setIsFits(isFits);
40 assertOK();
41}
42
43Channel::Channel(AstChannel *chan) : Object(reinterpret_cast<AstObject *>(chan)), _stream() { assertOK(); }
44
46 if (_stream.hasStdStream()) {
47 // avoid any attempt to read or write while the stream is being destroyed
48 astPutChannelData(getRawPtr(), nullptr);
49 }
50}
51
53 AstObject *rawRet = reinterpret_cast<AstObject *>(astRead(getRawPtr()));
54 assertOK(rawRet);
55 if (!rawRet) {
56 throw std::runtime_error("Could not read an AST object from this channel");
57 }
58 return Object::fromAstObject<Object>(rawRet, false);
59}
60
61int Channel::write(Object const &object) {
62 int ret = astWrite(getRawPtr(), object.getRawPtr());
63 assertOK();
64 return ret;
65}
66
68 AstKeyMap *rawKeyMap =
69 reinterpret_cast<AstKeyMap *>(astWarnings(reinterpret_cast<AstChannel const *>(getRawPtr())));
70 assertOK();
71 return rawKeyMap ? KeyMap(rawKeyMap) : KeyMap();
72}
73
74} // namespace ast
virtual ~Channel()
Definition Channel.cc:45
friend class Object
Definition Channel.h:61
KeyMap warnings() const
Return a KeyMap holding the text of any warnings issued as a result of the previous invocation of rea...
Definition Channel.cc:67
Channel(Stream &stream, std::string const &options="")
Construct a channel that uses a provided Stream.
Definition Channel.cc:31
std::shared_ptr< Object > read()
Read an object from a channel.
Definition Channel.cc:52
int write(Object const &object)
Write an object to a channel.
Definition Channel.cc:61
KeyMap is used to store a set of values with associated keys which identify the values.
Definition KeyMap.h:83
static std::shared_ptr< Class > fromAstObject(AstObject *rawObj, bool copy)
Given a bare AST object pointer return a shared pointer to an ast::Object of the correct type.
Definition Object.cc:138
AstObject const * getRawPtr() const
Get the raw AST pointer.
Definition Object.h:292
A stream for ast::Channel.
Definition Stream.h:41
AST wrapper classes and functions.
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Throw std::runtime_error if AST's state is bad.
Definition base.cc:49