diff --git a/.clang-tidy b/.clang-tidy index 2ff94f7..911ca71 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -14,7 +14,9 @@ cppcoreguidelines-*, -cppcoreguidelines-avoid-c-arrays, -cppcoreguidelines-owning-memory, -cppcoreguidelines-avoid-magic-numbers, +-cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, +-cppcoreguidelines-pro-type-member-init, -cppcoreguidelines-pro-type-reinterpret-cast, darwin-*, hiccp-*, @@ -22,8 +24,11 @@ llvm-*, -llvm-header-guard, google-*, -google-build-using-namespace, --google-explicit-constructor +-google-default-arguments, +-google-explicit-constructor, +-google-readability-todo, misc-*, +-misc-no-recursion, -misc-non-private-member-variables-in-classes, modernize-*, -modernize-avoid-c-arrays, diff --git a/.gitmodules b/.gitmodules index cfe160c..6808c93 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,5 +4,5 @@ [submodule "deps/power-grid-model"] path = deps/power-grid-model - url = git@github.com:PowerGridModel/power-grid-model.git + url = https://github.com/PowerGridModel/power-grid-model.git branch = main diff --git a/power_grid_model_io_native_c/power_grid_model_io_native/include/power_grid_model_io_native/vnf_converter/vnf_pgm_converter.hpp b/power_grid_model_io_native_c/power_grid_model_io_native/include/power_grid_model_io_native/vnf_converter/vnf_pgm_converter.hpp index 4c104ca..ddb2272 100644 --- a/power_grid_model_io_native_c/power_grid_model_io_native/include/power_grid_model_io_native/vnf_converter/vnf_pgm_converter.hpp +++ b/power_grid_model_io_native_c/power_grid_model_io_native/include/power_grid_model_io_native/vnf_converter/vnf_pgm_converter.hpp @@ -7,35 +7,52 @@ #define POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_HPP #include +#include +#include #include +#include +#include #include +inline power_grid_model::ConstDataset +create_const_dataset_from_container(power_grid_model::Container const& /*container*/, + power_grid_model::meta_data::MetaData const& meta_data) { + // for now leave it empty + std::string_view const dataset_name = "empty_dataset"; + power_grid_model::ConstDataset const_dataset{false, 1, dataset_name, meta_data}; + return const_dataset; +} + +inline std::string serialize_data(power_grid_model::ConstDataset const& const_dataset) { + power_grid_model::meta_data::Serializer serializer(const_dataset, power_grid_model::SerializationFormat::json); + std::string serialized_pgm_data = serializer.get_string(false, -1); + return serialized_pgm_data; +} + class PgmVnfConverter { public: PgmVnfConverter(char* buffer = nullptr, power_grid_model::WritableDataset* data = nullptr); // Public member functions void parse_vnf_file(); - power_grid_model::ConstDataset const* convert_input(power_grid_model::ConstDataset const* dataset); + void convert_input(); + + std::string const& get_serialized_data() const; + void set_file_buffer(char* file_buffer); + void set_deserialized_data(power_grid_model::WritableDataset* deserialized_data); + char* get_file_buffer(); + power_grid_model::WritableDataset* get_deserialized_data(); private: // Private attributes char* f_file_buffer; power_grid_model::WritableDataset* deserialized_data; // this type because it is generated by a deserializer type structure - - // Private setters/getters - void set_file_buffer(char* file_buffer); - - void set_deserialized_data(power_grid_model::WritableDataset* deserialized_data); - - char* get_file_buffer(); - - power_grid_model::WritableDataset* get_deserialized_data(); + std::string serialized_data; // Private member functions - void convert_node_input(); + static std::vector convert_node_input(); void convert_line_input(); void convert_sources_input(); void convert_sym_loads_input(); @@ -58,9 +75,8 @@ inline void PgmVnfConverter::parse_vnf_file() { // will be implemented later } -inline power_grid_model::ConstDataset const* -PgmVnfConverter::convert_input(power_grid_model::ConstDataset const* /*dataset*/) { - convert_node_input(); +inline void PgmVnfConverter::convert_input() { + std::vector const nodes = convert_node_input(); convert_line_input(); convert_sources_input(); convert_sym_loads_input(); @@ -69,11 +85,23 @@ PgmVnfConverter::convert_input(power_grid_model::ConstDataset const* /*dataset*/ convert_sym_gens_input(); convert_links_input(); - // then return the buffer - // return pgm_input_data; - // for now. - power_grid_model::ConstDataset* fake_data = nullptr; - return fake_data; + power_grid_model::Container container; + + for (const auto& node : nodes) { + container.emplace(node.id(), node); + } + + constexpr const auto& meta_data = power_grid_model::meta_data::meta_data_gen::meta_data; + power_grid_model::ConstDataset const const_dataset = create_const_dataset_from_container(container, meta_data); + + std::string const serialized_pgm_data = serialize_data(const_dataset); + + // 1. our vnf importer it directly understands the vnf format + // 2. convert vnf like dataset to internal types (take raw data and convert it to pgm component container) + // 3. another function which 1. makes const dataset view from pgm component container 2. const dataset to + // serializer + + this->serialized_data = serialized_pgm_data; } inline void PgmVnfConverter::set_file_buffer(char* file_buffer) { this->f_file_buffer = file_buffer; } @@ -86,8 +114,18 @@ inline char* PgmVnfConverter::get_file_buffer() { return this->f_file_buffer; } inline power_grid_model::WritableDataset* PgmVnfConverter::get_deserialized_data() { return this->deserialized_data; } -inline void PgmVnfConverter::convert_node_input() { - // Implementation +inline std::string const& PgmVnfConverter::get_serialized_data() const { return this->serialized_data; } + +inline std::vector PgmVnfConverter::convert_node_input() { + std::vector const node_inputs = {{1, 110.0}}; + std::vector nodes; + + nodes.reserve(node_inputs.size()); + for (const auto& node_input : node_inputs) { + nodes.emplace_back(node_input); + } + + return nodes; } inline void PgmVnfConverter::convert_line_input() { @@ -120,9 +158,9 @@ inline void PgmVnfConverter::convert_links_input() { inline void parse_vnf_file_wrapper(PgmVnfConverter* obj) { obj->parse_vnf_file(); } -inline power_grid_model::ConstDataset const* convert_input_wrapper(PgmVnfConverter* obj, - power_grid_model::ConstDataset const* dataset) { - return obj->convert_input(dataset); +inline std::string const& convert_input_wrapper(PgmVnfConverter* obj) { + obj->convert_input(); + return obj->get_serialized_data(); } #endif // POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_HPP diff --git a/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/basics.h b/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/basics.h index ca1b243..209b899 100644 --- a/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/basics.h +++ b/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/basics.h @@ -70,12 +70,6 @@ typedef int32_t PGM_IO_ID; */ typedef struct PGM_IO_VnfConverter PGM_IO_VnfConverter; -/** - * @brief Opaque struct for the ConstDataset. - * - */ -typedef struct PGM_IO_ConstDataset PGM_IO_ConstDataset; - /** * @brief Opaque struct for the handle class. * diff --git a/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/vnf_pgm_converter.h b/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/vnf_pgm_converter.h index d6fcb75..9dbfb9c 100644 --- a/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/vnf_pgm_converter.h +++ b/power_grid_model_io_native_c/power_grid_model_io_native_c/include/power_grid_model_io_native_c/vnf_pgm_converter.h @@ -13,29 +13,28 @@ extern "C" { #endif /** - * @brief Create the PGM_VNF_converter + * @brief Create the PGM_IO_VnfConverter * @param handle * @param file_buffer A pointer to the null-terminated C string. - * @return The pointer to a PGM_VNF_converter instance. The instance must be freed by - * PGM_VNF_delete_Converter + * @return The pointer to a PGM_IO_VnfConverter instance. The instance must be freed by + * PGM_IO_destroy_vnf_converter. */ -PGM_IO_API PGM_IO_VnfConverter* PGM_VNF_create_converter(PGM_IO_Handle* handle, char* file_buffer); +PGM_IO_API PGM_IO_VnfConverter* PGM_IO_create_vnf_converter(PGM_IO_Handle* handle, char* file_buffer); /** * @brief Retrieve the transformed input data from .vnf format to PGM format * @param handle - * @param converter_ptr A pointer to a PGM_VNF_converter instace. + * @param converter_ptr A pointer to a PGM_IO_VnfConverter instace. * @param dataset A pointer to the const dataset supplied by the user. * @return The pointer to the const dataset instance supplied by the user which has been filled in. */ -PGM_IO_API PGM_IO_ConstDataset const* PGM_VNF_get_input_data(PGM_IO_Handle* handle, PGM_IO_VnfConverter* converter_ptr, - PGM_IO_ConstDataset const* dataset); +PGM_IO_API char const* PGM_IO_get_vnf_input_data(PGM_IO_Handle* handle, PGM_IO_VnfConverter* converter_ptr); /** - * @brief Destroy the converter and free up the memory that was dedicated to it. - * @param converter_ptr A pointer to a PGM_VNF_converter instance. + * @brief Destroy the PGM_IO_VnfConverter and free up the memory that was dedicated to it. + * @param converter_ptr A pointer to a PGM_IO_VnfConverter instance. */ -PGM_IO_API void PGM_VNF_delete_Converter(PGM_IO_VnfConverter* converter_ptr); +PGM_IO_API void PGM_IO_destroy_vnf_converter(PGM_IO_VnfConverter* converter_ptr); #ifdef __cplusplus } diff --git a/power_grid_model_io_native_c/power_grid_model_io_native_c/src/vnf_pgm_converter.cpp b/power_grid_model_io_native_c/power_grid_model_io_native_c/src/vnf_pgm_converter.cpp index 6872acc..9b78b96 100644 --- a/power_grid_model_io_native_c/power_grid_model_io_native_c/src/vnf_pgm_converter.cpp +++ b/power_grid_model_io_native_c/power_grid_model_io_native_c/src/vnf_pgm_converter.cpp @@ -14,22 +14,19 @@ using power_grid_model::ConstDataset; -// TODO(Laurynas-Jagutis) add call_with_catch for these functions -PGM_IO_VnfConverter* PGM_VNF_create_converter(const PGM_IO_Handle* /*handle*/, char* file_buffer) { - auto* converter = new PgmVnfConverter(file_buffer); +struct PGM_IO_VnfConverter : public PgmVnfConverter { + using PgmVnfConverter::PgmVnfConverter; +}; + +// TODO(Laurynas-Jagutis) add call_with_catch for these functions. +PGM_IO_VnfConverter* PGM_IO_create_vnf_converter(const PGM_IO_Handle* /*handle*/, char* file_buffer) { + auto* converter = new PGM_IO_VnfConverter(file_buffer); parse_vnf_file_wrapper(converter); - return reinterpret_cast(converter); + return converter; } -PGM_IO_ConstDataset const* PGM_VNF_get_input_data(const PGM_IO_Handle* /*handle*/, PGM_IO_VnfConverter* converter_ptr, - PGM_IO_ConstDataset const* dataset) { - auto* converter = reinterpret_cast(converter_ptr); - auto const* data = reinterpret_cast(dataset); - convert_input_wrapper(converter, data); - return reinterpret_cast(data); +char const* PGM_IO_get_vnf_input_data(const PGM_IO_Handle* /*handle*/, PGM_IO_VnfConverter* converter_ptr) { + return convert_input_wrapper(converter_ptr).c_str(); } -void PGM_VNF_delete_Converter(PGM_IO_VnfConverter* converter_ptr) { - auto* converter = reinterpret_cast(converter_ptr); - delete converter; -} +void PGM_IO_destroy_vnf_converter(PGM_IO_VnfConverter* converter_ptr) { delete converter_ptr; }