lsst.astshim  14.0-9-g580965d+1
TimeMap.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_TIMEMAP_H
23 #define ASTSHIM_TIMEMAP_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 
40 class TimeMap : public Mapping {
41  friend class Object;
42 
43 public:
56  explicit TimeMap(std::string const &options = "")
57  : Mapping(reinterpret_cast<AstMapping *>(astTimeMap(0, "%s", options.c_str()))) {}
58 
59  virtual ~TimeMap() {}
60 
61  TimeMap(TimeMap const &) = delete;
62  TimeMap(TimeMap &&) = default;
63  TimeMap &operator=(TimeMap const &) = delete;
64  TimeMap &operator=(TimeMap &&) = default;
65 
67  std::shared_ptr<TimeMap> copy() const { return std::static_pointer_cast<TimeMap>(copyPolymorphic()); }
68 
180  void add(std::string const &cvt, std::vector<double> const &args) {
181  astTimeAdd(getRawPtr(), cvt.c_str(), args.size(), args.data());
182  assertOK();
183  }
184 
185 protected:
186  virtual std::shared_ptr<Object> copyPolymorphic() const override {
187  return copyImpl<TimeMap, AstTimeMap>();
188  }
189 
191  explicit TimeMap(AstTimeMap *rawptr) : Mapping(reinterpret_cast<AstMapping *>(rawptr)) {
192  if (!astIsATimeMap(getRawPtr())) {
193  std::ostringstream os;
194  os << "this is a " << getClassName() << ", which is not a TimeMap";
195  throw std::invalid_argument(os.str());
196  }
197  }
198 };
199 
200 } // namespace ast
201 
202 #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
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:49
virtual std::shared_ptr< Object > copyPolymorphic() const override
Definition: TimeMap.h:186
Definition: Mapping.h:59
Definition: TimeMap.h:40
std::shared_ptr< TimeMap > copy() const
Return a deep copy of this object.
Definition: TimeMap.h:67
void add(std::string const &cvt, std::vector< double > const &args)
Definition: TimeMap.h:180
Definition: Object.h:51
TimeMap(AstTimeMap *rawptr)
Construct a TimeMap from a raw AST pointer.
Definition: TimeMap.h:191
TimeMap(std::string const &options="")
Definition: TimeMap.h:56