diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-07-10 14:15:40 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-07-10 14:15:40 +0200 |
commit | ff066b06a82f0ab330dab3ceb2d4b7132727f861 (patch) | |
tree | 1e6b8d0d85bbb7d5c441af36913d1da2ea2ef523 /tools/c_lang_bind.cpp |
Initial commit
Diffstat (limited to 'tools/c_lang_bind.cpp')
-rw-r--r-- | tools/c_lang_bind.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/c_lang_bind.cpp b/tools/c_lang_bind.cpp new file mode 100644 index 0000000..f0ecf0d --- /dev/null +++ b/tools/c_lang_bind.cpp @@ -0,0 +1,49 @@ +#include <forstio/buffer.hpp> +#include <forstio/codec/schema.hpp> +#include <forstio/tools/c_gen_iface.hpp> + +#include <iostream> +#include <fstream> + +namespace sch { +using namespace saw::schema; + +using ExStruct = Struct< + Member<Float64, "dob">, + Member<Int16, "int24"> +>; + +using ExInterface = Interface< + Member<Function<Int32, ExStruct>, "foo">, + Member<Function<UInt64, Float32>, "bar"> +>; +} + +int main(){ + using namespace saw; + + ring_buffer src{4096*1024}; + ring_buffer hdr{4096*1024}; + language_binding_config cfg; + cfg.prefix = "forstio_example"; + auto eov = language_binding<sch::ExInterface, binding::SyncC>::generate(hdr, src,cfg); + if(eov.is_error()){ + auto& err = eov.get_error(); + std::cerr<<"Error: "<<err.get_category(); + auto msg = err.get_message(); + if(msg.size() > 0){ + std::cerr<<" - "<<msg; + } + std::cerr<<std::endl; + return err.get_id(); + } + + std::ofstream src_file{cfg.prefix + ".cpp"}; + src_file << convert_to_string(src); + src_file.close(); + std::ofstream hdr_file{cfg.prefix + ".hpp"}; + hdr_file << convert_to_string(hdr); + hdr_file.close(); + + return 0; +} |