lsst.astshim  14.0-11-g0e62142+2
CmpMap.h
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 #ifndef ASTSHIM_CMPMAP_H
23 #define ASTSHIM_CMPMAP_H
24 
25 #include <memory>
26 #include <sstream>
27 #include <stdexcept>
28 
29 #include "astshim/base.h"
30 #include "astshim/detail/utils.h"
31 #include "astshim/Mapping.h"
32 
33 namespace ast {
34 
56 class CmpMap : public Mapping {
57  friend class Object;
58 
59 public:
73  explicit CmpMap(Mapping const &map1, Mapping const &map2, bool series, std::string const &options = "")
74  : Mapping(reinterpret_cast<AstMapping *>(astCmpMap(const_cast<AstObject *>(map1.getRawPtr()),
75  const_cast<AstObject *>(map2.getRawPtr()),
76  series, "%s", options.c_str()))) {}
77 
78  virtual ~CmpMap() {}
79 
80  CmpMap(CmpMap const &) = delete;
81  CmpMap(CmpMap &&) = default;
82  CmpMap &operator=(CmpMap const &) = delete;
83  CmpMap &operator=(CmpMap &&) = default;
84 
86  std::shared_ptr<CmpMap> copy() const { return std::static_pointer_cast<CmpMap>(copyPolymorphic()); }
87 
94  std::shared_ptr<Mapping> operator[](int i) const { return decompose<Mapping>(i, false); };
95 
97  bool getSeries() { return detail::isSeries(reinterpret_cast<AstCmpMap *>(getRawPtr())); }
98 
99 protected:
100  virtual std::shared_ptr<Object> copyPolymorphic() const override {
101  return copyImpl<CmpMap, AstCmpMap>();
102  }
103 
106  explicit CmpMap(AstCmpMap *rawptr) : Mapping(reinterpret_cast<AstMapping *>(rawptr)) {
107  if (!astIsACmpMap(getRawPtr())) {
108  std::ostringstream os;
109  os << "this is a " << getClassName() << ", which is not a CmpMap";
110  throw std::invalid_argument(os.str());
111  }
112  }
113 };
114 
115 } // namespace ast
116 
117 #endif
AstObject const * getRawPtr() const
Definition: Object.h:289
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
std::string getClassName() const
Definition: Object.h:136
Definition: Mapping.h:59
virtual std::shared_ptr< Object > copyPolymorphic() const override
Definition: CmpMap.h:100
bool getSeries()
Return True if the map is in series.
Definition: CmpMap.h:97
std::shared_ptr< Mapping > operator[](int i) const
Definition: CmpMap.h:94
CmpMap(Mapping const &map1, Mapping const &map2, bool series, std::string const &options="")
Definition: CmpMap.h:73
std::shared_ptr< CmpMap > copy() const
Return a deep copy of this object.
Definition: CmpMap.h:86
Definition: Object.h:51
Definition: CmpMap.h:56
CmpMap(AstCmpMap *rawptr)
Definition: CmpMap.h:106