Wildmeshing Toolkit
GridOptions.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <string_view>
3 #include <variant>
4 
5 #include "Grid2Options.hpp"
6 #include "Grid3Options.hpp"
7 
8 
11 {
12  constexpr static auto name() -> std::string_view { return "grid"; }
13 
14 public:
15  std::variant<Grid2Options, Grid3Options> opts;
16  std::optional<std::string> get_coordinate_name() const
17  {
18  return std::visit([&](const auto& o) { return o.get_coordinate_name(); }, opts);
19  }
20  friend void to_json(nlohmann::json& nlohmann_json_j, const GridOptions& nlohmann_json_t)
21  {
22  std::visit([&](const auto& o) { to_json(nlohmann_json_j, o); }, nlohmann_json_t.opts);
23  }
24  friend void from_json(const nlohmann::json& nlohmann_json_j, GridOptions& nlohmann_json_t)
25  {
26  spdlog::info("{}", nlohmann_json_j.dump());
27  const auto& dimension = nlohmann_json_j["dimensions"];
28  assert(dimension.is_array());
29 
30  size_t dsize = dimension.size();
31  if (dsize == 2) {
32  nlohmann_json_t.opts = nlohmann_json_j.get<Grid2Options>();
33  } else {
34  nlohmann_json_t.opts = nlohmann_json_j.get<Grid3Options>();
35  }
36  }
37 };
38 } // namespace wmtk::components::procedural
friend void to_json(nlohmann::json &nlohmann_json_j, const GridOptions &nlohmann_json_t)
Definition: GridOptions.hpp:20
std::optional< std::string > get_coordinate_name() const
Definition: GridOptions.hpp:16
constexpr static auto name() -> std::string_view
Definition: GridOptions.hpp:12
std::variant< Grid2Options, Grid3Options > opts
Definition: GridOptions.hpp:15
friend void from_json(const nlohmann::json &nlohmann_json_j, GridOptions &nlohmann_json_t)
Definition: GridOptions.hpp:24
nlohmann::json json
Definition: input.cpp:9