Browse Source

Generate list of available actions

interpolate
Michael Uleysky 2 years ago
parent
commit
fb7000b2ab
  1. 1
      .gitignore
  2. 13
      actions/actiongenintfile.h
  3. 15
      actions/actioninfo.h
  4. 14
      actions/actiontsc.h
  5. 15
      actions/actionuv.h
  6. 16
      include/actiondep.h
  7. 24
      include/actioninfo.h
  8. 7
      include/actions.h
  9. 53
      scripts/genactionslist
  10. 11
      src/CMakeLists.txt

1
.gitignore vendored

@ -2,3 +2,4 @@
*.so
*.kdev4
.kdev4/*
actions-add/*

13
include/actiongenintfile.h → actions/actiongenintfile.h

@ -1,22 +1,13 @@
#pragma once
#include "BFileW.h"
#include "ParseArgs.h"
#include "traits.h"
#include "actiondep.h"
#include <memory>
using michlib::BFileW;
using michlib::Cos;
using michlib::M_PI;
class ActionGenIntFile
{
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);
};
ADD_ACTION(GenIntFile, genintfile, ReadIsGrid<Source>);
template<class D> MString ActionGenIntFile::DoAction(const CLArgs& args, D& ds)
{

15
actions/actioninfo.h

@ -0,0 +1,15 @@
#pragma once
#include "actiondep.h"
#include "merrors.h"
using michlib::message;
ADD_ACTION(Info, info, InfoSupported<Source>);
template<class D> MString ActionInfo::DoAction([[maybe_unused]] const CLArgs& args, D& data)
{
auto info = data.Info();
if(!info.Exist()) return "No info";
message(info);
return "";
};

14
include/actiontsc.h → actions/actiontsc.h

@ -1,19 +1,11 @@
#pragma once
#include "ParseArgs.h"
#include "traits.h"
#include "actiondep.h"
#include "BFileW.h"
#include <memory>
using michlib::BFileW;
class ActionTSC
{
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);
};
ADD_ACTION(TSC, tsc, ReadPSupported<Source> || ReadSupported<Source>);
template<class D> MString ActionTSC::DoAction(const CLArgs& args, D& ds)
{

15
include/actionuv.h → actions/actionuv.h

@ -1,16 +1,11 @@
#pragma once
#include "ParseArgs.h"
#include "traits.h"
#include "actiondep.h"
#include "BFileW.h"
#include <memory>
class ActionUV
{
public:
static constexpr const char* name = "uv";
template<class T> static constexpr bool IsSupported = ReadPSupported<T> || ReadSupported<T>;
using michlib::BFileW;
template<class D> static MString DoAction(const CLArgs& args, D& data);
};
ADD_ACTION(UV, uv, ReadPSupported<Source> || ReadSupported<Source>);
template<class D> MString ActionUV::DoAction(const CLArgs& args, D& ds)
{

16
include/actiondep.h

@ -0,0 +1,16 @@
#pragma once
#include "ParseArgs.h"
#include "traits.h"
#if defined GENACTIONLIST
#define ADD_ACTION(actclass, actname, suptest) ADD ACTION CLASS: actclass
#else
#define ADD_ACTION(actclass, actname, suptest) \
class Action##actclass \
{ \
public: \
static constexpr const char* name = #actname; \
template<class Source> static constexpr bool IsSupported = (suptest); \
template<class Source> static MString DoAction(const CLArgs& args, Source& data); \
};
#endif

24
include/actioninfo.h

@ -1,24 +0,0 @@
#pragma once
#include "ParseArgs.h"
#include "merrors.h"
#include "traits.h"
using michlib::message;
class ActionInfo
{
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 ActionInfo::DoAction([[maybe_unused]] const CLArgs& args, D& data)
{
auto info = data.Info();
if(!info.Exist()) return "No info";
message(info);
return "";
};

7
include/actions.h

@ -1,8 +1,5 @@
#pragma once
#include "actiongenintfile.h"
#include "actioninfo.h"
#include "actiontsc.h"
#include "actionuv.h"
#include "actionlist.h"
#include "basedata.h"
#include "mdatetime.h"
#include "mregex.h"
@ -11,7 +8,7 @@
using michlib::MDateTime;
using ActionVariants = std::variant<ActionInfo, ActionTSC, ActionUV, ActionGenIntFile>;
using ActionVariants = std::variant<ACTLIST>;
class Action: public ActionVariants
{

53
scripts/genactionslist

@ -0,0 +1,53 @@
#!/bin/bash
DIR="$(dirname $0)/../include"
COMPILER="$1"
OUT="$2"
shift
shift
declare -a EXCLUDE_ACTIONS=( $@ )
included()
{
local name="$1"
local i=0
while [ $i -lt ${#EXCLUDE_ACTIONS[@]} ]; do
if [ "$name" == "${EXCLUDE_ACTIONS[$i]}" ]; then
return 1
fi
let i++
done
return 0
}
if [ -z "$COMPILER" ]; then
exit 1
fi
actlist=""
echo "">"$OUT"
cdir="$(pwd)"
pushd "$DIR">/dev/null
for f in ../actions/action*.h ../actions-add/action*.h; do
if [ -f "$f" ]; then
# echo Compiler=$COMPILER
# echo Exclude list=${EXCLUDE_ACTIONS[@]}
name="$($COMPILER -E -DGENACTIONLIST "$f" 2>/dev/null| grep "ADD ACTION CLASS: " | sed "s/.*: //")"
name=${name//;/}
if included "$name"; then
pushd "$cdir">/dev/null
echo "#include \"$f\"">>"$OUT"
actlist+=" Action$name"
popd>/dev/null
fi
fi
done
actlist=${actlist## }
actlist=${actlist%% }
actlist=${actlist// /,}
pushd "$cdir">/dev/null
echo "#define ACTLIST $actlist">>"$OUT"
popd>/dev/null

11
src/CMakeLists.txt

@ -1,13 +1,18 @@
set(EXENAME odm)
set(ACTIONLIST ../include/actionlist.h)
set(GENALIST ${CMAKE_SOURCE_DIR}/scripts/genactionslist)
find_library(netcdf netcdf REQUIRED)
find_package(OpenMP REQUIRED)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
include_directories(../michlib/michlib)
file(GLOB srcs CONFIGURE_DEPENDS *.cpp)
add_executable(${EXENAME} ${srcs} ${ACTIONLIST})
target_include_directories(${EXENAME} PRIVATE ../michlib/michlib ${CMAKE_CURRENT_BINARY_DIR}/../include)
file(GLOB actfiles CONFIGURE_DEPENDS ../actions/action*.h ../actions-add/action*.h)
add_custom_command(OUTPUT ${ACTIONLIST} COMMAND ${GENALIST} ARGS "${CMAKE_CXX_COMPILER} -I$<JOIN:$<TARGET_PROPERTY:${EXENAME},INCLUDE_DIRECTORIES>, -I>" ${ACTIONLIST} ${EXCLUDE_ACTIONS} DEPENDS ${GENALIST} ${actfiles})
file(GLOB srcs *.cpp)
add_executable(${EXENAME} ${srcs})
target_link_libraries(${EXENAME} ${linker_options} ${netcdf} OpenMP::OpenMP_CXX teos)
set_target_properties(${EXENAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
install(TARGETS ${EXENAME})

Loading…
Cancel
Save