lsst.astshim  master-gd1207e8857
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
WinMap.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_WINMAP_H
23 #define ASTSHIM_WINMAP_H
24 
25 #include <memory>
26 #include <sstream>
27 #include <stdexcept>
28 #include <vector>
29 
30 #include "astshim/base.h"
31 #include "astshim/Mapping.h"
32 
33 namespace ast {
34 
45 class WinMap: public Mapping {
46 friend class Object;
47 public:
60  explicit WinMap(
61  std::vector<double> const & ina,
62  std::vector<double> const & inb,
63  std::vector<double> const & outa,
64  std::vector<double> const & outb,
65  std::string const & options=""
66  ) :
67  Mapping(reinterpret_cast<AstMapping *>(_makeRawWinMap(ina, inb, outa, outb, options)))
68  {}
69 
70  virtual ~WinMap() {}
71 
72  WinMap(WinMap const &) = delete;
73  WinMap(WinMap &&) = default;
74  WinMap & operator=(WinMap const &) = delete;
75  WinMap & operator=(WinMap &&) = default;
76 
78  std::shared_ptr<WinMap> copy() const {
79  return std::static_pointer_cast<WinMap>(_copyPolymorphic());
80  }
81 
82 protected:
83  virtual std::shared_ptr<Object> _copyPolymorphic() const override {
84  return _copyImpl<WinMap, AstWinMap>();
85  }
86 
88  explicit WinMap(AstWinMap * rawptr) :
89  Mapping(reinterpret_cast<AstMapping *>(rawptr))
90  {
91  if (!astIsAWinMap(getRawPtr())) {
92  std::ostringstream os;
93  os << "this is a " << getClass() << ", which is not a WinMap";
94  throw std::invalid_argument(os.str());
95  }
96  }
97 
98 private:
99  AstWinMap * _makeRawWinMap(
100  std::vector<double> const & ina,
101  std::vector<double> const & inb,
102  std::vector<double> const & outa,
103  std::vector<double> const & outb,
104  std::string const & options=""
105  ) {
106  auto const ncoord = ina.size();
107  if (inb.size() != ncoord) {
108  std::ostringstream os;
109  os << "inb.size() = " << inb.size() << " != " << ncoord << " = ina.size()";
110  throw std::invalid_argument(os.str());
111  }
112  if (outa.size() != ncoord) {
113  std::ostringstream os;
114  os << "outa.size() = " << outa.size() << " != " << ncoord << " = ina.size()";
115  throw std::invalid_argument(os.str());
116  }
117  if (outb.size() != ncoord) {
118  std::ostringstream os;
119  os << "outb.size() = " << outb.size() << " != " << ncoord << " = ina.size()";
120  throw std::invalid_argument(os.str());
121  }
122  return astWinMap(static_cast<int>(ncoord), ina.data(), inb.data(), outa.data(), outb.data(),
123  options.c_str());
124  }
125 };
126 
127 } // namespace ast
128 
129 #endif
WinMap(std::vector< double > const &ina, std::vector< double > const &inb, std::vector< double > const &outa, std::vector< double > const &outb, std::string const &options="")
Definition: WinMap.h:60
virtual std::shared_ptr< Object > _copyPolymorphic() const override
Definition: WinMap.h:83
std::string getClass() const
Definition: Object.h:117
std::shared_ptr< WinMap > copy() const
Return a deep copy of this object.
Definition: WinMap.h:78
Definition: Mapping.h:59
Definition: Object.h:49
WinMap(AstWinMap *rawptr)
Construct a WinMap from a raw AST pointer.
Definition: WinMap.h:88
Definition: WinMap.h:45
AstObject const * getRawPtr() const
Definition: Object.h:260