28#include <unordered_map>
78extern "C" void sinkToOstream(
const char *text) {
79 auto osptr =
reinterpret_cast<std::ostream *
>(astChannelData);
86 auto thisStr = this->
show(
false);
87 auto rhsStr = rhs.
show(
false);
88 return rhsStr == thisStr;
94 {
"ChebyMap", makeShim<ChebyMap, AstChebyMap>},
95 {
"CmpFrame", makeShim<CmpFrame, AstCmpFrame>},
96 {
"FitsChan", makeShim<FitsChan, AstFitsChan>},
97 {
"FitsTable", makeShim<FitsTable, AstFitsTable>},
98 {
"Frame", makeShim<Frame, AstFrame>},
99 {
"FrameSet", makeShim<FrameSet, AstFrameSet>},
100 {
"FrameDict", makeShim<FrameDict, AstFrameSet>},
101 {
"KeyMap", makeShim<KeyMap, AstKeyMap>},
102 {
"LutMap", makeShim<LutMap, AstLutMap>},
103 {
"MathMap", makeShim<MathMap, AstMathMap>},
104 {
"MatrixMap", makeShim<MatrixMap, AstMatrixMap>},
105 {
"NormMap", makeShim<NormMap, AstNormMap>},
106 {
"ParallelMap", makeShim<ParallelMap, AstCmpMap>},
107 {
"PcdMap", makeShim<PcdMap, AstPcdMap>},
108 {
"PermMap", makeShim<PermMap, AstPermMap>},
109 {
"PolyMap", makeShim<PolyMap, AstPolyMap>},
110 {
"RateMap", makeShim<RateMap, AstRateMap>},
111 {
"SeriesMap", makeShim<SeriesMap, AstCmpMap>},
112 {
"ShiftMap", makeShim<ShiftMap, AstShiftMap>},
113 {
"SkyFrame", makeShim<SkyFrame, AstSkyFrame>},
114 {
"SlaMap", makeShim<SlaMap, AstSlaMap>},
115 {
"SpecFrame", makeShim<SpecFrame, AstSpecFrame>},
116 {
"SphMap", makeShim<SphMap, AstSphMap>},
117 {
"TimeFrame", makeShim<TimeFrame, AstTimeFrame>},
118 {
"Table", makeShim<Table, AstTable>},
119 {
"TimeMap", makeShim<TimeMap, AstTimeMap>},
120 {
"TranMap", makeShim<TranMap, AstTranMap>},
121 {
"UnitMap", makeShim<UnitMap, AstUnitMap>},
122 {
"UnitNormMap", makeShim<UnitNormMap, AstUnitNormMap>},
123 {
"WcsMap", makeShim<WcsMap, AstWcsMap>},
124 {
"WinMap", makeShim<WinMap, AstWinMap>},
125 {
"ZoomMap", makeShim<ZoomMap, AstZoomMap>},
129 auto name_caster = ClassCasterMap.find(className);
130 if (name_caster == ClassCasterMap.end()) {
134 return name_caster->second(rawObj);
137template <
typename Class>
139 AstObject *rawObjCopy = rawObj;
141 rawObjCopy =
reinterpret_cast<AstObject *
>(astCopy(rawObj));
147 auto retObjectBeforeCast = Object::_basicFromAstObject(rawObjCopy);
148 auto retObject = std::dynamic_pointer_cast<Class>(retObjectBeforeCast);
151 os <<
"The component is of type " << retObject->getClassName()
152 <<
", which could not be cast to the desired type " <<
typeid(Class).
name();
159 Stream stream(
nullptr, &os);
160 Channel ch(stream, showComments ?
"" :
"Comment=0");
167 show(os, showComments);
table::Key< std::string > name
Channel provides input/output of AST objects.
int write(Object const &object)
Write an object to a channel.
Abstract base class for all AST objects.
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.
void show(std::ostream &os, bool showComments=true) const
Print a textual description the object to an ostream.
int getI(std::string const &attrib) const
Get the value of an attribute as an int.
Object(Object const &object)
Copy constructor: make a deep copy.
AstObject const * getRawPtr() const
Get the raw AST pointer.
bool operator==(Object const &rhs) const
Return True if this and rhs are the equal.
A stream for ast::Channel.
std::string getClassName(AstObject const *rawObj)
Get the AST class name, changing CmpMap to SeriesMap or ParallelMap as appropriate.
AST wrapper classes and functions.
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Throw std::runtime_error if AST's state is bad.