Skip to content

Commit f8366b7

Browse files
committed
Merge branch 'hotfix/1.29.1'
2 parents d455322 + 0e45e04 commit f8366b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+559
-793
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.29.0
1+
1.29.1

src/eckit/geo/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ list(APPEND eckit_geo_srcs
109109
iterator/Unstructured.h
110110
order/HEALPix.cc
111111
order/HEALPix.h
112-
order/ReducedScan.cc
113-
order/ReducedScan.h
114-
order/RegularScan.cc
115-
order/RegularScan.h
116112
order/Scan.cc
117113
order/Scan.h
118114
polygon/Polygon.cc

src/eckit/geo/Exceptions.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ AreaError::AreaError(const std::string& what, const CodeLocation& loc) : Excepti
2121
};
2222

2323

24-
ReorderError::ReorderError(const std::string& what, const CodeLocation& loc) {
25-
reason("ReorderError: [" + what + "], in " + loc.asString());
24+
OrderError::OrderError(const std::string& what, const CodeLocation& loc) {
25+
reason("OrderError: [" + what + "], in " + loc.asString());
2626
}
2727

2828

src/eckit/geo/Exceptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class AreaError : public geo::Exception {
3838
};
3939

4040

41-
class ReorderError : public geo::Exception {
41+
class OrderError : public geo::Exception {
4242
public:
4343

44-
explicit ReorderError(const std::string&, const CodeLocation&);
44+
explicit OrderError(const std::string&, const CodeLocation&);
4545
};
4646

4747

src/eckit/geo/Grid.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ std::pair<std::vector<double>, std::vector<double> > Grid::to_latlons() const {
124124
}
125125

126126

127-
Grid::order_type Grid::order() const {
127+
const Grid::order_type& Grid::order() const {
128128
NOTIMP;
129129
}
130130

131131

132-
Reordering Grid::reorder(order_type) const {
132+
Reordering Grid::reorder(const order_type&) const {
133133
NOTIMP;
134134
}
135135

136136

137-
Grid* Grid::make_grid_reordered(order_type) const {
137+
Grid* Grid::make_grid_reordered(const order_type&) const {
138138
NOTIMP;
139139
}
140140

src/eckit/geo/Grid.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ class Grid {
159159
[[nodiscard]] virtual std::vector<Point> to_points() const;
160160
[[nodiscard]] virtual std::pair<std::vector<double>, std::vector<double>> to_latlons() const;
161161

162-
virtual order_type order() const;
163-
virtual Reordering reorder(order_type) const;
162+
virtual const order_type& order() const;
163+
virtual Reordering reorder(const order_type&) const;
164164

165165
virtual const Area& area() const;
166166
virtual Reordering crop(const Area&) const;
@@ -170,7 +170,7 @@ class Grid {
170170
virtual const area::BoundingBox& boundingBox() const;
171171
[[nodiscard]] virtual area::BoundingBox* calculate_bbox() const;
172172

173-
[[nodiscard]] virtual Grid* make_grid_reordered(order_type) const;
173+
[[nodiscard]] virtual Grid* make_grid_reordered(const order_type&) const;
174174
[[nodiscard]] virtual Grid* make_grid_cropped(const Area&) const;
175175

176176
// -- Class methods

src/eckit/geo/Order.cc

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "eckit/geo/Spec.h"
2121
#include "eckit/geo/spec/Layered.h"
2222
#include "eckit/geo/util/mutex.h"
23+
#include "eckit/parser/YAMLParser.h"
2324

2425

2526
namespace eckit::geo {
@@ -36,26 +37,34 @@ class lock_type {
3637
};
3738

3839

39-
std::map<std::string, size_t> ORDERING_INDEX;
40-
std::map<size_t, std::string> ORDERING_NAME;
40+
std::map<std::string, size_t> ORDER_INDEX;
41+
std::map<size_t, std::string> ORDER_NAME;
4142

4243

4344
} // namespace
4445

4546

46-
std::string Order::className() {
47-
static const std::string ordering = "ordering";
48-
return ordering;
47+
const Spec& Order::spec() const {
48+
if (!spec_) {
49+
spec_ = std::make_shared<spec::Custom>();
50+
ASSERT(spec_);
51+
52+
auto& custom = *spec_;
53+
fill_spec(custom);
54+
}
55+
56+
return *spec_;
4957
}
5058

5159

52-
Order::value_type Order::make_ordering_from_spec(const Spec&) {
53-
NOTIMP;
60+
std::string Order::className() {
61+
static const std::string order = "order";
62+
return order;
63+
}
64+
5465

55-
// int key = (spec.get_bool("scan_i_plus", true) ? 0 : 1) + (spec.get_bool("scan_j_plus", false) ? 1 << 1 : 0) +
56-
// (spec.get_bool("scan_ij", true) ? 0 : 1 << 2) + (spec.get_bool("scan_alternating", false) ? 1 << 3 :
57-
// 0);
58-
// return static_cast<value_type>(key);
66+
Order::value_type Order::make_order_from_spec(const Spec& spec) {
67+
return std::unique_ptr<const Order>(OrderFactory::build(spec))->order();
5968
}
6069

6170

@@ -66,69 +75,59 @@ Reordering Order::no_reorder(size_t size) {
6675
}
6776

6877

69-
void Order::fill_spec(spec::Custom& custom) const {
70-
if (order() != order_default()) {
71-
custom.set("type", type());
72-
custom.set("order", order());
73-
}
74-
}
75-
76-
7778
void Order::register_ordering(const std::string& name) {
7879
lock_type lock;
7980

80-
auto index = ORDERING_INDEX.size();
81-
82-
ASSERT(ORDERING_INDEX.emplace(name, index).second);
83-
ASSERT(ORDERING_NAME.emplace(index, name).second);
81+
auto index = ORDER_INDEX.size();
82+
ASSERT(ORDER_INDEX.try_emplace(name, index).second == ORDER_NAME.try_emplace(index, name).second);
8483
}
8584

8685

87-
const Order* ReorderFactory::make_from_string(const std::string&) {
88-
// FIXME
89-
NOTIMP;
86+
const Order* OrderFactory::make_from_string(const std::string& str) {
87+
std::unique_ptr<Spec> spec(spec::Custom::make_from_value(YAMLParser::decodeString(str)));
88+
return instance().make_from_spec_(*spec);
9089
}
9190

9291

93-
ReorderFactory& ReorderFactory::instance() {
94-
static ReorderFactory obj;
92+
OrderFactory& OrderFactory::instance() {
93+
static OrderFactory obj;
9594
return obj;
9695
}
9796

9897

99-
const Order* ReorderFactory::make_from_spec_(const Spec& spec) const {
98+
const Order* OrderFactory::make_from_spec_(const Spec& spec) const {
10099
lock_type lock;
101100

102101
std::unique_ptr<Spec> cfg(make_spec_(spec));
103102

104103
if (std::string type; cfg->get("type", type)) {
105-
return ReorderFactoryType::instance().get(type).create(*cfg);
104+
return OrderFactoryType::instance().get(type).create(*cfg);
106105
}
107106

108-
list(Log::error() << "Reorder: cannot build ordering without 'type', choices are: ");
109-
throw exception::SpecError("Reorder: cannot build ordering without 'type'", Here());
107+
list(Log::error() << "Order: cannot build order without 'type', choices are: ");
108+
throw exception::SpecError("Order: cannot build order without 'type'", Here());
110109
}
111110

112111

113-
Spec* ReorderFactory::make_spec_(const Spec& spec) const {
112+
Spec* OrderFactory::make_spec_(const Spec& spec) const {
114113
lock_type lock;
115114

116115
auto* cfg = new spec::Layered(spec);
117116
ASSERT(cfg != nullptr);
118117

119118

120-
// hardcoded, interpreted options (contributing to orderingspec)
119+
// hardcoded, interpreted options (contributing to orderspec)
121120

122-
// cfg->push_back(new spec::Custom{{"type", ""}});
121+
cfg->push_back(new spec::Custom{{"type", "scan"}});
123122

124123
return cfg;
125124
}
126125

127126

128-
std::ostream& ReorderFactory::list_(std::ostream& out) const {
127+
std::ostream& OrderFactory::list_(std::ostream& out) const {
129128
lock_type lock;
130129

131-
out << ReorderFactoryType::instance() << std::endl;
130+
out << OrderFactoryType::instance() << std::endl;
132131

133132
return out;
134133
}

src/eckit/geo/Order.h

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414

1515
#include <memory>
1616
#include <string>
17-
#include <type_traits>
1817

1918
#include "eckit/geo/spec/Custom.h"
2019
#include "eckit/geo/spec/Generator.h"
2120
#include "eckit/memory/Builder.h"
2221
#include "eckit/memory/Factory.h"
2322

2423

24+
namespace eckit::geo::grid {
25+
class Regular;
26+
class Reduced;
27+
} // namespace eckit::geo::grid
28+
29+
2530
namespace eckit::geo {
2631

2732

@@ -39,13 +44,6 @@ class Order {
3944

4045
// -- Constructors
4146

42-
template <typename... Args>
43-
explicit Order(Args&&... args) {
44-
static_assert((std::is_convertible_v<Args, value_type> && ...),
45-
"Reorder: arguments must be convertible to value_type");
46-
(register_ordering(std::forward<Args>(args)), ...);
47-
}
48-
4947
Order() noexcept = default;
5048
Order(const Order&) = default;
5149
Order(Order&&) = default;
@@ -61,19 +59,27 @@ class Order {
6159

6260
// -- Methods
6361

62+
[[nodiscard]] const Spec& spec() const;
63+
std::string spec_str() const { return spec().str(); }
64+
6465
virtual const std::string& type() const = 0;
6566

66-
virtual const value_type& order_default() const = 0;
6767
virtual const value_type& order() const = 0;
6868
virtual Reordering reorder(const value_type& to) const = 0;
6969

7070
// -- Class methods
7171

7272
static std::string className();
7373

74-
[[nodiscard]] static value_type make_ordering_from_spec(const Spec&);
74+
[[nodiscard]] static value_type make_order_from_spec(const Spec&);
7575
[[nodiscard]] static Reordering no_reorder(size_t);
7676

77+
protected:
78+
79+
// -- Class methods
80+
81+
static void register_ordering(const std::string&);
82+
7783
private:
7884

7985
// -- Members
@@ -82,19 +88,23 @@ class Order {
8288

8389
// -- Methods
8490

85-
void fill_spec(spec::Custom&) const;
91+
virtual void fill_spec(spec::Custom&) const = 0;
8692

87-
void register_ordering(const std::string&);
93+
// -- Friends
94+
95+
friend class grid::Reduced;
96+
friend class grid::Regular;
8897
};
8998

9099

91-
using ReorderFactoryType = Factory<Order>;
100+
using OrderFactoryType = Factory<Order>;
101+
92102

93103
template <typename T>
94-
using ReorderRegisterType = ConcreteBuilderT1<Order, T>;
104+
using OrderRegisterType = ConcreteBuilderT1<Order, T>;
95105

96106

97-
struct ReorderFactory {
107+
struct OrderFactory {
98108
[[nodiscard]] static const Order* build(const Spec& spec) { return instance().make_from_spec_(spec); }
99109

100110
[[nodiscard]] static const Order* make_from_string(const std::string&);
@@ -104,7 +114,7 @@ struct ReorderFactory {
104114

105115
private:
106116

107-
static ReorderFactory& instance();
117+
static OrderFactory& instance();
108118

109119
[[nodiscard]] const Order* make_from_spec_(const Spec&) const;
110120
[[nodiscard]] Spec* make_spec_(const Spec&) const;

src/eckit/geo/area/library/Shapefile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Shapefile : public Library {
4848

4949
// -- Destructor
5050

51-
~Shapefile();
51+
~Shapefile() override;
5252

5353
// -- Operators
5454

0 commit comments

Comments
 (0)