From 5e244b8b4e762e853904fda42b0d56dbcc1a83f9 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Sun, 11 Jun 2023 20:01:58 +1000 Subject: [PATCH] The enumeration of actions has been removed, the actions are made independent classes. Lists of unsupported actions have been added to source classes. --- include/BINFILE.h | 2 ++ include/MODISBINLOCAL.h | 2 ++ include/NEMOBIO.h | 2 ++ include/actiongenintfile.h | 18 +++++++--- include/actioninfo.h | 15 +++++--- include/actions.h | 72 +++----------------------------------- include/actiontsc.h | 17 ++++++--- include/actionuv.h | 14 +++++--- include/basedata.h | 2 ++ include/odm.h | 8 ++--- include/traits.h | 38 ++++++++++++++++++-- src/odm.cpp | 4 +-- 12 files changed, 102 insertions(+), 92 deletions(-) diff --git a/include/BINFILE.h b/include/BINFILE.h index 42f145e..00018cc 100644 --- a/include/BINFILE.h +++ b/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; diff --git a/include/MODISBINLOCAL.h b/include/MODISBINLOCAL.h index 04e5590..88fb4f4 100644 --- a/include/MODISBINLOCAL.h +++ b/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; diff --git a/include/NEMOBIO.h b/include/NEMOBIO.h index 53573aa..2b7ac85 100644 --- a/include/NEMOBIO.h +++ b/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 diff --git a/include/actiongenintfile.h b/include/actiongenintfile.h index fa74910..53d7a8e 100644 --- a/include/actiongenintfile.h +++ b/include/actiongenintfile.h @@ -1,14 +1,24 @@ #pragma once -#include "actions.h" +#include "BFileW.h" +#include "ParseArgs.h" +#include "traits.h" +#include +using michlib::BFileW; using michlib::Cos; +using michlib::M_PI; -template struct DoAction_ +class ActionGenIntFile { - static MString DoAction(const CLArgs& args, D& data); + public: + static constexpr const char* name = "genintfile"; + + template static constexpr bool IsSupported = ReadIsGrid; + + template static MString DoAction(const CLArgs& args, D& data); }; -template MString DoAction_::DoAction(const CLArgs& args, D& ds) +template MString ActionGenIntFile::DoAction(const CLArgs& args, D& ds) { michlib_internal::ParameterListEx pars; pars.UsePrefix(""); diff --git a/include/actioninfo.h b/include/actioninfo.h index 7d516c1..43855b5 100644 --- a/include/actioninfo.h +++ b/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 struct DoAction_ +class ActionInfo { - static MString DoAction(const CLArgs& args, D& data); + public: + static constexpr const char* name = "info"; + + template static constexpr bool IsSupported = InfoSupported; + + template static MString DoAction(const CLArgs& args, D& data); }; -template MString DoAction_::DoAction([[maybe_unused]] const CLArgs& args, D& data) +template MString ActionInfo::DoAction([[maybe_unused]] const CLArgs& args, D& data) { auto info = data.Info(); if(!info.Exist()) return "No info"; diff --git a/include/actions.h b/include/actions.h index cb1fa58..c54510f 100644 --- a/include/actions.h +++ b/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; - -enum class ActionID -{ - INFO, - TSC, - UV, - GENINTFILE -}; - -template struct ActionName; - -template<> struct ActionName -{ - static constexpr const char* name = "info"; -}; -template<> struct ActionName -{ - static constexpr const char* name = "tsc"; -}; -template<> struct ActionName -{ - static constexpr const char* name = "uv"; -}; -template<> struct ActionName -{ - static constexpr const char* name = "genintfile"; -}; - -template struct ActionCarrier: public ActionName -{ - constexpr static ActionID action = id; -}; - -template struct IsActionSupportedTest -{ - static constexpr bool ans = false; -}; - -template struct IsActionSupportedTest -{ - static constexpr bool ans = InfoSupported; -}; -template struct IsActionSupportedTest -{ - static constexpr bool ans = ReadPSupported || ReadSupported; -}; -template struct IsActionSupportedTest -{ - static constexpr bool ans = ReadPSupported || ReadSupported; -}; -template struct IsActionSupportedTest -{ - static constexpr bool ans = ReadIsGrid; -}; - -template constexpr bool IsActionSupported = IsActionSupportedTest::ans; - -using ActionVariants = std::variant, ActionCarrier, ActionCarrier, ActionCarrier>; +using ActionVariants = std::variant; class Action: public ActionVariants { @@ -82,13 +27,6 @@ class Action: public ActionVariants } }; -template struct DoAction_ -{ - static MString DoAction(const CLArgs& args, D& data) { return "Internal error"; } -}; - -template MString DoAction(const CLArgs& args, D& data) { return DoAction_::DoAction(args, data); } - template size_t GetTIndex(const D& data, const MDateTime& t) { size_t nt = data.NTimes(); diff --git a/include/actiontsc.h b/include/actiontsc.h index 587935a..943730c 100644 --- a/include/actiontsc.h +++ b/include/actiontsc.h @@ -1,12 +1,21 @@ #pragma once -#include "actions.h" +#include "ParseArgs.h" +#include "traits.h" +#include "BFileW.h" -template struct DoAction_ +using michlib::BFileW; + +class ActionTSC { - static MString DoAction(const CLArgs& args, D& data); + public: + static constexpr const char* name = "tsc"; + + template static constexpr bool IsSupported = ReadPSupported || ReadSupported; + + template static MString DoAction(const CLArgs& args, D& data); }; -template MString DoAction_::DoAction(const CLArgs& args, D& ds) +template MString ActionTSC::DoAction(const CLArgs& args, D& ds) { michlib_internal::ParameterListEx pars; pars.UsePrefix(""); diff --git a/include/actionuv.h b/include/actionuv.h index 4b756da..ceb0779 100644 --- a/include/actionuv.h +++ b/include/actionuv.h @@ -1,12 +1,18 @@ #pragma once -#include "actions.h" +#include "ParseArgs.h" +#include "traits.h" -template struct DoAction_ +class ActionUV { - static MString DoAction(const CLArgs& args, D& data); + public: + static constexpr const char* name = "uv"; + + template static constexpr bool IsSupported = ReadPSupported || ReadSupported; + + template static MString DoAction(const CLArgs& args, D& data); }; -template MString DoAction_::DoAction(const CLArgs& args, D& ds) +template MString ActionUV::DoAction(const CLArgs& args, D& ds) { michlib_internal::ParameterListEx pars; pars.UsePrefix(""); diff --git a/include/basedata.h b/include/basedata.h index 41082c7..c78c574 100644 --- a/include/basedata.h +++ b/include/basedata.h @@ -2,6 +2,8 @@ #include "traits.h" #include +using TIndex = std::vector; + class BaseParameters { public: diff --git a/include/odm.h b/include/odm.h index 780f7c3..7b798dd 100644 --- a/include/odm.h +++ b/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 consteval bool MustSup() { static_assert(IsActionSupported); @@ -37,3 +36,4 @@ template<> constexpr bool DisableAction template<> constexpr bool DisableAction = true; template<> constexpr bool DisableAction = true; template<> constexpr bool DisableAction = true; +*/ diff --git a/include/traits.h b/include/traits.h index 0345059..d4640aa 100644 --- a/include/traits.h +++ b/include/traits.h @@ -56,10 +56,7 @@ concept HaveXYStep = requires(T t) { t.YStep() } -> std::convertible_to; }; -} -namespace internal -{ template using void_ = void; template struct GetReadType_; @@ -75,8 +72,43 @@ template struct GetReadType_ using type = decltype(D().Read(MString(), 0)); }; +template +concept HaveDisable = requires(T t) { + { + T::disabledactions + } -> std::convertible_to; +}; + +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 consteval bool IsDisabled() +{ + if constexpr(!internal::HaveDisable) + 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 using ReadType = internal::GetReadType_, ReadSupported>::type; template diff --git a/src/odm.cpp b/src/odm.cpp index 6051b70..e2756ce 100644 --- a/src/odm.cpp +++ b/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; - if constexpr(IsActionSupported && !DisableAction) - return DoAction(args, data); + if constexpr(AT::template IsSupported
&& !IsDisabled()) + return AT::DoAction(args, data); else return MString("Unsupported combination of action and source"); },