}
void CsProxyGen::GenInterop(std::ofstream& stream) {
- GenCodeBlock("cs_interop.cb", [](Generator& gen, int pos) {
- gen.GenCodeBlock("cs_proxy_interop.cb");
+ GenCodeBlock("cs_interop.cb", [&](int pos) {
+ GenCodeBlock("cs_proxy_interop.cb");
});
}
void CsStubGen::OnFiniGen(std::ofstream& stream) {}
void CsStubGen::GenInterop(std::ofstream& stream) {
- GenCodeBlock("cs_interop.cb", [](Generator& gen, int pos) {
- gen.GenCodeBlock("cs_stub_interop.cb");
+ GenCodeBlock("cs_interop.cb", [&](int pos) {
+ GenCodeBlock("cs_stub_interop.cb");
});
}
namespace tidl {
-Generator::Generator(std::shared_ptr<Document> doc) : doc_(doc) {
-}
+Generator::Generator(std::shared_ptr<Document> doc) : doc_(doc) {}
void Generator::Run(const std::string& file_name) {
FileName = file_name;
out_file_.close();
}
-void Generator::GenCodeBlock(std::string filename,
- void (*cb)(Generator& gen, int pos)) {
- std::ifstream cb_file;
- std::string line;
- int cnt = 1;
-
- cb_file.open("/usr/share/tidl/code_block/" + filename);
- if (!cb_file.is_open()) {
- cb_file.open("../idlc/code_block/" + filename);
- }
-
- if (!cb_file.is_open())
- return;
-
- while (std::getline(cb_file, line)) {
- if (line.find("#event") == 0) {
- if (cb != nullptr)
- cb(*this, cnt);
- cnt++;
- } else {
- out_file_ << line << std::endl;
- }
- }
-
- cb_file.close();
-}
-
} // namespace tidl
class Generator {
public:
+ using EmptyCallbackType = void (*)(int);
+
explicit Generator(std::shared_ptr<Document> doc);
virtual ~Generator() = default;
void Run(const std::string& file_name);
- void GenCodeBlock(std::string filename,
- void (*cb)(Generator& gen, int pos) = nullptr);
+
+ template<typename T = EmptyCallbackType>
+ void GenCodeBlock(std::string filename, T cb = CallEmptyCallback) {
+ std::ifstream cb_file;
+ std::string line;
+ int cnt = 1;
+
+ cb_file.open("/usr/share/tidl/code_block/" + filename);
+ if (!cb_file.is_open()) {
+ cb_file.open("../idlc/code_block/" + filename);
+ }
+
+ if (!cb_file.is_open())
+ return;
+
+ while (std::getline(cb_file, line)) {
+ if (line.find("#event") == 0) {
+ cb(cnt);
+ cnt++;
+ } else {
+ out_file_ << line << std::endl;
+ }
+ }
+ cb_file.close();
+ }
template<typename T, typename ...ARGS>
void GenTemplate(std::string templ, std::ofstream& stream, T cb, ARGS... args) {
std::string FileName;
private:
+ static void CallEmptyCallback(int pos) {}
+
+ private:
std::shared_ptr<Document> doc_;
std::ofstream out_file_;
};
void OnInitGen(std::ofstream& stream) override {
GenCodeBlock("cs_interop.cb",
- [](Generator& gen, int pos) {
- (static_cast<CodeBlockGenerator&>(gen)).touch = true;
+ [&](int pos) {
+ touch = true;
ASSERT_TRUE(pos == 1);
});
}