netgen/libsrc/interface/writeuser.hpp

72 lines
2.5 KiB
C++
Raw Normal View History

#ifndef WRITEUSER
#define WRITEUSER
/**************************************************************************/
/* File: writeuser.hh */
/* Authors: many */
/* Date: 10. Dec. 97 */
/**************************************************************************/
2023-10-09 20:41:02 +02:00
#include <filesystem>
#include <functional>
#include <optional>
2023-10-09 20:41:02 +02:00
#include <meshing.hpp>
2023-10-09 20:41:02 +02:00
namespace netgen {
2023-10-09 20:41:02 +02:00
using namespace std::filesystem;
typedef std::function<void (const Mesh & mesh, const filesystem::path & filename)> FWrite;
typedef std::function<void (Mesh & mesh, const filesystem::path & filename)> FRead;
typedef std::function<bool (const filesystem::path & filename)> FTest;
struct UserFormatRegister {
struct UserFormatEntry {
string format;
Array<string> extensions;
optional<FRead> read;
optional<FWrite> write;
};
static void Register(UserFormatEntry && entry);
2023-10-09 20:41:02 +02:00
static const bool HaveFormat(string format);
DLL_HEADER static const UserFormatEntry & Get(string format);
2023-10-09 20:41:02 +02:00
template<typename TFunc>
static void IterateFormats(TFunc func, bool need_read=false, bool need_write=false) {
Array<string> import_formats;
for(const auto & e: getFormats())
if((!need_read || e.second.read) && (!need_write || e.second.write))
import_formats.Append(e.second.format);
2023-10-09 20:41:02 +02:00
QuickSort(import_formats);
for(auto format : import_formats)
func(Get(format));
2023-10-09 20:41:02 +02:00
}
DLL_HEADER static std::map<std::string, UserFormatEntry>& getFormats();
2023-10-09 20:41:02 +02:00
};
struct RegisterUserFormat {
RegisterUserFormat(string format, Array<string> extensions, optional<FRead> read, optional<FWrite> write, FTest ftest = [](const filesystem::path & ){return true;})
{
UserFormatRegister::Register({format, std::move(extensions), std::move(read), std::move(write)});
}
};
DLL_HEADER void ReadFile(Mesh & mesh, const filesystem::path & filename);
DLL_HEADER void ReadUserFormat(Mesh & mesh, const filesystem::path & filename, const string & format = "");
extern bool DLL_HEADER WriteUserFormat (const string & format,
const Mesh & mesh,
const filesystem::path & filename);
2019-07-09 10:39:16 +02:00
extern void DLL_HEADER RegisterUserFormats (NgArray<const char*> & names,
NgArray<const char*> & extensions);
2016-07-10 18:07:36 +02:00
}
#endif