lsst.astshim
gf5dcc679e7+7aca86229d
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Object.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
#include <algorithm>
23
#include <functional>
24
#include <ostream>
25
#include <sstream>
26
#include <stdexcept>
27
#include <string>
28
#include <unordered_map>
29
30
#include "
astshim/base.h
"
31
#include "
astshim/detail/utils.h
"
32
#include "
astshim/Object.h
"
33
#include "
astshim/Channel.h
"
34
#include "
astshim/ChebyMap.h
"
35
#include "
astshim/CmpFrame.h
"
36
#include "
astshim/FitsChan.h
"
37
#include "
astshim/FitsTable.h
"
38
#include "
astshim/Frame.h
"
39
#include "
astshim/FrameSet.h
"
40
#include "
astshim/FrameDict.h
"
41
#include "
astshim/KeyMap.h
"
42
#include "
astshim/LutMap.h
"
43
#include "
astshim/MathMap.h
"
44
#include "
astshim/MatrixMap.h
"
45
#include "
astshim/NormMap.h
"
46
#include "
astshim/ParallelMap.h
"
47
#include "
astshim/PcdMap.h
"
48
#include "
astshim/PermMap.h
"
49
#include "
astshim/PolyMap.h
"
50
#include "
astshim/RateMap.h
"
51
#include "
astshim/SeriesMap.h
"
52
#include "
astshim/ShiftMap.h
"
53
#include "
astshim/SkyFrame.h
"
54
#include "
astshim/SlaMap.h
"
55
#include "
astshim/SpecFrame.h
"
56
#include "
astshim/SphMap.h
"
57
#include "
astshim/SplineMap.h
"
58
#include "
astshim/Table.h
"
59
#include "
astshim/TimeFrame.h
"
60
#include "
astshim/TimeMap.h
"
61
#include "
astshim/TranMap.h
"
62
#include "
astshim/UnitMap.h
"
63
#include "
astshim/UnitNormMap.h
"
64
#include "
astshim/WcsMap.h
"
65
#include "
astshim/WinMap.h
"
66
#include "
astshim/ZoomMap.h
"
67
68
namespace
ast
{
69
70
namespace
{
71
79
extern
"C"
void
sinkToOstream(
const
char
*text) {
80
auto
osptr =
reinterpret_cast<
std::ostream *
>
(astChannelData);
81
(*osptr) << text <<
std::endl
;
82
}
83
84
}
// anonymous namespace
85
86
bool
Object::operator==
(
Object
const
&rhs)
const
{
87
auto
thisStr = this->
show
(
false
);
88
auto
rhsStr = rhs.
show
(
false
);
89
return
rhsStr == thisStr;
90
}
91
92
std::shared_ptr<Object>
Object::_basicFromAstObject(AstObject *rawObj) {
93
static
std::unordered_map<std::string, std::function<std::shared_ptr<Object>
(AstObject *)>>
94
ClassCasterMap = {
95
{
"ChebyMap"
,
makeShim<ChebyMap, AstChebyMap>
},
96
{
"CmpFrame"
,
makeShim<CmpFrame, AstCmpFrame>
},
97
{
"FitsChan"
,
makeShim<FitsChan, AstFitsChan>
},
98
{
"FitsTable"
,
makeShim<FitsTable, AstFitsTable>
},
99
{
"Frame"
,
makeShim<Frame, AstFrame>
},
100
{
"FrameSet"
,
makeShim<FrameSet, AstFrameSet>
},
101
{
"FrameDict"
,
makeShim<FrameDict, AstFrameSet>
},
102
{
"KeyMap"
,
makeShim<KeyMap, AstKeyMap>
},
103
{
"LutMap"
,
makeShim<LutMap, AstLutMap>
},
104
{
"MathMap"
,
makeShim<MathMap, AstMathMap>
},
105
{
"MatrixMap"
,
makeShim<MatrixMap, AstMatrixMap>
},
106
{
"NormMap"
,
makeShim<NormMap, AstNormMap>
},
107
{
"ParallelMap"
,
makeShim<ParallelMap, AstCmpMap>
},
108
{
"PcdMap"
,
makeShim<PcdMap, AstPcdMap>
},
109
{
"PermMap"
,
makeShim<PermMap, AstPermMap>
},
110
{
"PolyMap"
,
makeShim<PolyMap, AstPolyMap>
},
111
{
"RateMap"
,
makeShim<RateMap, AstRateMap>
},
112
{
"SeriesMap"
,
makeShim<SeriesMap, AstCmpMap>
},
113
{
"ShiftMap"
,
makeShim<ShiftMap, AstShiftMap>
},
114
{
"SkyFrame"
,
makeShim<SkyFrame, AstSkyFrame>
},
115
{
"SlaMap"
,
makeShim<SlaMap, AstSlaMap>
},
116
{
"SpecFrame"
,
makeShim<SpecFrame, AstSpecFrame>
},
117
{
"SphMap"
,
makeShim<SphMap, AstSphMap>
},
118
{
"SplineMap"
,
makeShim<SplineMap, AstSplineMap>
},
119
{
"TimeFrame"
,
makeShim<TimeFrame, AstTimeFrame>
},
120
{
"Table"
,
makeShim<Table, AstTable>
},
121
{
"TimeMap"
,
makeShim<TimeMap, AstTimeMap>
},
122
{
"TranMap"
,
makeShim<TranMap, AstTranMap>
},
123
{
"UnitMap"
,
makeShim<UnitMap, AstUnitMap>
},
124
{
"UnitNormMap"
,
makeShim<UnitNormMap, AstUnitNormMap>
},
125
{
"WcsMap"
,
makeShim<WcsMap, AstWcsMap>
},
126
{
"WinMap"
,
makeShim<WinMap, AstWinMap>
},
127
{
"ZoomMap"
,
makeShim<ZoomMap, AstZoomMap>
},
128
};
129
assertOK
(rawObj);
130
auto
className =
detail::getClassName
(rawObj);
131
auto
name_caster = ClassCasterMap.find(className);
132
if
(name_caster == ClassCasterMap.end()) {
133
astAnnul(rawObj);
134
throw
std::runtime_error(
"Class "
+ className +
" not supported"
);
135
}
136
return
name_caster->second(rawObj);
137
}
138
139
template
<
typename
Class>
140
std::shared_ptr<Class>
Object::fromAstObject
(AstObject *rawObj,
bool
copy
) {
141
AstObject *rawObjCopy = rawObj;
142
if
(
copy
) {
143
rawObjCopy =
reinterpret_cast<
AstObject *
>
(astCopy(rawObj));
144
astAnnul(rawObj);
145
}
146
assertOK
(rawObjCopy);
147
148
// Make the appropriate ast shim object and dynamically cast to the desired output type
149
auto
retObjectBeforeCast = Object::_basicFromAstObject(rawObjCopy);
150
auto
retObject =
std::dynamic_pointer_cast<Class>
(retObjectBeforeCast);
151
if
(!retObject) {
152
std::ostringstream
os;
153
os <<
"The component is of type "
<< retObject->getClassName()
154
<<
", which could not be cast to the desired type "
<<
typeid
(Class).name();
155
throw
std::runtime_error
(os.
str
());
156
}
157
return
retObject;
158
}
159
160
void
Object::show
(
std::ostream
&os,
bool
showComments)
const
{
161
Stream
stream(
nullptr
, &os);
162
Channel
ch(stream, showComments ?
""
:
"Comment=0"
);
163
ch.
write
(*
this
);
164
assertOK
();
165
}
166
167
std::string
Object::show
(
bool
showComments)
const
{
168
std::ostringstream
os;
169
show
(os, showComments);
170
return
os.
str
();
171
}
172
173
Object::Object
(AstObject *
object
) : _objPtr(object, &
detail
::annulAstObject) {
174
assertOK
();
175
if
(!
object
) {
176
throw
std::runtime_error
(
"Null pointer"
);
177
}
178
}
179
180
int
Object::getI
(
std::string
const
&attrib)
const
{
181
int
val = astGetI(
getRawPtr
(), attrib.
c_str
());
182
assertOK
();
183
return
val;
184
}
185
186
// Explicit instantiations
187
template
std::shared_ptr<KeyMap>
Object::fromAstObject<KeyMap>
(AstObject *,
bool
);
188
template
std::shared_ptr<FitsChan>
Object::fromAstObject<FitsChan>
(AstObject *,
bool
);
189
template
std::shared_ptr<FrameSet>
Object::fromAstObject<FrameSet>
(AstObject *,
bool
);
190
template
std::shared_ptr<Frame>
Object::fromAstObject<Frame>
(AstObject *,
bool
);
191
template
std::shared_ptr<Mapping>
Object::fromAstObject<Mapping>
(AstObject *,
bool
);
192
template
std::shared_ptr<Object>
Object::fromAstObject<Object>
(AstObject *,
bool
);
193
194
}
// namespace ast
Channel.h
ChebyMap.h
CmpFrame.h
FitsChan.h
FitsTable.h
Frame.h
FrameDict.h
FrameSet.h
KeyMap.h
LutMap.h
MathMap.h
MatrixMap.h
NormMap.h
Object.h
ParallelMap.h
PcdMap.h
PermMap.h
PolyMap.h
RateMap.h
SeriesMap.h
ShiftMap.h
SkyFrame.h
SlaMap.h
SpecFrame.h
SphMap.h
SplineMap.h
Table.h
TimeFrame.h
TimeMap.h
TranMap.h
UnitMap.h
UnitNormMap.h
WcsMap.h
WinMap.h
ZoomMap.h
base.h
std::ostream
std::ostringstream
std::string
std::string::c_str
T c_str(T... args)
ast::Channel
Channel provides input/output of AST objects.
Definition
Channel.h:60
ast::Channel::write
int write(Object const &object)
Write an object to a channel.
Definition
Channel.cc:61
ast::Object::fromAstObject
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:140
ast::Object::show
void show(std::ostream &os, bool showComments=true) const
Print a textual description the object to an ostream.
Definition
Object.cc:160
ast::Object::copy
std::shared_ptr< Object > copy() const
Return a deep copy of this object.
Definition
Object.h:109
ast::Object::makeShim
static std::shared_ptr< ShimT > makeShim(AstObject *p)
Functor to make an astshim instance from a raw AST pointer of the corresponding type.
Definition
Object.h:310
ast::Object::getI
int getI(std::string const &attrib) const
Get the value of an attribute as an int.
Definition
Object.cc:180
ast::Object::Object
Object(Object const &object)
Copy constructor: make a deep copy.
Definition
Object.h:64
ast::Object::getRawPtr
AstObject const * getRawPtr() const
Get the raw AST pointer.
Definition
Object.h:292
ast::Object::operator==
bool operator==(Object const &rhs) const
Return True if this and rhs are the equal.
Definition
Object.cc:86
ast::Stream
A stream for ast::Channel.
Definition
Stream.h:41
std::endl
T endl(T... args)
ast::detail
Definition
polyMapUtils.h:30
ast::detail::getClassName
std::string getClassName(AstObject const *rawObj)
Get the AST class name, changing CmpMap to SeriesMap or ParallelMap as appropriate.
Definition
utils.cc:37
ast
AST wrapper classes and functions.
Definition
attributes_channel.dox:1
ast::assertOK
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Throw std::runtime_error if AST's state is bad.
Definition
base.cc:49
std::dynamic_pointer_cast
T dynamic_pointer_cast(T... args)
std::runtime_error
std::shared_ptr
std::ostringstream::str
T str(T... args)
std::unordered_map
utils.h
Generated on
for lsst.astshim by
1.17.0