Debian Codegraph @

src/atlas/field/MissingValue.cc

raw
1 /*
2 * (C) Copyright 1996- ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 *
7 * In applying this licence, ECMWF does not waive the privileges and immunities
8 * granted to it by virtue of its status as an intergovernmental organisation nor
9 * does it submit to any jurisdiction.
10 */
11
12
13 #include "atlas/field/MissingValue.h"
14
15 #include <cmath>
16
17 #include "eckit/types/FloatCompare.h"
18
19 #include "atlas/field/Field.h"
20 #include "atlas/runtime/Exception.h"
21 #include "atlas/util/Config.h"
22 #include "atlas/util/Metadata.h"
23
24
25 namespace atlas {
26 namespace field {
27
28
29 namespace {
30 std::string config_type(const MissingValue::Config& c) {
31 std::string value;
32 c.get("type", value);
33 return value;
34 }
35
36
37 std::string field_type(const Field& f) {
38 std::string value;
39 if (f.metadata().get("missing_value_type", value)) {
40 value += "-" + f.datatype().str();
41 }
42 return value;
43 }
44 } // namespace
45
46
47 MissingValue::MissingValue(): Handle(nullptr) {}
48
49
50 MissingValue::MissingValue(const MissingValue::Config& config):
51 Handle(detail::MissingValueFactory::build(config_type(config), config)) {}
52
53
54 MissingValue::MissingValue(const std::string& type, const MissingValue::Config& config):
55 Handle(detail::MissingValueFactory::build(type, config)) {}
56
57
58 MissingValue::MissingValue(const Field& field):
59 Handle(detail::MissingValueFactory::build(field_type(field), field.metadata())) {}
60
61
62 MissingValue::MissingValue(const std::string& type, const Field& field):
63 Handle(detail::MissingValueFactory::build(type, field.metadata())) {}
64
65
66 bool MissingValue::operator()(const double& value) const {
67 ATLAS_ASSERT_MSG(operator bool(), "MissingValue::operator()( const double& ) ObjectHandle not setup");
68 return get()->operator()(value);
69 }
70
71
72 bool MissingValue::operator()(const float& value) const {
73 ATLAS_ASSERT_MSG(operator bool(), "MissingValue::operator()( const float& ): ObjectHandle not setup");
74 return get()->operator()(value);
75 }
76
77
78 bool MissingValue::operator()(const int& value) const {
79 ATLAS_ASSERT_MSG(operator bool(), "MissingValue::operator()( const int& ): ObjectHandle not setup");
80 return get()->operator()(value);
81 }
82
83
84 bool MissingValue::operator()(const long& value) const {
85 ATLAS_ASSERT_MSG(operator bool(), "MissingValue::operator()( const long& ): ObjectHandle not setup");
86 return get()->operator()(value);
87 }
88
89
90 bool MissingValue::operator()(const unsigned long& value) const {
91 ATLAS_ASSERT_MSG(operator bool(), "MissingValue::operator()( const unsigned long& ): ObjectHandle not setup");
92 return get()->operator()(value);
93 }
94
95
96 bool MissingValue::isnan() const {
97 ATLAS_ASSERT_MSG(operator bool(), "MissingValue: ObjectHandle not setup");
98 return get()->isnan();
99 }
100
101
102 const detail::MissingValue& MissingValue::ref() const {
103 ATLAS_ASSERT_MSG(operator bool(), "MissingValue: ObjectHandle not setup");
104 return *get(); // (one dereferencing level less)
105 }
106
107
108 void MissingValue::metadata(Field& field) const {
109 ATLAS_ASSERT_MSG(operator bool(), "MissingValue: ObjectHandle not setup");
110 get()->metadata(field);
111 }
112
113
114 } // namespace field
115 } // namespace atlas