summaryrefslogtreecommitdiff
path: root/tools/c_lang_bind.cpp
blob: f0ecf0db8fa3834a5ba6e0c520302899d1b8c1f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}