1/* 2* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15 16import { 17 boolIn, 18 boolRet, 19 callbackIn, 20 doubleIn, 21 doubleRet, 22 int32tIn, 23 int32tRet, 24 int64tIn, 25 int64tRet, 26 objectRet, 27 stringIn, 28 stringInUtf16, 29 stringRet, 30 stringRetUtf16, 31 uint32tIn, 32 uint32tRet 33} from "../func_template" 34 35export let cpp2DtsKey = [ 36 { 37 keys: ['char', 'string'], 38 value: 'string' 39 }, 40 { 41 keys: ['size_t', 'int', 'short', 'long', 'double', 'float', 'unsigned'], 42 value: 'number' 43 }, 44 { 45 keys: ['bool'], 46 value: 'boolean' 47 }, 48 { 49 keys: ['void'], 50 value: 'void' 51 } 52] 53 54export let h2NapiInKey = [ 55 { 56 // 如包含这些字眼,则默认是ObjectIn, 此时框架不做任何处理,由用户自己处理 57 keys: ['iterator', 'vector', 'list', 'map', 'array', 'set', 'stack', 'queue', 'deque', 'tuple', 'pair'], 58 value: '' 59 }, 60 { 61 keys: ['std::function'], 62 value: callbackIn 63 }, 64 { 65 keys: ['uint32_t', 'size_t', 'uint8_t', 'uint16_t', 'uint64_t', 'unsigned '], 66 value: uint32tIn 67 }, 68 { 69 keys: ['int64_t', 'long'], 70 value: int64tIn 71 }, 72 { 73 keys: ['double', 'float'], 74 value: doubleIn 75 }, 76 { 77 keys: ['char', 'string', 'char8_t'], 78 value: stringIn 79 }, 80 { 81 keys: ['wchar_t', 'char16_t', 'char32_t'], 82 value: stringInUtf16 83 }, 84 { 85 keys: ['bool'], 86 value: boolIn 87 }, 88 { 89 keys: ['int', 'int32_t', 'short'], 90 value: int32tIn 91 } 92] 93 94export let dts2CppKey = [ 95 { 96 keys: ['number'], 97 value: 'double' 98 }, 99 { 100 keys: ['string'], 101 value: 'std::string' 102 }, 103 { 104 keys: ['boolean'], 105 value: 'bool' 106 }, 107 { 108 keys: ['void'], 109 value: 'void' 110 }, 111 { 112 keys: ['Array<number>', 'number[]'], 113 value: 'std::vector<double>' 114 }, 115 { 116 keys: ['Array<string>', 'string[]'], 117 value: 'std::vector<std::string>' 118 }, 119 { 120 keys: ['Array<boolean>', 'boolean[]'], 121 value: 'std::vector<bool>' 122 }, 123 { 124 keys: ['Map<string,number>'], 125 value: 'std::map<std::string, double>' 126 }, 127 { 128 keys: ['Map<string,string>'], 129 value: 'std::map<std::string, std::string>' 130 }, 131 { 132 keys: ['Map<string,boolean>'], 133 value: 'std::map<std::string, bool>' 134 }, 135 { 136 keys: ['Map<number,number>'], 137 value: 'std::map<double, double>' 138 }, 139 { 140 keys: ['Map<number,string>'], 141 value: 'std::map<double, std::string>' 142 }, 143 { 144 keys: ['Map<number,boolean>'], 145 value: 'std::map<double, bool>' 146 }, 147 { 148 keys: ['Set<string>'], 149 value: 'std::set<std::string>' 150 }, 151 { 152 keys: ['Set<number>'], 153 value: 'std::set<double>' 154 }, 155 { 156 keys: ['Set<boolean>'], 157 value: 'std::set<bool>' 158 }, 159 { 160 keys: ['any', 'object'], 161 value: 'std::any' 162 } 163] 164 165export let h2NapiOutKey = [ 166 { 167 // 如包含这些字眼,则默认是ObjectOut 168 keys: ['iterator', 'vector', 'list', 'map', 'array', 'set', 'stack', 'queue', 'deque', 'tuple', 'pair'], 169 value: objectRet 170 }, 171 { 172 keys: ['uint32_t', 'size_t', 'uint8_t', 'uint16_t', 'uint64_t', 'unsigned '], 173 value: uint32tRet 174 }, 175 { 176 keys: ['int64_t', 'long'], 177 value: int64tRet 178 }, 179 { 180 keys: ['double', 'float'], 181 value: doubleRet 182 }, 183 { 184 keys: ['char', 'string', 'char8_t'], 185 value: stringRet 186 }, 187 { 188 keys: ['wchar_t', 'char16_t', 'char32_t'], 189 value: stringRetUtf16 190 }, 191 { 192 keys: ['bool'], 193 value: boolRet 194 }, 195 { 196 keys: ['int', 'int32_t', 'short'], 197 value: int32tRet 198 } 199] 200 201export let dts2TestValue = [ 202 { 203 key: 'number', 204 value: '1' 205 }, 206 { 207 key: 'string', 208 value: '"hello"' 209 }, 210 { 211 key: 'boolean', 212 value: 'true' 213 }, 214 { 215 key: 'Array<number>', 216 value: '[1,2]' 217 }, 218 { 219 key: 'Array<string>', 220 value: '["hello","world"]' 221 }, 222 { 223 key: 'Array<boolean>', 224 value: '[true,false]' 225 }, 226 { 227 key: 'Map<number, number>', 228 value: 'new Map([[0,0],[1,1]])' 229 }, 230 { 231 key: 'Map<number, string>', 232 value: 'new Map([[0,"0"],[1,"1"]])' 233 }, 234 { 235 key: 'Map<number, boolean>', 236 value: 'new Map([[0,true],[1,false]])' 237 }, 238 { 239 key: 'Map<string, string>', 240 value: 'new Map([["key1","b"],["key2","d"]])' 241 }, 242 { 243 key: 'Map<string, boolean>', 244 value: 'new Map([["key1",false],["key2",true]])' 245 }, 246 { 247 key: 'Map<string, number>', 248 value: 'new Map([["key1",0],["key2",1]])' 249 }, 250 { 251 key: 'Set<number>', 252 value: 'new Set([0,1])' 253 }, 254 { 255 key: 'Set<string>', 256 value: 'new Set(["a","b"])' 257 }, 258 { 259 key: 'Set<boolean>', 260 value: 'new Set([true,false])' 261 } 262] 263