lsst.astshim  master-gd1207e8857
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
MathMap.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_MATHMAP_H
23 #define ASTSHIM_MATHMAP_H
24 
25 #include <memory>
26 
27 #include "astshim/base.h"
28 #include "astshim/Mapping.h"
29 
30 namespace ast {
31 
61 class MathMap : public Mapping {
62 friend class Object;
63 public:
374  MathMap(int nin, int nout, std::vector<std::string> const & fwd,
375  std::vector<std::string> const & rev, std::string const & options="") :
376  Mapping(reinterpret_cast<AstMapping *>(
377  astMathMap(nin, nout,
378  fwd.size(), getCStrVec(fwd).data(),
379  rev.size(), getCStrVec(rev).data(), options.c_str())))
380  {}
381 
382  virtual ~MathMap() {}
383 
384  MathMap(MathMap const &) = delete;
385  MathMap(MathMap &&) = default;
386  MathMap & operator=(MathMap const &) = delete;
387  MathMap & operator=(MathMap &&) = default;
388 
390  std::shared_ptr<MathMap> copy() const {
391  return std::static_pointer_cast<MathMap>(_copyPolymorphic());
392  }
393 
397  int getSeed() const { return getI("Seed"); }
398 
402  bool getSimpFI() const { return getB("SimpFI"); }
403 
407  bool getSimpIF() const { return getB("SimpIF"); }
408 
409 protected:
410  virtual std::shared_ptr<Object> _copyPolymorphic() const override {
411  return _copyImpl<MathMap, AstMathMap>();
412  }
413 
415  explicit MathMap(AstMathMap * rawptr) :
416  Mapping(reinterpret_cast<AstMapping *>(rawptr))
417  {
418  if (!astIsAMathMap(getRawPtr())) {
419  std::ostringstream os;
420  os << "this is a " << getClass() << ", which is not a MathMap";
421  throw std::invalid_argument(os.str());
422  }
423  }
424 
425 private:
427  std::vector<char const *> getCStrVec(std::vector<std::string> const & strVec) {
428  std::vector<char const *> cstrVec;
429  for (auto const & str : strVec) {
430  cstrVec.push_back(str.c_str());
431  }
432  return cstrVec;
433  }
434 };
435 
436 } // namespace ast
437 
438 #endif
virtual std::shared_ptr< Object > _copyPolymorphic() const override
Definition: MathMap.h:410
MathMap(AstMathMap *rawptr)
Construct a MathMap from a raw AST pointer.
Definition: MathMap.h:415
bool getSimpFI() const
Definition: MathMap.h:402
std::string getClass() const
Definition: Object.h:117
Definition: Mapping.h:59
Definition: Object.h:49
MathMap(int nin, int nout, std::vector< std::string > const &fwd, std::vector< std::string > const &rev, std::string const &options="")
Definition: MathMap.h:374
Definition: MathMap.h:61
bool getSimpIF() const
Definition: MathMap.h:407
int getSeed() const
Definition: MathMap.h:397
int getI(std::string const &attrib) const
Definition: Object.h:386
bool getB(std::string const &attrib) const
Definition: Object.h:334
AstObject const * getRawPtr() const
Definition: Object.h:260
std::shared_ptr< MathMap > copy() const
Return a deep copy of this object.
Definition: MathMap.h:390