-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor node-addon-api to remove duplicate. (#873)
- Loading branch information
1 parent
939fdd9
commit 0895b64
Showing
7 changed files
with
191 additions
and
570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// scripts/node-addon-api/src/macros.h | ||
// | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
#ifndef SCRIPTS_NODE_ADDON_API_SRC_MACROS_H_ | ||
#define SCRIPTS_NODE_ADDON_API_SRC_MACROS_H_ | ||
|
||
#include <algorithm> | ||
#include <string> | ||
|
||
#define SHERPA_ONNX_ASSIGN_ATTR_STR(c_name, js_name) \ | ||
do { \ | ||
if (o.Has(#js_name) && o.Get(#js_name).IsString()) { \ | ||
Napi::String _str = o.Get(#js_name).As<Napi::String>(); \ | ||
std::string s = _str.Utf8Value(); \ | ||
char *p = new char[s.size() + 1]; \ | ||
std::copy(s.begin(), s.end(), p); \ | ||
p[s.size()] = 0; \ | ||
\ | ||
c.c_name = p; \ | ||
} \ | ||
} while (0) | ||
|
||
#define SHERPA_ONNX_ASSIGN_ATTR_INT32(c_name, js_name) \ | ||
do { \ | ||
if (o.Has(#js_name) && o.Get(#js_name).IsNumber()) { \ | ||
c.c_name = o.Get(#js_name).As<Napi::Number>().Int32Value(); \ | ||
} \ | ||
} while (0) | ||
|
||
#define SHERPA_ONNX_ASSIGN_ATTR_FLOAT(c_name, js_name) \ | ||
do { \ | ||
if (o.Has(#js_name) && o.Get(#js_name).IsNumber()) { \ | ||
c.c_name = o.Get(#js_name).As<Napi::Number>().FloatValue(); \ | ||
} \ | ||
} while (0) | ||
|
||
#endif // SCRIPTS_NODE_ADDON_API_SRC_MACROS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.