Browse Source

The enumeration of actions has been removed, the actions are made independent classes.

Lists of unsupported actions have been added to source classes.
interpolate
Michael Uleysky 1 year ago
parent
commit
5e244b8b4e
  1. 2
      include/BINFILE.h
  2. 2
      include/MODISBINLOCAL.h
  3. 2
      include/NEMOBIO.h
  4. 18
      include/actiongenintfile.h
  5. 15
      include/actioninfo.h
  6. 72
      include/actions.h
  7. 17
      include/actiontsc.h
  8. 14
      include/actionuv.h
  9. 2
      include/basedata.h
  10. 8
      include/odm.h
  11. 38
      include/traits.h
  12. 4
      src/odm.cpp

2
include/BINFILE.h

@ -18,6 +18,8 @@ class BINFILEData
public:
static constexpr const char* name = "BINFILE";
static constexpr const char* disabledactions = "genintfile";
using Data = Simple2DData;
BINFILEData() = default;

2
include/MODISBINLOCAL.h

@ -34,6 +34,8 @@ class MODISBINLOCALData
public:
static constexpr const char* name = "MODISBINLOCAL";
static constexpr const char* disabledactions = "genintfile uv";
using Data = UngriddedData;
MString Info() const;

2
include/NEMOBIO.h

@ -15,6 +15,8 @@ class NEMOBIOData: public LayeredData
public:
static constexpr const char* name = "NEMOBIO";
static constexpr const char* disabledactions = "genintfile uv";
NEMOBIOData() = default;
MString DataTitle() const

18
include/actiongenintfile.h

@ -1,14 +1,24 @@
#pragma once
#include "actions.h"
#include "BFileW.h"
#include "ParseArgs.h"
#include "traits.h"
#include <memory>
using michlib::BFileW;
using michlib::Cos;
using michlib::M_PI;
template<class D> struct DoAction_<D, ActionID::GENINTFILE>
class ActionGenIntFile
{
static MString DoAction(const CLArgs& args, D& data);
public:
static constexpr const char* name = "genintfile";
template<class T> static constexpr bool IsSupported = ReadIsGrid<T>;
template<class D> static MString DoAction(const CLArgs& args, D& data);
};
template<class D> MString DoAction_<D, ActionID::GENINTFILE>::DoAction(const CLArgs& args, D& ds)
template<class D> MString ActionGenIntFile::DoAction(const CLArgs& args, D& ds)
{
michlib_internal::ParameterListEx pars;
pars.UsePrefix("");

15
include/actioninfo.h

@ -1,14 +1,21 @@
#pragma once
#include "actions.h"
#include "ParseArgs.h"
#include "merrors.h"
#include "traits.h"
using michlib::message;
template<class D> struct DoAction_<D, ActionID::INFO>
class ActionInfo
{
static MString DoAction(const CLArgs& args, D& data);
public:
static constexpr const char* name = "info";
template<class T> static constexpr bool IsSupported = InfoSupported<T>;
template<class D> static MString DoAction(const CLArgs& args, D& data);
};
template<class D> MString DoAction_<D, ActionID::INFO>::DoAction([[maybe_unused]] const CLArgs& args, D& data)
template<class D> MString ActionInfo::DoAction([[maybe_unused]] const CLArgs& args, D& data)
{
auto info = data.Info();
if(!info.Exist()) return "No info";

72
include/actions.h

@ -1,72 +1,17 @@
#pragma once
#include "actiongenintfile.h"
#include "actioninfo.h"
#include "actiontsc.h"
#include "actionuv.h"
#include "basedata.h"
#include "mdatetime.h"
#include "mregex.h"
#include "uvdata.h"
#include "varhelpers.h"
using michlib::BFileW;
using michlib::MDateTime;
using TIndex = std::vector<size_t>;
enum class ActionID
{
INFO,
TSC,
UV,
GENINTFILE
};
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;
};
template<class T, ActionID id> struct IsActionSupportedTest
{
static constexpr bool ans = false;
};
template<class T> struct IsActionSupportedTest<T, ActionID::INFO>
{
static constexpr bool ans = InfoSupported<T>;
};
template<class T> struct IsActionSupportedTest<T, ActionID::TSC>
{
static constexpr bool ans = ReadPSupported<T> || ReadSupported<T>;
};
template<class T> struct IsActionSupportedTest<T, ActionID::UV>
{
static constexpr bool ans = ReadPSupported<T> || ReadSupported<T>;
};
template<class T> struct IsActionSupportedTest<T, ActionID::GENINTFILE>
{
static constexpr bool ans = ReadIsGrid<T>;
};
template<class T, ActionID id> constexpr bool IsActionSupported = IsActionSupportedTest<T, id>::ans;
using ActionVariants = std::variant<ActionCarrier<ActionID::INFO>, ActionCarrier<ActionID::TSC>, ActionCarrier<ActionID::UV>, ActionCarrier<ActionID::GENINTFILE>>;
using ActionVariants = std::variant<ActionInfo, ActionTSC, ActionUV, ActionGenIntFile>;
class Action: public ActionVariants
{
@ -82,13 +27,6 @@ class Action: public ActionVariants
}
};
template<class D, ActionID id> struct DoAction_
{
static MString DoAction(const CLArgs& args, D& data) { return "Internal error"; }
};
template<ActionID id, class D> MString DoAction(const CLArgs& args, D& data) { return DoAction_<D, id>::DoAction(args, data); }
template<class D> size_t GetTIndex(const D& data, const MDateTime& t)
{
size_t nt = data.NTimes();

17
include/actiontsc.h

@ -1,12 +1,21 @@
#pragma once
#include "actions.h"
#include "ParseArgs.h"
#include "traits.h"
#include "BFileW.h"
template<class D> struct DoAction_<D, ActionID::TSC>
using michlib::BFileW;
class ActionTSC
{
static MString DoAction(const CLArgs& args, D& data);
public:
static constexpr const char* name = "tsc";
template<class T> static constexpr bool IsSupported = ReadPSupported<T> || ReadSupported<T>;
template<class D> static MString DoAction(const CLArgs& args, D& data);
};
template<class D> MString DoAction_<D, ActionID::TSC>::DoAction(const CLArgs& args, D& ds)
template<class D> MString ActionTSC::DoAction(const CLArgs& args, D& ds)
{
michlib_internal::ParameterListEx pars;
pars.UsePrefix("");

14
include/actionuv.h

@ -1,12 +1,18 @@
#pragma once
#include "actions.h"
#include "ParseArgs.h"
#include "traits.h"
template<class D> struct DoAction_<D, ActionID::UV>
class ActionUV
{
static MString DoAction(const CLArgs& args, D& data);
public:
static constexpr const char* name = "uv";
template<class T> static constexpr bool IsSupported = ReadPSupported<T> || ReadSupported<T>;
template<class D> static MString DoAction(const CLArgs& args, D& data);
};
template<class D> MString DoAction_<D, ActionID::UV>::DoAction(const CLArgs& args, D& ds)
template<class D> MString ActionUV::DoAction(const CLArgs& args, D& ds)
{
michlib_internal::ParameterListEx pars;
pars.UsePrefix("");

2
include/basedata.h

@ -2,6 +2,8 @@
#include "traits.h"
#include <vector>
using TIndex = std::vector<size_t>;
class BaseParameters
{
public:

8
include/odm.h

@ -1,12 +1,11 @@
#pragma once
#include "actiongenintfile.h"
#include "actioninfo.h"
#include "actiontsc.h"
#include "actionuv.h"
#include "actions.h"
#include "data.h"
using michlib::errmessage;
using michlib::message;
/*
template<class T, ActionID id> consteval bool MustSup()
{
static_assert(IsActionSupported<T, id>);
@ -37,3 +36,4 @@ template<> constexpr bool DisableAction<MODISBINLOCALData, ActionID::UV>
template<> constexpr bool DisableAction<MODISBINLOCALData, ActionID::GENINTFILE> = true;
template<> constexpr bool DisableAction<NEMOBIOData, ActionID::UV> = true;
template<> constexpr bool DisableAction<NEMOBIOData, ActionID::GENINTFILE> = true;
*/

38
include/traits.h

@ -56,10 +56,7 @@ concept HaveXYStep = requires(T t) {
t.YStep()
} -> std::convertible_to<real>;
};
}
namespace internal
{
template<typename...> using void_ = void;
template<class D, bool RP, bool R> struct GetReadType_;
@ -75,8 +72,43 @@ template<class D> struct GetReadType_<D, false, true>
using type = decltype(D().Read(MString(), 0));
};
template<class T>
concept HaveDisable = requires(T t) {
{
T::disabledactions
} -> std::convertible_to<const char*>;
};
consteval bool cmpspace(const char* s1, const char* s2)
{
size_t i = 0;
while(true)
{
if(s1[i] != s2[i]) return false;
i++;
if(s1[i] == 0 && (s2[i] == 0 || s2[i] == ' ')) return true;
if(s1[i] == 0 || s2[i] == 0 || s2[i] == ' ') return false;
}
return false;
}
} // namespace internal
template<class Act, class S> consteval bool IsDisabled()
{
if constexpr(!internal::HaveDisable<S>)
return false;
else
{
bool prsp = true;
size_t i = 0;
do {
if(prsp && internal::cmpspace(Act::name, S::disabledactions + i)) return true;
prsp = S::disabledactions[i] == ' ';
} while(S::disabledactions[++i] != 0);
return false;
}
}
template<class D> using ReadType = internal::GetReadType_<D, ReadPSupported<D>, ReadSupported<D>>::type;
template<class T>

4
src/odm.cpp

@ -92,8 +92,8 @@ int main(int argc, char** argv)
[&data = arg, &args = std::as_const(args)](const auto& arg)
{
using AT = std::decay_t<decltype(arg)>;
if constexpr(IsActionSupported<DT, AT::action> && !DisableAction<DT,AT::action>)
return DoAction<AT::action>(args, data);
if constexpr(AT::template IsSupported<DT> && !IsDisabled<AT, DT>())
return AT::DoAction(args, data);
else
return MString("Unsupported combination of action and source");
},

Loading…
Cancel
Save