lsst.astshim  14.0-6-g52c7625+1
utils.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_DETAIL_UTILS_H
23 #define ASTSHIM_DETAIL_UTILS_H
24 
25 #include <stdexcept>
26 
27 #include "astshim/base.h"
28 
29 namespace ast {
30 namespace detail {
31 
32 static const int FITSLEN = 80;
33 
35 inline void annulAstObject(AstObject *object) {
36  if (object != nullptr) {
37  astAnnul(object);
38  }
39 }
40 
41 template <typename T1, typename T2>
42 inline void assertEqual(T1 val1, std::string const &descr1, T2 val2, std::string const &descr2) {
43  if (val1 != val2) {
44  std::ostringstream os;
45  os << descr1 << " = " << val1 << " != " << descr2 << " = " << val2;
46  throw std::invalid_argument(os.str());
47  }
48 }
49 
53 inline void astBadToNan(std::vector<double> &p) {
54  for (auto &val : p) {
55  if (val == AST__BAD) {
56  val = std::numeric_limits<double>::quiet_NaN();
57  }
58  }
59 }
60 
64 void astBadToNan(ast::Array2D const &arr);
65 
73 inline std::string formatAxisAttr(std::string const &name, int axis) {
74  std::stringstream os;
75  os << name << "(" << axis << ")";
76  return os.str();
77 }
78 
82 bool isSeries(AstCmpMap const *cmpMap);
83 
89 std::string getClassName(AstObject const *rawObj);
90 
94 inline double safeDouble(double val) {
95  assertOK();
96  return val != AST__BAD ? val : std::numeric_limits<double>::quiet_NaN();
97 }
98 
99 } // namespace detail
100 } // namespace ast
101 
102 #endif
ndarray::Array< double, 2, 2 > Array2D
Definition: base.h:42
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:49