Skip to content

Commit 2a87a84

Browse files
committed
eckit::geo::Grid generalise use of grids by name/uid
1 parent d803b9b commit 2a87a84

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/eckit/geo/Grid.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,21 @@ void Grid::fill_spec(spec::Custom& custom) const {
264264
}
265265

266266

267+
ShareEckitGeoGridInit::ShareEckitGeoGridInit() {
268+
// ensure load of supporting files
269+
share::Grid::instance();
270+
}
271+
272+
267273
const Grid* GridFactory::make_from_string(const std::string& str) {
268274
std::unique_ptr<Spec> spec(spec::Custom::make_from_value(YAMLParser::decodeString(str)));
269275
return instance().make_from_spec_(*spec);
270276
}
271277

272278

273279
GridFactory& GridFactory::instance() {
280+
share::Grid::instance();
281+
274282
static GridFactory INSTANCE;
275283
return INSTANCE;
276284
}
@@ -282,7 +290,7 @@ const Grid* GridFactory::make_from_spec_(const Spec& spec) const {
282290
std::unique_ptr<Spec> cfg(make_spec_(spec));
283291

284292
if (std::string type; cfg->get("type", type)) {
285-
return GridFactoryType::instance().get(type).create(*cfg);
293+
return Factory<Grid>::instance().get(type).create(*cfg);
286294
}
287295

288296
list(Log::error() << "Grid: cannot build grid without 'type', choices are: ");
@@ -292,7 +300,6 @@ const Grid* GridFactory::make_from_spec_(const Spec& spec) const {
292300

293301
Spec* GridFactory::make_spec_(const Spec& spec) const {
294302
lock_type lock;
295-
share::Grid::instance();
296303

297304
auto* cfg = new spec::Layered(spec);
298305
ASSERT(cfg != nullptr);
@@ -344,11 +351,10 @@ bool Grid::NextIterator::next(Point& point) {
344351

345352
std::ostream& GridFactory::list_(std::ostream& out) const {
346353
lock_type lock;
347-
share::Grid::instance();
348354

349355
out << GridSpecByUID::instance() << std::endl;
350356
out << GridSpecByName::instance() << std::endl;
351-
out << GridFactoryType::instance() << std::endl;
357+
out << Factory<Grid>::instance() << std::endl;
352358

353359
return out;
354360
}

src/eckit/geo/Grid.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,15 @@ class Grid {
203203
};
204204

205205

206-
using GridFactoryType = Factory<Grid>;
207-
using GridSpecByName = spec::GeneratorT<spec::SpecGeneratorT1<const std::string&>>;
208-
using GridSpecByUID = spec::GeneratorT<spec::SpecGeneratorT0>;
206+
struct ShareEckitGeoGridInit {
207+
private:
208+
209+
ShareEckitGeoGridInit();
210+
};
211+
212+
213+
struct GridSpecByName : spec::GeneratorT<spec::SpecGeneratorT1<const std::string&>>, private ShareEckitGeoGridInit {};
214+
struct GridSpecByUID : spec::GeneratorT<spec::SpecGeneratorT0>, private ShareEckitGeoGridInit {};
209215

210216

211217
template <typename T>

0 commit comments

Comments
 (0)