Browse Source

The names of actions and sources are placed in the corresponding classes

interpolate
Michael Uleysky 2 years ago
parent
commit
9b11464de2
  1. 2
      include/AVISO.h
  2. 2
      include/AVISOLOCAL.h
  3. 2
      include/BINFILE.h
  4. 2
      include/HYCOM.h
  5. 10
      include/MODISBINLOCAL.h
  6. 2
      include/NEMO.h
  7. 2
      include/NEMOBIO.h
  8. 35
      include/actions.h
  9. 2
      include/data.h
  10. 20
      include/varhelpers.h
  11. 56
      src/data.cpp

2
include/AVISO.h

@ -15,6 +15,8 @@ class AVISOData: public LayeredData
Type type = TYPE_UNKNOWN;
public:
static constexpr const char* name = "AVISO";
AVISOData() = default;
MString DataTitle() const

2
include/AVISOLOCAL.h

@ -25,6 +25,8 @@ class AVISOLOCALData: public NCFuncs
};
public:
static constexpr const char* name = "AVISOLOCAL";
using Data = Simple2DData;
AVISOLOCALData() = default;

2
include/BINFILE.h

@ -16,6 +16,8 @@ class BINFILEData
std::unique_ptr<michlib::IntData> data;
public:
static constexpr const char* name = "BINFILE";
using Data = Simple2DData;
BINFILEData() = default;

2
include/HYCOM.h

@ -14,6 +14,8 @@ class HYCOMData: public LayeredData
Type type = TYPE_UNKNOWN;
public:
static constexpr const char* name = "HYCOM";
HYCOMData() = default;
MString DataTitle() const

10
include/MODISBINLOCAL.h

@ -1,21 +1,21 @@
#pragma once
#include "DataAdapters/ncfilealt.h"
#include "ParseArgs.h"
#include "basedata.h"
#include "mdatetime.h"
#include "mregex.h"
#include "DataAdapters/ncfilealt.h"
#include <dirent.h>
#include <set>
#include <utility>
using michlib::Ceil;
using michlib::Floor;
using michlib::GPL;
using michlib::MDateTime;
using michlib::pointer_cast;
using michlib::RegExp;
using michlib::uint2;
using michlib::uint4;
using michlib::Floor;
using michlib::Ceil;
using michlib::pointer_cast;
class MODISBINLOCALData
{
@ -32,6 +32,8 @@ class MODISBINLOCALData
};
public:
static constexpr const char* name = "MODISBINLOCAL";
using Data = UngriddedData;
MString Info() const;

2
include/NEMO.h

@ -14,6 +14,8 @@ class NEMOData: public LayeredData
Type type = TYPE_UNKNOWN;
public:
static constexpr const char* name = "NEMO";
NEMOData() = default;
MString DataTitle() const

2
include/NEMOBIO.h

@ -13,6 +13,8 @@ class NEMOBIOData: public LayeredData
Type type = TYPE_UNKNOWN;
public:
static constexpr const char* name = "NEMOBIO";
NEMOBIOData() = default;
MString DataTitle() const

35
include/actions.h

@ -3,7 +3,7 @@
#include "mdatetime.h"
#include "mregex.h"
#include "uvdata.h"
#include <variant>
#include "varhelpers.h"
using michlib::BFileW;
using michlib::MDateTime;
@ -18,7 +18,26 @@ enum class ActionID
GENINTFILE
};
template<ActionID id> struct ActionCarrier
template<ActionID id> struct ActionName;
template<> struct ActionName<ActionID::INFO>
{
static constexpr const char* name = "info";
};
template<> struct ActionName<ActionID::TSC>
{
static constexpr const char* name = "tsc";
};
template<> struct ActionName<ActionID::UV>
{
static constexpr const char* name = "uv";
};
template<> struct ActionName<ActionID::GENINTFILE>
{
static constexpr const char* name = "genintfile";
};
template<ActionID id> struct ActionCarrier: public ActionName<id>
{
constexpr static ActionID action = id;
};
@ -57,16 +76,8 @@ class Action: public ActionVariants
MString Init(const CLArgs& args)
{
MString act = args.contains("action") ? args.at("action") : "info";
if(act == "info")
*this = ActionVariants(ActionCarrier<ActionID::INFO>());
else if(act == "tsc")
*this = ActionVariants(ActionCarrier<ActionID::TSC>());
else if(act == "uv")
*this = ActionVariants(ActionCarrier<ActionID::UV>());
else if(act == "genintfile")
*this = ActionVariants(ActionCarrier<ActionID::GENINTFILE>());
else
return "Unknown action: " + act;
bool res = internal::InitV(*this, act);
if(!res) return "Unknown action: " + act;
return "";
}
};

2
include/data.h

@ -6,7 +6,7 @@
#include "MODISBINLOCAL.h"
#include "NEMO.h"
#include "NEMOBIO.h"
#include <variant>
#include "varhelpers.h"
using DataVariants = std::variant<NEMOData, NEMOBIOData, HYCOMData, AVISOData, AVISOLOCALData, BINFILEData, MODISBINLOCALData>;
class Data: public DataVariants

20
include/varhelpers.h

@ -0,0 +1,20 @@
#pragma once
#include <variant>
namespace internal
{
template<class T1, class... T, class... Vargs> bool InitV1(std::variant<Vargs...>& v, const michlib::MString& n)
{
if(T1::name != n)
{
if constexpr(sizeof...(T) > 0)
return InitV1<T...>(v, n);
else
return false;
}
v = T1();
return true;
}
template<class... Vargs> bool InitV(std::variant<Vargs...>& v, const michlib::MString& n) { return InitV1<Vargs...>(v, n); }
} // namespace internal

56
src/data.cpp

@ -5,56 +5,10 @@ MString Data::Init(const CLArgs& args)
{
MString src = args.contains("source") ? args.at("source") : "";
if(!src.Exist()) return "No source specified";
if(src == "NEMO")
{
NEMOData data;
auto res = data.Open(args);
if(res.Exist()) return "Can't open source " + src + ":\n" + res;
*this = Data(std::move(data));
}
else if(src == "NEMOBIO")
{
NEMOBIOData data;
auto res = data.Open(args);
if(res.Exist()) return "Can't open source " + src + ":\n" + res;
*this = Data(std::move(data));
}
else if(src == "AVISO")
{
AVISOData data;
auto res = data.Open(args);
if(res.Exist()) return "Can't open source " + src + ":\n" + res;
*this = Data(std::move(data));
}
else if(src == "AVISOLOCAL")
{
AVISOLOCALData data;
auto res = data.Open(args);
if(res.Exist()) return "Can't open source " + src + ":\n" + res;
*this = Data(std::move(data));
}
else if(src == "HYCOM")
{
HYCOMData data;
auto res = data.Open(args);
if(res.Exist()) return "Can't open source " + src + ":\n" + res;
*this = Data(std::move(data));
}
else if(src == "BINFILE")
{
BINFILEData data;
auto res = data.Open(args);
if(res.Exist()) return "Can't open source " + src + ":\n" + res;
*this = Data(std::move(data));
}
else if(src == "MODISBINLOCAL")
{
MODISBINLOCALData data;
auto res = data.Open(args);
if(res.Exist()) return "Can't open source " + src + ":\n" + res;
*this = Data(std::move(data));
}
else
return "Unknown source: " + src;
bool res = internal::InitV(*this, src);
if(!res) return "Unknown source: " + src;
auto resop = std::visit([&args = std::as_const(args)](auto& data) -> auto { return data.Open(args); }, *this);
if(resop.Exist()) return "Can't open source " + src + ":\n" + resop;
return "";
}

Loading…
Cancel
Save