feat(eosIO): added EosIO class to handle arbitrary eos data

EosIO class wraps all eos tables (like helm) so that they can be used in a more standard fashion
This commit is contained in:
2025-03-20 14:25:22 -04:00
parent efa4bdadff
commit 171fbf7961
4 changed files with 232 additions and 46 deletions

34
src/eos/public/eosIO.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef EOSIO_H
#define EOSIO_H
#include <string>
#include <variant>
#include <memory>
// EOS table format includes
#include "helm.h"
using EOSTable = std::variant<
std::unique_ptr<helmholtz::HELMTable>
>;
class EosIO {
private:
std::string m_filename;
bool m_loaded = false;
std::string m_format;
EOSTable m_table;
void load();
// Loaders for each format, right now just HELM
void loadHelm();
public:
EosIO(const std::string filename);
~EosIO() = default;
std::string getFormat() const;
EOSTable& getTable();
};
#endif // EOSIO_H

View File

@@ -35,6 +35,8 @@
#include <string>
#include <format>
#include "debug.h"
/**
* @brief 2D array template alias.
* @tparam T Type of the array elements.
@@ -139,6 +141,118 @@ namespace helmholtz
heap_deallocate_contiguous_2D_memory(xfdt);
}
// // Delete copy constructor and copy assignment operator to prevent accidental shallow copies
// HELMTable(const HELMTable&) = delete;
// HELMTable& operator=(const HELMTable&) = delete;
// // Move constructor
// HELMTable(HELMTable&& other) noexcept
// : loaded(other.loaded),
// f(other.f), fd(other.fd), ft(other.ft), fdd(other.fdd), ftt(other.ftt), fdt(other.fdt),
// fddt(other.fddt), fdtt(other.fdtt), fddtt(other.fddtt),
// dpdf(other.dpdf), dpdfd(other.dpdfd), dpdft(other.dpdft), dpdfdt(other.dpdfdt),
// ef(other.ef), efd(other.efd), eft(other.eft), efdt(other.efdt),
// xf(other.xf), xfd(other.xfd), xft(other.xft), xfdt(other.xfdt)
// {
// other.f = nullptr;
// other.fd = nullptr;
// other.ft = nullptr;
// other.fdd = nullptr;
// other.ftt = nullptr;
// other.fdt = nullptr;
// other.fddt = nullptr;
// other.fdtt = nullptr;
// other.fddtt = nullptr;
// other.dpdf = nullptr;
// other.dpdfd = nullptr;
// other.dpdft = nullptr;
// other.dpdfdt = nullptr;
// other.ef = nullptr;
// other.efd = nullptr;
// other.eft = nullptr;
// other.efdt = nullptr;
// other.xf = nullptr;
// other.xfd = nullptr;
// other.xft = nullptr;
// other.xfdt = nullptr;
// }
// // Move assignment operator
// HELMTable& operator=(HELMTable&& other) noexcept {
// if (this != &other) {
// // Deallocate current memory
// heap_deallocate_contiguous_2D_memory(f);
// heap_deallocate_contiguous_2D_memory(fd);
// heap_deallocate_contiguous_2D_memory(ft);
// heap_deallocate_contiguous_2D_memory(fdd);
// heap_deallocate_contiguous_2D_memory(ftt);
// heap_deallocate_contiguous_2D_memory(fdt);
// heap_deallocate_contiguous_2D_memory(fddt);
// heap_deallocate_contiguous_2D_memory(fdtt);
// heap_deallocate_contiguous_2D_memory(fddtt);
// heap_deallocate_contiguous_2D_memory(dpdf);
// heap_deallocate_contiguous_2D_memory(dpdfd);
// heap_deallocate_contiguous_2D_memory(dpdft);
// heap_deallocate_contiguous_2D_memory(dpdfdt);
// heap_deallocate_contiguous_2D_memory(ef);
// heap_deallocate_contiguous_2D_memory(efd);
// heap_deallocate_contiguous_2D_memory(eft);
// heap_deallocate_contiguous_2D_memory(efdt);
// heap_deallocate_contiguous_2D_memory(xf);
// heap_deallocate_contiguous_2D_memory(xfd);
// heap_deallocate_contiguous_2D_memory(xft);
// heap_deallocate_contiguous_2D_memory(xfdt);
// // Transfer ownership of resources
// loaded = other.loaded;
// f = other.f;
// fd = other.fd;
// ft = other.ft;
// fdd = other.fdd;
// ftt = other.ftt;
// fdt = other.fdt;
// fddt = other.fddt;
// fdtt = other.fdtt;
// fddtt = other.fddtt;
// dpdf = other.dpdf;
// dpdfd = other.dpdfd;
// dpdft = other.dpdft;
// dpdfdt = other.dpdfdt;
// ef = other.ef;
// efd = other.efd;
// eft = other.eft;
// efdt = other.efdt;
// xf = other.xf;
// xfd = other.xfd;
// xft = other.xft;
// xfdt = other.xfdt;
// // Null out the other object's pointers
// other.f = nullptr;
// other.fd = nullptr;
// other.ft = nullptr;
// other.fdd = nullptr;
// other.ftt = nullptr;
// other.fdt = nullptr;
// other.fddt = nullptr;
// other.fdtt = nullptr;
// other.fddtt = nullptr;
// other.dpdf = nullptr;
// other.dpdfd = nullptr;
// other.dpdft = nullptr;
// other.dpdfdt = nullptr;
// other.ef = nullptr;
// other.efd = nullptr;
// other.eft = nullptr;
// other.efdt = nullptr;
// other.xf = nullptr;
// other.xfd = nullptr;
// other.xft = nullptr;
// other.xfdt = nullptr;
// }
// return *this;
// }
friend std::ostream& operator<<(std::ostream& os, const helmholtz::HELMTable& table) {
if (!table.loaded) {
os << "HELMTable not loaded\n";
@@ -371,7 +485,7 @@ namespace helmholtz
* @param filename Path to the file containing the table.
* @return HELMTable structure containing the table data.
*/
HELMTable read_helm_table(const std::string filename);
std::unique_ptr<HELMTable> read_helm_table(const std::string filename);
/**
* @brief Calculate the Helmholtz EOS components.