MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / buildCSharp

Function buildCSharp

src/api_builder/build_csharp.cpp:223–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221
222
223void buildCSharp(const std::string& input, const std::string& _template, const std::string& output)
224{
225 std::ofstream outfile(output.c_str());
226
227 std::string jsBuff = loadFile(input);
228
229 std::string tpl = loadFile( _template );
230 if( tpl.empty() ) {
231 die("Unable to load template file");
232 }
233
234 json_value *root = json_parse(jsBuff.c_str(), jsBuff.size());
235 if (root) {
236 std::map< std::string, std::string > typeMap;
237
238 json_value *typedef_root = get_object_key(root, "typedefs");
239 if( typedef_root )
240 parseTypedefs( typedef_root, typeMap );
241
242 auto processToken = [root,typeMap] ( std::ostream& out, const std::string& token ) {
243
244 if( ! token.compare( 0, 9, "functions" ) ) {
245
246 std::unordered_set<std::string> includes;
247 std::unordered_set<std::string> excludes;
248
249 for( auto& option : split( token.substr(10), ' ' ) ) {
250 if( option.length() < 3 )
251 continue;
252 else if( option[0] == '-' ) {
253 excludes.insert( option.substr(1) );
254 } else { // if( option[0] == '+' ) ) { include is implicit
255 includes.insert( option.substr(1) );
256 }
257 }
258
259 write_functions( out, get_object_key(root,"functions"), typeMap, function_template, includes, excludes );
260 } else if( token == "enums" ) {
261 write_enums( out, get_object_key(root,"enums") );
262 }
263 };
264
265 template_replace_tokens(outfile, tpl, processToken );
266
267 json_value_free(root);
268 } else {
269 die("Unable to parse JSON file");
270 }
271}

Callers 1

mainFunction · 0.85

Calls 15

loadFileFunction · 0.85
dieFunction · 0.85
json_parseFunction · 0.85
get_object_keyFunction · 0.85
parseTypedefsFunction · 0.85
splitFunction · 0.85
write_functionsFunction · 0.85
write_enumsFunction · 0.85
template_replace_tokensFunction · 0.85
json_value_freeFunction · 0.85
c_strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected