Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustment to c api #11

Merged
merged 37 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b74f75c
add worfklow
Laurynas-Jagutis Sep 25, 2024
26810ee
adjust workflow
Laurynas-Jagutis Sep 25, 2024
3a6389f
change ssh to http for testing purposes
Laurynas-Jagutis Sep 25, 2024
1b8ce27
adjust workflow
Laurynas-Jagutis Sep 25, 2024
800fdd3
try out brew
Laurynas-Jagutis Sep 25, 2024
427a397
enable dev build for testing
Laurynas-Jagutis Sep 25, 2024
89694c8
remove comments
Laurynas-Jagutis Sep 30, 2024
b813f03
add new workflow
Laurynas-Jagutis Sep 30, 2024
e0ccb1c
delete workflow
Laurynas-Jagutis Sep 30, 2024
4e71951
update c api
Laurynas-Jagutis Oct 2, 2024
bce8295
format files
Laurynas-Jagutis Oct 2, 2024
e613118
add const
Laurynas-Jagutis Oct 2, 2024
646863f
fix some clang tidy issues
Laurynas-Jagutis Oct 2, 2024
ac4c29f
preallocate
Laurynas-Jagutis Oct 2, 2024
5d17092
stop some clang tidy checks
Laurynas-Jagutis Oct 2, 2024
cf1a40b
add const, format
Laurynas-Jagutis Oct 2, 2024
570bad9
fix clang tidy more
Laurynas-Jagutis Oct 2, 2024
10a8517
add a nolint statement
Laurynas-Jagutis Oct 2, 2024
f42fb55
fix clang tidy
Laurynas-Jagutis Oct 7, 2024
ab637af
add const&
Laurynas-Jagutis Oct 7, 2024
9bb6b50
add const
Laurynas-Jagutis Oct 7, 2024
f8abc0d
adjust converter, remove build.yml
Laurynas-Jagutis Oct 7, 2024
070a8cc
add const
Laurynas-Jagutis Oct 7, 2024
fe6b41f
adjust const
Laurynas-Jagutis Oct 7, 2024
1ec0d0f
add cppcoreguidelines-pro-type-member-init check
Laurynas-Jagutis Oct 7, 2024
ede546b
remove -misc-no-recursion from clang tidy, add -cppcoreguidelines-pro…
Laurynas-Jagutis Oct 7, 2024
c69d3cb
reinclude checks to clang tidy file
Laurynas-Jagutis Oct 7, 2024
11c4cfc
change metadata to metadatagen
Laurynas-Jagutis Oct 7, 2024
96928bd
remove reinterpret cast
Laurynas-Jagutis Oct 7, 2024
7f2763e
add const
Laurynas-Jagutis Oct 7, 2024
f43114b
adjust const
Laurynas-Jagutis Oct 7, 2024
80c4a72
disable two clang tidy checks since they are failing on the PGM side
Laurynas-Jagutis Oct 7, 2024
166ea01
fix a sonarcloud smell
Laurynas-Jagutis Oct 7, 2024
23f5c4d
remove unused ssh format, add static, change c api to PGM_IO
Laurynas-Jagutis Oct 7, 2024
0d30b75
Merge remote-tracking branch 'origin/main' into feature/workflows
Laurynas-Jagutis Oct 17, 2024
f531881
change delete to destroy
Laurynas-Jagutis Oct 17, 2024
fd4a65b
change another delete into destroy
Laurynas-Jagutis Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ 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,
Laurynas-Jagutis marked this conversation as resolved.
Show resolved Hide resolved
-cppcoreguidelines-pro-type-reinterpret-cast,
darwin-*,
hiccp-*,
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,
Laurynas-Jagutis marked this conversation as resolved.
Show resolved Hide resolved
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-avoid-c-arrays,
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,52 @@
#define POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_HPP

#include <power_grid_model/auxiliary/dataset.hpp>
#include <power_grid_model/auxiliary/meta_data_gen.hpp>
#include <power_grid_model/auxiliary/serialization/serializer.hpp>
#include <power_grid_model/common/exception.hpp>
#include <power_grid_model/component/node.hpp>
#include <power_grid_model/container.hpp>

#include <iostream>

inline power_grid_model::ConstDataset
create_const_dataset_from_container(power_grid_model::Container<power_grid_model::Node> 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<power_grid_model::Node> convert_node_input();
void convert_line_input();
void convert_sources_input();
void convert_sym_loads_input();
Expand All @@ -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<power_grid_model::Node> const nodes = convert_node_input();
convert_line_input();
convert_sources_input();
convert_sym_loads_input();
Expand All @@ -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<power_grid_model::Node> container;

for (const auto& node : nodes) {
container.emplace<power_grid_model::Node>(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; }
Expand All @@ -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<power_grid_model::Node> PgmVnfConverter::convert_node_input() {
std::vector<power_grid_model::NodeInput> const node_inputs = {{1, 110.0}};
std::vector<power_grid_model::Node> 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() {
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_delete_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_delete_vnf_converter(PGM_IO_VnfConverter* converter_ptr);
Laurynas-Jagutis marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PGM_IO_VnfConverter*>(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<PgmVnfConverter*>(converter_ptr);
auto const* data = reinterpret_cast<ConstDataset const*>(dataset);
convert_input_wrapper(converter, data);
return reinterpret_cast<PGM_IO_ConstDataset const*>(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<PgmVnfConverter*>(converter_ptr);
delete converter;
}
void PGM_IO_delete_vnf_converter(PGM_IO_VnfConverter* converter_ptr) { delete converter_ptr; }
Laurynas-Jagutis marked this conversation as resolved.
Show resolved Hide resolved
Loading